protected override void ExecuteSetup(CreateFabMember pCre) { pCre.DefinedByAppId = 4362346234; pCre.DefinedByUserId = 6326234; pCre.Type = (byte)MemberType.Id.Staff; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias <Member> alias = new WeaverVarAlias <Member>("test"); MockTasks .Setup(x => x.FindDuplicateMember(build, pCre.DefinedByUserId, pCre.DefinedByAppId)) .Callback(CheckCallIndex("FindDuplicateMemberNameKey")); MockTasks .Setup(x => x.AddMember(build, ItIsVert <Member>(VertId), out alias)) .Callback(CheckCallIndex("AddMember")); MockTasks .Setup(x => x.AddMemberDefinedByApp( build, ItIsVert <Member>(VertId), It.Is <CreateFabMember>(c => c.DefinedByAppId == pCre.DefinedByAppId), alias )) .Callback(CheckCallIndex("AddMemberDefinedByApp")); MockTasks .Setup(x => x.AddMemberDefinedByUser( build, ItIsVert <Member>(VertId), It.Is <CreateFabMember>(c => c.DefinedByUserId == pCre.DefinedByUserId), alias )) .Callback(CheckCallIndex("AddMemberDefinedByUser")); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public Result Execute(IOperationContext pOpCtx, ICreateOperationBuilder pBuild, CreateOperationTasks pTasks, string pName, long pCreatorMemberId, long pUserId) { vOpCtx = pOpCtx; vBuild = pBuild; vTasks = pTasks; vDataAcc = vOpCtx.Data.Build(null, true); vBuild.SetDataAccess(vDataAcc); vName = pName; vCreatorMemberId = pCreatorMemberId; vUserId = pUserId; try { return(ExecuteSession()); } catch (FabDuplicateFault) { return(new Result { Status = ResultStatus.DuplicateAppName }); } catch (FabNotFoundFault) { return(new Result { Status = ResultStatus.NotFoundMemberOrUser }); } catch (Exception e) { Log.Error("Unexpected error", e); return(new Result { Status = ResultStatus.UnexpectedError }); } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void ExecuteSetup(CreateFabApp pCre) { pCre.Name = "Test Name"; pCre.Secret = "12345678901234567890123456789012"; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias <App> alias = new WeaverVarAlias <App>("test"); MockTasks .Setup(x => x.FindDuplicateAppNameKey(build, ItIsVert <App>(VertId))) .Callback(CheckCallIndex("FindDuplicateAppNameKey")); MockTasks .Setup(x => x.AddApp(build, ItIsVert <App>(VertId), out alias)) .Callback(CheckCallIndex("AddApp")); MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert <App>(VertId), It.Is <CreateFabApp>(c => c.CreatedByMemberId == MemId), It.Is <IWeaverVarAlias <Artifact> >(a => a.Name == alias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void ExecuteSetup(CreateFabUrl pCre) { pCre.Name = "Test Name"; pCre.FullPath = "http://test.FullPath.com"; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias <Url> alias = new WeaverVarAlias <Url>("test"); MockTasks .Setup(x => x.FindDuplicateUrlFullPath(build, ItIsVert <Url>(VertId))) .Callback(CheckCallIndex("FindDuplicateUrlFullPath")); MockTasks .Setup(x => x.AddUrl(build, ItIsVert <Url>(VertId), out alias)) .Callback(CheckCallIndex("AddUrl")); MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert <Url>(VertId), It.Is <CreateFabUrl>(c => c.CreatedByMemberId == MemId), It.Is <IWeaverVarAlias <Artifact> >(a => a.Name == alias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void ExecuteSetup(CreateFabClass pCre) { pCre.Name = "Test Name"; pCre.Disamb = "Test Disamb"; pCre.Note = "Test Note"; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias<Class> alias = new WeaverVarAlias<Class>("test"); MockTasks .Setup(x => x.FindDuplicateClass(build, pCre.Name.ToLower(), pCre.Disamb.ToLower())) .Callback(CheckCallIndex("FindDuplicateClass")); MockTasks .Setup(x => x.AddClass(build, ItIsVert<Class>(VertId), out alias)) .Callback(CheckCallIndex("AddClass")); MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert<Class>(VertId), It.Is<CreateFabClass>(c => c.CreatedByMemberId == MemId), It.Is<IWeaverVarAlias<Artifact>>(a => a.Name == alias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public static void ClassAfterSessionStart(CreateOperationTasks pTasks, ICreateOperationBuilder pBuild, Class pNewDom, CreateFabClass pNewCre) { string disLow = (pNewDom.Disamb == null ? null : pNewDom.Disamb.ToLower()); pTasks.FindDuplicateClass(pBuild, pNewDom.NameKey, disLow); }
/*--------------------------------------------------------------------------------------------*/ private static void AddEdge <TEdge>(ICreateOperationBuilder pCreCtx, IWeaverVarAlias pFromVar, TEdge pEdge, IWeaverVarAlias pToVar) where TEdge : IWeaverEdge { IWeaverQuery q = Weave.Inst.Graph.AddEdge(pFromVar, pEdge, pToVar); pCreCtx.AddQuery(q, true); pCreCtx.SetupLatestCommand(true); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private static void AddVertex <T>(ICreateOperationBuilder pCreCtx, T pVertex, out IWeaverVarAlias <T> pAlias) where T : Vertex, new() { IWeaverQuery q = Weave.Inst.Graph.AddVertex(pVertex); q = WeaverQuery.StoreResultAsVar(pCreCtx.GetNextAliasName(), q, out pAlias); pCreCtx.AddQuery(q, true); pCreCtx.SetupLatestCommand(); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public static void FactorAfterSessionStart(CreateOperationTasks pTasks, ICreateOperationBuilder pBuild, Factor pNewDom, CreateFabFactor pNewCre) { if (pNewCre.UsesPrimaryArtifactId == pNewCre.UsesRelatedArtifactId) { throw new FabPropertyValueFault("RelatedArtifactId", pNewCre.UsesRelatedArtifactId + "", "Cannot be equal to PrimaryArtifactId"); } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public static void InstanceAfterSessionStart(CreateOperationTasks pTasks, ICreateOperationBuilder pBuild, Instance pNewDom, CreateFabInstance pNewCre) { if (pNewDom.Name == null && pNewDom.Disamb != null) { throw new FabPropertyValueFault("Name", null, "Cannot be null when Disamb is specified."); } }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddEmailUsedByArtifact(ICreateOperationBuilder pCreCtx, Email pNewDom, CreateFabEmail pNewCre, IWeaverVarAlias <Email> pAlias) { var a = AddEdge <Email, EmailUsedByArtifact, Artifact>( pCreCtx, pAlias, pNewCre.UsedByArtifactId); var aueEdge = new ArtifactUsesEmail(); AddReverseEdge(pCreCtx, a, aueEdge, pAlias); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private static IWeaverVarAlias <TTo> AddEdge <TFrom, TEdge, TTo>(ICreateOperationBuilder pCreCtx, IWeaverVarAlias <TFrom> pFromVar, long pToVertexId) where TFrom : IVertex, new() where TTo : Vertex, new() where TEdge : IWeaverEdge <TFrom, TTo>, new() { IWeaverVarAlias <TTo> toVar = VerifyVertex <TTo>(pCreCtx, pToVertexId); AddEdge(pCreCtx, pFromVar, new TEdge(), toVar); return(toVar); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddFactorVectorUsesAxisArtifact(ICreateOperationBuilder pCreCtx, Factor pNewDom, CreateFabFactor pNewCre, IWeaverVarAlias <Factor> pAlias) { if (pNewCre.Vector == null) { return; } var a = AddEdge <Factor, FactorVectorUsesAxisArtifact, Artifact>( pCreCtx, pAlias, pNewCre.Vector.UsesAxisArtifactId); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddFactorDescriptorRefinesTypeWithArtifact(ICreateOperationBuilder pCreCtx, Factor pNewDom, CreateFabFactor pNewCre, IWeaverVarAlias <Factor> pAlias) { if (pNewCre.Descriptor == null) { return; } var a = AddEdge <Factor, FactorDescriptorRefinesTypeWithArtifact, Artifact>( pCreCtx, pAlias, pNewCre.Descriptor.RefinesTypeWithArtifactId); }
/*--------------------------------------------------------------------------------------------*/ private static void AddReverseEdge <TFrom, TEdge, TTo>(ICreateOperationBuilder pCreCtx, IWeaverVarAlias <TFrom> pFromVar, TEdge pEdge, IWeaverVarAlias <TTo> pToVar) where TFrom : IVertex, new() where TTo : IVertex, new() where TEdge : IWeaverEdge <TFrom, TTo> { if (pFromVar != null) { AddEdge(pCreCtx, pFromVar, pEdge, pToVar); } }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddOauthAccessAuthenticatesMember(ICreateOperationBuilder pCreCtx, OauthAccess pNewDom, CreateFabOauthAccess pNewCre, IWeaverVarAlias <OauthAccess> pAlias) { var a = AddEdge <OauthAccess, OauthAccessAuthenticatesMember, Member>( pCreCtx, pAlias, pNewCre.AuthenticatesMemberId); var maboaEdge = new MemberAuthenticatedByOauthAccess(); maboaEdge.Timestamp = pNewDom.Timestamp; AddReverseEdge(pCreCtx, a, maboaEdge, pAlias); }
//// Add Edge /*--------------------------------------------------------------------------------------------*/ public virtual void AddArtifactCreatedByMember(ICreateOperationBuilder pCreCtx, Artifact pNewDom, CreateFabArtifact pNewCre, IWeaverVarAlias <Artifact> pAlias) { var a = AddEdge <Artifact, ArtifactCreatedByMember, Member>( pCreCtx, pAlias, pNewCre.CreatedByMemberId); var mcaEdge = new MemberCreatesArtifact(); mcaEdge.Timestamp = pNewDom.Timestamp; mcaEdge.VertexType = pNewDom.VertexType; AddReverseEdge(pCreCtx, a, mcaEdge, pAlias); }
/*--------------------------------------------------------------------------------------------*/ private static IWeaverVarAlias <TTo> AddEdge <TFrom, TEdge, TTo>(ICreateOperationBuilder pCreCtx, IWeaverVarAlias <TFrom> pFromVar, long?pToVertexId) where TFrom : IVertex, new() where TTo : Vertex, new() where TEdge : IWeaverEdge <TFrom, TTo>, new() { if (pToVertexId == null) { return(null); } return(AddEdge <TFrom, TEdge, TTo>(pCreCtx, pFromVar, (long)pToVertexId)); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddFactorUsesRelatedArtifact(ICreateOperationBuilder pCreCtx, Factor pNewDom, CreateFabFactor pNewCre, IWeaverVarAlias <Factor> pAlias) { var a = AddEdge <Factor, FactorUsesRelatedArtifact, Artifact>( pCreCtx, pAlias, pNewCre.UsesRelatedArtifactId); var arbfEdge = new ArtifactUsedAsRelatedByFactor(); arbfEdge.Timestamp = pNewDom.Timestamp; arbfEdge.DescriptorType = pNewDom.DescriptorType; arbfEdge.PrimaryArtifactId = pNewCre.UsesPrimaryArtifactId; AddReverseEdge(pCreCtx, a, arbfEdge, pAlias); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddMemberDefinedByUser(ICreateOperationBuilder pCreCtx, Member pNewDom, CreateFabMember pNewCre, IWeaverVarAlias <Member> pAlias) { var a = AddEdge <Member, MemberDefinedByUser, User>( pCreCtx, pAlias, pNewCre.DefinedByUserId); var udmEdge = new UserDefinesMember(); udmEdge.Timestamp = pNewDom.Timestamp; udmEdge.MemberType = pNewDom.MemberType; udmEdge.AppId = pNewCre.DefinedByAppId; AddReverseEdge(pCreCtx, a, udmEdge, pAlias); }
public void ClassAfterSessionStart(string pDisamb, string pDisambLow) { var c = new Class(); c.NameKey = "test"; c.Disamb = pDisamb; ICreateOperationBuilder build = vMockBuild.Object; vMockTasks.Setup(x => x.FindDuplicateClass(build, c.NameKey, pDisambLow)); CreateOperationsCustom.ClassAfterSessionStart(vMockTasks.Object, build, c, null); vMockTasks.Verify(x => x.FindDuplicateClass(build, c.NameKey, pDisambLow), Times.Once); }
/*--------------------------------------------------------------------------------------------*/ public virtual void AddFactorCreatedByMember(ICreateOperationBuilder pCreCtx, Factor pNewDom, CreateFabFactor pNewCre, IWeaverVarAlias <Factor> pAlias) { var a = AddEdge <Factor, FactorCreatedByMember, Member>( pCreCtx, pAlias, pNewCre.CreatedByMemberId); var mcfEdge = new MemberCreatesFactor(); mcfEdge.Timestamp = pNewDom.Timestamp; mcfEdge.DescriptorType = pNewDom.DescriptorType; mcfEdge.PrimaryArtifactId = pNewCre.UsesPrimaryArtifactId; mcfEdge.RelatedArtifactId = pNewCre.UsesRelatedArtifactId; AddReverseEdge(pCreCtx, a, mcfEdge, pAlias); }
public void MemberAfterSessionStart() { var cre = new CreateFabMember(); cre.DefinedByAppId = 123461235; cre.DefinedByUserId = 34623463; ICreateOperationBuilder build = vMockBuild.Object; vMockTasks.Setup(x => x.FindDuplicateMember( build, cre.DefinedByUserId, cre.DefinedByAppId)); CreateOperationsCustom.MemberAfterSessionStart(vMockTasks.Object, build, null, cre); vMockTasks.Verify(x => x.FindDuplicateMember( build, cre.DefinedByUserId, cre.DefinedByAppId), Times.Once); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public virtual void FindDuplicateClass( ICreateOperationBuilder pCreCtx, string pNameKey, string pDisambLower) { Class c = Weave.Inst.Graph.V .ExactIndex <Class>(x => x.NameKey, pNameKey); IWeaverQuery q; if (pDisambLower == null) { q = c.HasNot(x => x.Disamb) .Property(x => x.VertexId) .ToQuery(); } else { q = c.Has(x => x.Disamb) .CustomStep("filter{" + "it.property('" + DbName.Vert.Class.Disamb + "').next().toLowerCase()==_P1" + "}") .Property(x => x.VertexId) .ToQuery(); q.AddParam(new WeaverQueryVal(pDisambLower)); } //// const string classVarName = "c"; IWeaverVarAlias <Class> alias; q = WeaverQuery.StoreResultAsVar(classVarName, q, out alias); pCreCtx.AddQuery(q, true, classVarName + "?0:1;"); string cmdId = pCreCtx.SetupLatestCommand(false, true); pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => { if (dr.ToIntAt(i, 0) != 1) { string name = pNameKey + (pDisambLower == null ? "" : " (" + pDisambLower + ")"); throw new FabDuplicateFault(typeof(Class), "Name", name, "Name+Disamb conflict."); } })); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private static void FindDuplicate <T>(ICreateOperationBuilder pCreCtx, Expression <Func <T, object> > pProp, string pValue, string pErrPropName) where T : IVertex, new() { IWeaverVarAlias alias; IWeaverQuery q = Weave.Inst.Graph .V.ExactIndex(pProp, pValue) .ToQueryAsVar(pCreCtx.GetNextAliasName(), out alias); pCreCtx.AddQuery(q, true, alias.Name + "?0:1;"); string cmdId = pCreCtx.SetupLatestCommand(false, true); pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => { if (dr.ToIntAt(i, 0) != 1) { throw new FabDuplicateFault(typeof(T), pErrPropName, pValue); } })); }
/*--------------------------------------------------------------------------------------------*/ public virtual TDom Execute(IOperationContext pOpCtx, ICreateOperationBuilder pBuild, CreateOperationTasks pTasks, TCre pNewCre) { SetExecuteData(pOpCtx, pBuild, pTasks, pNewCre, pOpCtx.GetSharpflakeId <Vertex>(), pOpCtx.Data.Build(null, true), true); Build.SetDataAccess(vDataAcc); Build.StartSession(); CheckAndAddVertex(); AddEdges(); Build.CommitAndCloseSession(); vDataRes = vDataAcc.Execute(GetType().Name); Build.PerformChecks(vDataRes); int cmdI = vDataRes.GetCommandIndexByCmdId(AddVertexCommandId); return(vDataRes.ToElementAt <TDom>(cmdI, 0)); }
/*--------------------------------------------------------------------------------------------*/ private static IWeaverVarAlias <T> VerifyVertex <T>(ICreateOperationBuilder pCreCtx, long pVertexId) where T : Vertex, new() { IWeaverVarAlias <T> alias; string var = pCreCtx.GetNextAliasName(); IWeaverQuery q = Weave.Inst.Graph.V .ExactIndex <T>(x => x.VertexId, pVertexId) .ToQueryAsVar(var, out alias); pCreCtx.AddQuery(q, true, "if(" + var + "){" + var + "=" + var + ".next();1;}else{0;}"); string cmdId = pCreCtx.SetupLatestCommand(false, true); pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => { if (dr.ToIntAt(i, 0) != 1) { throw new FabNotFoundFault(typeof(T), "Id=" + pVertexId + " // " + i + " / " + cmdId); } })); return(alias); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void ExecuteSetup(CreateFabInstance pCre) { pCre.Name = "Test Name"; pCre.Disamb = "Test Disamb"; pCre.Note = "Test Note"; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias <Instance> alias = new WeaverVarAlias <Instance>("test"); MockTasks .Setup(x => x.AddInstance(build, ItIsVert <Instance>(VertId), out alias)) .Callback(CheckCallIndex("AddInstance")); MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert <Instance>(VertId), It.Is <CreateFabInstance>(c => c.CreatedByMemberId == MemId), It.Is <IWeaverVarAlias <Artifact> >(a => a.Name == alias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void ExecuteSetup(CreateFabEmail pCre) { pCre.Address = "*****@*****.**"; pCre.Code = "12345678901234567890123456789012"; pCre.Verified = false; pCre.UsedByArtifactId = 1641346431; ICreateOperationBuilder build = MockBuild.Object; IWeaverVarAlias <Email> alias = new WeaverVarAlias <Email>("test"); MockTasks .Setup(x => x.AddEmail(build, ItIsVert <Email>(VertId), out alias)) .Callback(CheckCallIndex("AddEmail")); MockTasks .Setup(x => x.AddEmailUsedByArtifact( build, ItIsVert <Email>(VertId), It.Is <CreateFabEmail>(c => c.UsedByArtifactId == pCre.UsedByArtifactId), It.Is <IWeaverVarAlias <Email> >(a => a.Name == alias.Name) )) .Callback(CheckCallIndex("AddEmailUsedByArtifact")); }
/*--------------------------------------------------------------------------------------------*/ public void SetExecuteData(IOperationContext pOpCtx, ICreateOperationBuilder pBuild, CreateOperationTasks pTasks, TCre pNewCre, long pVertexId, IDataAccess pAccess, bool pRequireAuthAndSetCreator) { vOpCtx = pOpCtx; Build = pBuild; Tasks = pTasks; vDataAcc = pAccess; vVertexId = pVertexId; NewCre = pNewCre; if (pRequireAuthAndSetCreator) { VerifyAuthAndSetCreator(); } NewCre.Validate(); NewDom = ToDomain(NewCre); NewDom.VertexId = vVertexId; NewDom.Timestamp = vOpCtx.UtcNow.Ticks; }