/// <summary> /// Creates a <see cref="BinaryRelationship" /> for the selected cell /// </summary> /// <param name="direction">The direction fo the relationship to create</param> /// <returns>The task</returns> private Task CreateRelationship(RelationshipDirectionKind direction) { var vm = this.SelectedCell as MatrixCellViewModel; if (vm == null) { return(Task.FromResult(0)); } var relationship = new BinaryRelationship(Guid.NewGuid(), null, null) { Owner = this.session.OpenIterations[this.iteration].Item1 }; relationship.Category.Add(vm.Rule.RelationshipCategory); relationship.Source = direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceY : vm.SourceX; relationship.Target = direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceX : vm.SourceY; var iterationClone = this.iteration.Clone(false); iterationClone.Relationship.Add(relationship); var context = TransactionContextResolver.ResolveContext(relationship); var transaction = new ThingTransaction(context, iterationClone); transaction.Create(relationship, iterationClone); return(this.session.Write(transaction.FinalizeTransaction())); }
/// <summary> /// Posts a predefined <see cref="Parameter"/> /// </summary> private void PostParameter() { if (this.session.OpenIterations.Count == 0) { Console.WriteLine("At first an iteration should be opened"); return; } var iteration = this.session.OpenIterations.Keys.First(); if (iteration != null) { var elementDefinition = iteration.Element[0]; var elementDefinitionClone = elementDefinition.Clone(false); this.session.OpenIterations.TryGetValue(iteration, out var tuple); var domainOfExpertise = tuple.Item1; var parameter = new Parameter(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); parameter.ParameterType = this.session.Assembler.Cache.Values.Select(x => x.Value) .OfType <ParameterType>().First(); parameter.Owner = domainOfExpertise; var transaction = new ThingTransaction( TransactionContextResolver.ResolveContext(elementDefinitionClone), elementDefinitionClone); transaction.Create(parameter, elementDefinitionClone); this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult(); this.PrintCacheCount(); this.PrintCommands(); } }
/// <summary> /// Method for creating a <see cref="BinaryRelationship"/> for requirement verification between a <see cref="ParameterOrOverrideBase"/> and a <see cref="RelationalExpression"/>. /// </summary> /// <param name="session">The <see cref="Session"/> for which the <see cref="BinaryRelationship"/> will be created</param> /// <param name="iteration">The <see cref="Iteration"/> for which the <see cref="BinaryRelationship"/> will be created</param> /// <param name="parameter">The <see cref="ParameterOrOverrideBase"/> that acts as the source of the <see cref="BinaryRelationship"/></param> /// <param name="relationalExpression">The <see cref="RelationalExpression"/> that acts as the target of the <see cref="BinaryRelationship"/></param> /// <returns>An awaitable <see cref="Task"/></returns> public async Task CreateBinaryRelationshipForRequirementVerification(ISession session, Iteration iteration, ParameterOrOverrideBase parameter, RelationalExpression relationalExpression) { session.OpenIterations.TryGetValue(iteration, out var tuple); var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), null, null) { Owner = tuple?.Item1 }; var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(relationalExpression)); binaryRelationship.Container = iteration; binaryRelationship.Source = parameter; binaryRelationship.Target = relationalExpression; var iterationClone = iteration.Clone(false); iterationClone.Relationship.Add(binaryRelationship); transaction.CreateOrUpdate(iterationClone); transaction.Create(binaryRelationship); try { var operationContainer = transaction.FinalizeTransaction(); await session.Write(operationContainer); } catch (Exception ex) { LogManager.GetLogger(typeof(Iteration).FullName).Error("The inline update operation failed: {0}", ex.Message); } }
/// <summary> /// Executes the <see cref="CreateSubscriptionCommand"/> /// </summary> private async Task ExecuteCreateSubscriptionCommand() { if (this.SelectedThing == null) { return; } var parameterOrOverrideRow = this.SelectedThing as ParameterOrOverrideBaseRowViewModel; if (parameterOrOverrideRow == null) { return; } Tuple <DomainOfExpertise, Participant> tuple; this.Session.OpenIterations.TryGetValue(this.Thing.GetContainerOfType <Iteration>(), out tuple); var subscription = new ParameterSubscription { Owner = tuple.Item1 }; var transactionContext = TransactionContextResolver.ResolveContext(this.Thing); var transaction = new ThingTransaction(transactionContext); var clone = parameterOrOverrideRow.Thing.Clone(false); transaction.Create(subscription); transaction.CreateOrUpdate(clone); clone.ParameterSubscription.Add(subscription); await this.DalWrite(transaction); }
/// <summary> /// Posts a predefined <see cref="PossibleFiniteStateList"/> /// </summary> private void PostPossibleFiniteStateList() { if (this.session.OpenIterations.Count == 0) { Console.WriteLine("At first an iteration should be opened"); return; } var iteration = this.session.OpenIterations.Keys.First(); if (iteration != null) { var iterationClone = iteration.Clone(false); var pfs1 = new PossibleFiniteState(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Name = "state1", ShortName = "s1" }; var pfs2 = new PossibleFiniteState(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Name = "state2", ShortName = "s2" }; var pfsList = new PossibleFiniteStateList(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Name = "PossibleFiniteStateList1", ShortName = "PFSL1" }; this.session.OpenIterations.TryGetValue(iteration, out var tuple); var domainOfExpertise = tuple.Item1; pfsList.Owner = domainOfExpertise; var transaction = new ThingTransaction( TransactionContextResolver.ResolveContext(iterationClone), iterationClone); transaction.Create(pfsList, iterationClone); transaction.Create(pfs1, pfsList); transaction.Create(pfs2, pfsList); this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult(); this.PrintCacheCount(); this.PrintCommands(); } }
public void Verify_that_OperationContainerFileVerification_throws_no_exception_when_data_is_complete() { var siteDirectory = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), null, null); var engineeringModelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), null, null); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), null, null); siteDirectory.Model.Add(engineeringModelSetup); engineeringModelSetup.IterationSetup.Add(iterationSetup); var engineeringModel = new CDP4Common.EngineeringModelData.EngineeringModel(Guid.NewGuid(), null, null); engineeringModel.EngineeringModelSetup = engineeringModelSetup; var iteration = new CDP4Common.EngineeringModelData.Iteration(Guid.NewGuid(), null, null); iteration.IterationSetup = iterationSetup; var commonFileStore = new CDP4Common.EngineeringModelData.CommonFileStore(Guid.NewGuid(), null, null); engineeringModel.Iteration.Add(iteration); engineeringModel.CommonFileStore.Add(commonFileStore); var context = TransactionContextResolver.ResolveContext(commonFileStore); var transaction = new ThingTransaction(context); var commonFileStoreClone = commonFileStore.Clone(false); var file = new CDP4Common.EngineeringModelData.File(Guid.NewGuid(), null, null); var fileRevision = new CDP4Common.EngineeringModelData.FileRevision(Guid.NewGuid(), null, null); fileRevision.ContentHash = "1B686ADFA2CAE870A96E5885087337C032781BE6"; transaction.Create(file, commonFileStoreClone); transaction.Create(fileRevision, file); var operationContainer = transaction.FinalizeTransaction(); var files = new List <string> { this.filePath }; var testDal = new TestDal(this.credentials); Assert.DoesNotThrow(() => testDal.TestOperationContainerFileVerification(operationContainer, files)); }
/// <summary> /// Posts a predefined <see cref="Person"/> /// </summary> private void PostPerson() { if (this.IsSiteDirectoryUnavailable()) { Console.WriteLine("At first a connection should be opened."); return; } // Create person object var person = new Person(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { IsActive = true, ShortName = "M" + DateTime.Now, Surname = "Mouse", GivenName = "Mike", Password = "******" }; var email1 = new EmailAddress(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Value = "*****@*****.**", VcardType = VcardEmailAddressKind.HOME }; person.DefaultEmailAddress = email1; var email2 = new EmailAddress(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Value = "*****@*****.**", VcardType = VcardEmailAddressKind.WORK }; var modifiedSiteDirectory = this.session.Assembler.RetrieveSiteDirectory().Clone(true); var transaction = new ThingTransaction( TransactionContextResolver.ResolveContext(modifiedSiteDirectory), modifiedSiteDirectory); transaction.Create(person, modifiedSiteDirectory); transaction.Create(email1, person); transaction.Create(email2, person); this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult(); this.PrintCacheCount(); this.PrintCommands(); }
/// <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> /// Get parameter group with given name. If it does not exist create it. /// </summary> /// <param name="elementDefinition">he element definition.</param> /// <param name="parameterGroupName">The parameter group name.</param> /// <param name="transaction">the <see cref="ThingTransaction" /> holding the changes to persist</param> /// <returns>The <see cref="ParameterGroup" /></returns> private ParameterGroup GetOrCreateParameterGroup(ElementDefinition elementDefinition, string parameterGroupName, ThingTransaction transaction) { var parameterGroup = elementDefinition.ParameterGroup.SingleOrDefault(pg => pg.Name == parameterGroupName); if (parameterGroup == null) { parameterGroup = new ParameterGroup(Guid.NewGuid(), this.sessionService.Cache, this.commandArguments.ServerUri) { Name = parameterGroupName }; transaction.Create(parameterGroup, elementDefinition); } return(parameterGroup.Iid != Guid.Empty ? parameterGroup.Clone(true) : parameterGroup); }
/// <summary> /// Create a new <see cref="BuiltInRuleVerification"/> /// </summary> /// <param name="ruleVerificationList"> /// The container <see cref="RuleVerificationList"/> of the <see cref="BuiltInRuleVerification"/> that is to be created. /// </param> /// <param name="name"> /// The name for the <see cref="BuiltInRuleVerification"/> /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the new <see cref="UserRuleVerification"/> is to be added /// </param> public async Task CreateBuiltInRuleVerification(RuleVerificationList ruleVerificationList, string name, ISession session) { if (ruleVerificationList == null) { throw new ArgumentNullException(nameof(ruleVerificationList), "The ruleVerificationList must not be null"); } if (string.IsNullOrEmpty(name)) { throw new ArgumentException("The name may not be null or empty"); } if (session == null) { throw new ArgumentNullException(nameof(session), "The session may not be null"); } var builtInRuleVerification = new BuiltInRuleVerification(Guid.NewGuid(), null, null) { Name = name, IsActive = false, Status = RuleVerificationStatusKind.NONE }; var clone = ruleVerificationList.Clone(false); clone.RuleVerification.Add(builtInRuleVerification); var transactionContext = TransactionContextResolver.ResolveContext(ruleVerificationList); var transaction = new ThingTransaction(transactionContext, clone); transaction.Create(builtInRuleVerification); try { var operationContainer = transaction.FinalizeTransaction(); await session.Write(operationContainer); } catch (Exception ex) { logger.Error("The BuiltInRuleVerification could not be created", ex); throw ex; } }
/// <summary> /// Execute the <see cref="CreateCommand"/> /// </summary> private async Task ExecuteCreateParameterOverride() { if (this.SelectedThing == null) { return; } var elementUsage = this.SelectedThing.ContainerViewModel.Thing as ElementUsage; if (elementUsage == null) { return; } var parameter = this.SelectedThing.Thing as Parameter; if (parameter == null) { return; } Tuple <DomainOfExpertise, Participant> tuple; this.Session.OpenIterations.TryGetValue(this.Thing.GetContainerOfType <Iteration>(), out tuple); var parameterOverride = new ParameterOverride { Parameter = parameter, Owner = tuple.Item1 }; var transactionContext = TransactionContextResolver.ResolveContext(elementUsage); var transaction = new ThingTransaction(transactionContext); transaction.Create(parameterOverride); var clone = elementUsage.Clone(false); transaction.CreateOrUpdate(clone); clone.ParameterOverride.Add(parameterOverride); await this.DalWrite(transaction); }
/// <summary> /// Create a new <see cref="UserRuleVerification"/> /// </summary> /// <param name="ruleVerificationList"> /// The container <see cref="RuleVerificationList"/> of the <see cref="UserRuleVerification"/> that is to be created. /// </param> /// <param name="rule"> /// The <see cref="Rule"/> that the new <see cref="UserRuleVerification"/> references. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the new <see cref="UserRuleVerification"/> is to be added /// </param> public async Task CreateUserRuleVerification(RuleVerificationList ruleVerificationList, Rule rule, ISession session) { if (ruleVerificationList == null) { throw new ArgumentNullException("ruleVerificationList", "The ruleVerificationList must not be null"); } if (rule == null) { throw new ArgumentNullException("rule", "The rule must not be null"); } if (session == null) { throw new ArgumentNullException("session", "The session may not be null"); } var userRuleVerification = new UserRuleVerification(Guid.NewGuid(), null, null) { Rule = rule, IsActive = false, Status = RuleVerificationStatusKind.NONE }; var clone = ruleVerificationList.Clone(false); clone.RuleVerification.Add(userRuleVerification); var transactionContext = TransactionContextResolver.ResolveContext(ruleVerificationList); var transaction = new ThingTransaction(transactionContext, clone); transaction.Create(userRuleVerification); try { var operationContainer = transaction.FinalizeTransaction(); await session.Write(operationContainer); } catch (Exception ex) { logger.Error("The UserRuleVerification could not be created", ex); throw ex; } }
/// <summary> /// Execute the <see cref="CreateCommand"/> /// </summary> private async Task ExecuteCreateParameterOverride() { if (this.SelectedThing == null) { return; } var elementUsage = this.SelectedThing.ContainerViewModel.Thing as ElementUsage; if (elementUsage == null) { return; } var parameter = this.SelectedThing.Thing as Parameter; if (parameter == null) { return; } this.Session.OpenIterations.TryGetValue(this.Thing, out var tuple); if (tuple != null) { var parameterOverride = new ParameterOverride { Parameter = parameter, Owner = tuple.Item1 }; var transactionContext = TransactionContextResolver.ResolveContext(elementUsage); var transaction = new ThingTransaction(transactionContext); transaction.Create(parameterOverride); var elementUsageClone = elementUsage.Clone(false); transaction.CreateOrUpdate(elementUsageClone); elementUsageClone.ParameterOverride.Add(parameterOverride); await this.DalWrite(transaction); } }
/// <summary> /// Handles the drop action of a <see cref="Tuple{ParameterType, MeasurementScale}"/> /// </summary> /// <param name="tuple">The <see cref="Tuple{ParameterType, MeasurementScale}"/></param> private async Task Drop(Tuple <ParameterType, MeasurementScale> tuple) { var clone = this.Thing.Clone(false); var parameterValue = new SimpleParameterValue(); parameterValue.ParameterType = tuple.Item1; parameterValue.Scale = tuple.Item2; parameterValue.Value = new ValueArray <string>(new [] { "-" }); clone.ParameterValue.Add(parameterValue); var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(this.Thing)); transaction.Create(parameterValue); transaction.CreateOrUpdate(clone); await this.DalWrite(transaction); }
/// <summary> /// Executes the <see cref="PostDiscussionItemCommand"/> /// </summary> private async Task ExecutePostDiscussionItemCommand() { this.ErrorMessage = string.Empty; this.IsBusy = true; var clone = this.Thing.Clone(false); var discussionItem = new EngineeringModelDataDiscussionItem(); discussionItem.Content = this.NewDiscussionItemText; discussionItem.Author = this.currentParticipant; discussionItem.LanguageCode = "en-GB"; discussionItem.CreatedOn = DateTime.UtcNow; clone.Discussion.Add(discussionItem); var context = TransactionContextResolver.ResolveContext(clone); var transaction = new ThingTransaction(context, clone); transaction.Create(discussionItem); await this.DalWrite(transaction); this.IsBusy = false; this.NewDiscussionItemText = string.Empty; }
/// <summary> /// Execute the <see cref="CreateRelationshipCommand"/> /// </summary> private async Task ExecuteCreateRelationshipCommand() { var relationship = this.SelectedRelationshipCreator.CreateRelationshipObject(); relationship.Owner = this.session.OpenIterations[this.iteration].Item1; var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(this.iteration)); var iterationClone = this.iteration.Clone(false); iterationClone.Relationship.Add(relationship); transaction.CreateOrUpdate(iterationClone); transaction.Create(relationship); try { await this.session.Write(transaction.FinalizeTransaction()); this.SelectedRelationshipCreator.ReInitializeControl(); } catch (Exception e) { Logger.Error(e.Message); } }