/// <summary> /// Create a new <see cref="Parameter"/> /// </summary> /// <param name="elementDefinition"> /// The container <see cref="ElementDefinition"/> of the <see cref="Parameter"/> that is to be created. /// </param> /// <param name="group"> /// The <see cref="ParameterGroup"/> that the <see cref="Parameter"/> is to be grouped in. /// </param> /// <param name="parameterType"> /// The <see cref="ParameterType"/> that the new <see cref="Parameter"/> references /// </param> /// <param name="measurementScale"> /// The <see cref="MeasurementScale"/> that the <see cref="Parameter"/> references in case the <see cref="ParameterType"/> is a <see cref="QuantityKind"/> /// </param> /// <param name="owner"> /// The <see cref="DomainOfExpertise"/> that is the owner of the <see cref="Parameter"/> that is to be created. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Parameter"/> is to be added /// </param> public async Task CreateParameter(ElementDefinition elementDefinition, ParameterGroup group, ParameterType parameterType, MeasurementScale measurementScale, DomainOfExpertise owner, ISession session) { if (elementDefinition == null) { throw new ArgumentNullException(nameof(elementDefinition), "The container ElementDefinition may not be null"); } if (parameterType == null) { throw new ArgumentNullException(nameof(parameterType), "The ParameterType may not be null"); } if (owner == null) { throw new ArgumentNullException(nameof(owner), "The owner DomainOfExpertise may not be null"); } if (session == null) { throw new ArgumentNullException(nameof(session), "The session may not be null"); } var parameter = new Parameter(Guid.NewGuid(), null, null) { Owner = owner, ParameterType = parameterType, Scale = measurementScale, Group = group }; var clone = elementDefinition.Clone(false); clone.Parameter.Add(parameter); var transactionContext = TransactionContextResolver.ResolveContext(elementDefinition); var transaction = new ThingTransaction(transactionContext, clone); transaction.Create(parameter); try { var operationContainer = transaction.FinalizeTransaction(); await session.Write(operationContainer); } catch (Exception ex) { logger.Error("The parameter could not be created", ex); throw ex; } }
/// <summary> /// Create a new <see cref="ElementUsage"/> /// </summary> /// <param name="container"> /// The container <see cref="ElementDefinition"/> of the <see cref="ElementUsage"/> that is to be created. /// </param> /// <param name="referencedDefinition"> /// The referenced <see cref="ElementDefinition"/> of the <see cref="ElementUsage"/> that is to be created. /// </param> /// <param name="owner"> /// The <see cref="DomainOfExpertise"/> that is the owner of the <see cref="ElementUsage"/> that is to be created. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Parameter"/> is to be added /// </param> public async Task CreateElementUsage(ElementDefinition container, ElementDefinition referencedDefinition, DomainOfExpertise owner, ISession session) { if (container == null) { throw new ArgumentNullException("container", "The container must not be null"); } if (referencedDefinition == null) { throw new ArgumentNullException("referencedDefinition", "The referencedDefinition must not be null"); } if (owner == null) { throw new ArgumentNullException("owner", "The owner must not be null"); } if (session == null) { throw new ArgumentNullException("session", "The session may not be null"); } var clone = container.Clone(false); var usage = new ElementUsage { Name = referencedDefinition.Name, ShortName = referencedDefinition.ShortName, Category = referencedDefinition.Category, Owner = owner, ElementDefinition = referencedDefinition }; clone.ContainedElement.Add(usage); var transactionContext = TransactionContextResolver.ResolveContext(container); var transaction = new ThingTransaction(transactionContext, clone); transaction.Create(usage); try { var operationContainer = transaction.FinalizeTransaction(); await session.Write(operationContainer); } catch (Exception ex) { logger.Error("The ElementUsage could not be created", ex); throw ex; } }
/// <summary> /// Perform the copy operation of an <see cref="ElementDefinition"/> /// </summary> /// <param name="elementDefinition">The <see cref="ElementDefinition"/> to copy</param> /// <param name="targetIteration">The target container</param> public async Task Copy(ElementDefinition elementDefinition, bool areUsagesCopied) { var iterationClone = (Iteration)elementDefinition.Container.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(iterationClone); var transaction = new ThingTransaction(transactionContext, iterationClone); var clone = elementDefinition.Clone(true); clone.Iid = Guid.NewGuid(); clone.Name += CopyAffix; if (!areUsagesCopied) { clone.ContainedElement.Clear(); } this.ResolveReferences(elementDefinition, clone); iterationClone.Element.Add(clone); transaction.CopyDeep(clone); await this.session.Write(transaction.FinalizeTransaction()); }
public void VerifyThatParameterGroupsAreAcyclic() { var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { Name = "ElemDef", ShortName = "ED" }; this.testIteration.Element.Add(elementDefinition); var pg1 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "1" }; elementDefinition.ParameterGroup.Add(pg1); var pg2 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "2", ContainingGroup = pg1 }; elementDefinition.ParameterGroup.Add(pg2); var pg3 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "3", ContainingGroup = pg2 }; elementDefinition.ParameterGroup.Add(pg3); var pg4 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "4", ContainingGroup = pg3 }; elementDefinition.ParameterGroup.Add(pg4); var pg5 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "5" }; elementDefinition.ParameterGroup.Add(pg5); var pg6 = new ParameterGroup(Guid.NewGuid(), this.cache, this.uri) { Name = "6", ContainingGroup = pg5 }; elementDefinition.ParameterGroup.Add(pg6); this.cache.TryAdd(new CacheKey(elementDefinition.Iid, this.testIteration.Iid), new Lazy <Thing>(() => elementDefinition)); var clone = elementDefinition.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.testIteration); this.transaction = new ThingTransaction(transactionContext, clone); var vm1 = new ParameterGroupDialogViewModel(pg1, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone); Assert.AreEqual(2, vm1.PossibleGroups.Count); var vm2 = new ParameterGroupDialogViewModel(pg2, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone); Assert.AreEqual(3, vm2.PossibleGroups.Count); var vm3 = new ParameterGroupDialogViewModel(pg3, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone); Assert.AreEqual(4, vm3.PossibleGroups.Count); }
public void Setup() { this.uri = new Uri("http://www.rheagroup.com"); this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.session = new Mock <ISession>(); this.permissionService = new Mock <IPermissionService>(); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >(); var testDomain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri); var subscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri); var anotherDomain = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.uri) { Name = "Other Domain" }; subscription.Owner = anotherDomain; var paramValueSet = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri); paramValueSet.Computed = new ValueArray <string>(new[] { "c" }); paramValueSet.Manual = new ValueArray <string>(new[] { "m" }); paramValueSet.Reference = new ValueArray <string>(new[] { "r" }); paramValueSet.ValueSwitch = ParameterSwitchKind.COMPUTED; var testParamType = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri); this.parameter = new Parameter(Guid.NewGuid(), this.cache, this.uri) { Owner = testDomain, ParameterType = testParamType }; this.parameter.ParameterSubscription.Add(subscription); this.parameter.ValueSet.Add(paramValueSet); var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); elementDefinition.Parameter.Add(this.parameter); this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri); this.option1 = new Option(Guid.NewGuid(), this.cache, this.uri) { Name = "opt1", ShortName = "o1" }; this.option2 = new Option(Guid.NewGuid(), this.cache, this.uri) { Name = "opt2", ShortName = "o2" }; this.iteration.Option.Add(this.option1); this.iteration.Option.Add(this.option2); this.iteration.Element.Add(elementDefinition); this.psl = new PossibleFiniteStateList(Guid.NewGuid(), this.cache, this.uri); this.ps1 = new PossibleFiniteState(Guid.NewGuid(), this.cache, this.uri) { Name = "1", ShortName = "1" }; this.ps2 = new PossibleFiniteState(Guid.NewGuid(), this.cache, this.uri) { Name = "2", ShortName = "2" }; this.psl.PossibleState.Add(this.ps1); this.psl.PossibleState.Add(this.ps2); this.asl = new ActualFiniteStateList(Guid.NewGuid(), this.cache, this.uri); this.as1 = new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri); this.as1.PossibleState.Add(this.ps1); this.as2 = new ActualFiniteState(Guid.NewGuid(), this.cache, this.uri); this.as2.PossibleState.Add(this.ps2); this.asl.PossibleFiniteStateList.Add(this.psl); this.asl.ActualState.Add(this.as1); this.asl.ActualState.Add(this.as2); this.iteration.ActualFiniteStateList.Add(this.asl); this.iteration.PossibleFiniteStateList.Add(this.psl); var modelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri); modelSetup.ActiveDomain.Add(testDomain); modelSetup.ActiveDomain.Add(anotherDomain); var testPerson = new Person(Guid.NewGuid(), null, null); var testParticipant = new Participant(Guid.NewGuid(), null, null) { Person = testPerson, SelectedDomain = testDomain }; modelSetup.Participant.Add(testParticipant); this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri) { EngineeringModelSetup = modelSetup }; this.sitedir = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri); var ratioScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri); this.srdl.Scale.Add(ratioScale); testParamType.PossibleScale.Add(ratioScale); this.srdl.ParameterType.Add(testParamType); var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri) { RequiredRdl = this.srdl }; this.model.EngineeringModelSetup.RequiredRdl.Add(mrdl); this.sitedir.SiteReferenceDataLibrary.Add(this.srdl); this.model.Iteration.Add(this.iteration); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir); this.session.Setup(x => x.ActivePerson).Returns(testPerson); this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration)); this.elementDefinitionClone = elementDefinition.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.iteration); this.thingTransaction = new ThingTransaction(transactionContext, this.elementDefinitionClone); this.integerScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri) { NumberSet = NumberSetKind.INTEGER_NUMBER_SET, MaximumPermissibleValue = "5", MinimumPermissibleValue = "0" }; this.realScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri) { MaximumPermissibleValue = "50", MinimumPermissibleValue = "0", NumberSet = NumberSetKind.REAL_NUMBER_SET }; this.simpleQt = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri); this.simpleQt.PossibleScale.Add(this.integerScale); this.simpleQt.PossibleScale.Add(this.realScale); this.cptPt = new CompoundParameterType(Guid.NewGuid(), this.cache, this.uri); this.c1 = new ParameterTypeComponent(Guid.NewGuid(), this.cache, this.uri) { ParameterType = this.simpleQt, Scale = this.integerScale }; this.cptPt.Component.Add(this.c1); this.srdl.Scale.Add(this.integerScale); this.srdl.Scale.Add(this.realScale); this.srdl.ParameterType.Add(this.cptPt); this.srdl.ParameterType.Add(this.simpleQt); var dal = new Mock <IDal>(); this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0)); this.session.Setup(x => x.Dal).Returns(dal.Object); dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider()); }