public void VerifyThatIfNonCategorizableThingsAreRelatedViolationsAreReturned() { var rule = new MultiRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { RelationshipCategory = this.lithiumBatteryCategory }; rule.RelatedCategory.Add(this.lithiumBatteryCategory); var alias = new Alias(Guid.NewGuid(), this.cache, this.uri); var definition = new Definition(Guid.NewGuid(), this.cache, this.uri); var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); multiRelationship.Category.Add(this.lithiumBatteryCategory); multiRelationship.RelatedThing.Add(alias); multiRelationship.RelatedThing.Add(definition); this.iteration.Relationship.Add(multiRelationship); var violations = rule.Verify(this.iteration); Assert.AreEqual(2, violations.Count()); var aliasViolation = violations.Single(v => v.ViolatingThing.Contains(alias.Iid)); Assert.IsTrue(aliasViolation.Description.Contains("is not a CategorizableThing")); var definitionViolation = violations.Single(v => v.ViolatingThing.Contains(definition.Iid)); Assert.IsTrue(definitionViolation.Description.Contains("is not a CategorizableThing")); }
/// <summary> /// Creates a <see cref="MultiRelationshipDiagramConnector"/> from a given <see cref="MultiRelationship"/>. /// </summary> /// <param name="relationship">The <see cref="MultiRelationship"/> that defines this connector.</param> private void CreateMultiRelationshipDiagramConnector(MultiRelationship relationship) { foreach (var thing in relationship.RelatedThing) { var otherThings = relationship.RelatedThing.Except(new List <Thing> { thing }).ToList(); var sourceItem = this.ThingDiagramItems.OfType <NamedThingDiagramContentItem>().First( x => x.Thing == thing); foreach (var item in otherThings) { var targetItem = this.ThingDiagramItems.OfType <NamedThingDiagramContentItem>().First( x => x.Thing == item); var newConnector = new MultiRelationshipDiagramConnector(relationship, sourceItem, targetItem); this.Behavior.AddConnector(newConnector); } } }
/// <summary> /// Initializes a new instance of the <see cref="ThingDiagramConnector"/> class. /// </summary> public MultiRelationshipDiagramConnector(MultiRelationship thing, NamedThingDiagramContentItem source, NamedThingDiagramContentItem target) : base(thing) { this.Source = source; this.Target = target; this.UpdateProperties(); }
/// <summary> /// Creates a <see cref="Relationship"/> /// </summary> /// <returns>A new instance of <see cref="Relationship"/></returns> public Relationship CreateRelationshipObject() { var relationship = new MultiRelationship(); relationship.RelatedThing.AddRange(this.RelatedThings.Select(x => x.Thing)); relationship.Category.AddRange(this.AppliedCategories); return(relationship); }
/// <summary> /// Removes a multi relationship row view-model. /// </summary> /// <param name="relationship">The relationship that is removed.</param> private void RemoveMultiRelationshipRowViewModel(MultiRelationship relationship) { var row = this.multiRelationshipsFolder.ContainedRows.FirstOrDefault(pr => pr.Thing == relationship); if (row != null) { this.multiRelationshipsFolder.ContainedRows.RemoveAndDispose(row); } }
public void VerifyThatIfTheIterationContainsNoBinaryRelationShipsAnEmptyResultIsReturned() { var rule = new DecompositionRule(Guid.NewGuid(), this.cache, this.uri); var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); this.iteration.Relationship.Add(multiRelationship); var violations = rule.Verify(this.iteration); CollectionAssert.IsEmpty(violations); }
/// <summary> /// Creates a <see cref="MultiRelationship"/> /// </summary> /// <param name="relatableThings">The list of <see cref="Thing"/> that this relationship will apply to.</param> /// <param name="rule">The <see cref="MultiRelationshipRule"/> that defines this relationship.</param> private async void CreateMultiRelationship(IEnumerable <Thing> relatableThings, MultiRelationshipRule rule) { // send off the relationship Tuple <DomainOfExpertise, Participant> tuple; this.Session.OpenIterations.TryGetValue(this.Thing, out tuple); var multiRelationship = new MultiRelationship(Guid.NewGuid(), null, null) { Owner = tuple.Item1 }; if (rule != null) { multiRelationship.Category.Add(rule.RelationshipCategory); } var iteration = this.Thing.Clone(false); iteration.Relationship.Add(multiRelationship); multiRelationship.Container = iteration; multiRelationship.RelatedThing = relatableThings.ToList(); var transactionContext = TransactionContextResolver.ResolveContext(this.Thing); var containerTransaction = new ThingTransaction(transactionContext, iteration); containerTransaction.CreateOrUpdate(multiRelationship); try { var operationContainer = containerTransaction.FinalizeTransaction(); await this.Session.Write(operationContainer); // at this point relationship has gone through. var returedRelationship = this.Thing.Relationship.FirstOrDefault(r => r.Iid == multiRelationship.Iid) as MultiRelationship; if (returedRelationship != null) { this.CreateMultiRelationshipDiagramConnector(returedRelationship); } } catch (Exception ex) { MessageBox.Show(string.Format("Creation of Binary Relationship failed: {0}", ex.Message), "Binary Relationship Failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void VerifyThatIfRelationshipIsNotMemberOfCategoryNoViolationIsReturned() { var rule = new MultiRelationshipRule(); rule.RelationshipCategory = this.equipmentCategory; var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); this.iteration.Relationship.Add(multiRelationship); var violations = rule.Verify(this.iteration); Assert.IsEmpty(violations); }
public void VerifyThatMultiRelationshipsAreAddedModifiedRemoved() { var viewmodel = new RelationshipBrowserViewModel(this.iteration, this.session.Object, this.thingDialogNavigationService.Object, this.panelNavigationService.Object, null, null); //Add relationship1 and relationship2 and relationship3 var relationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri) { Owner = this.domain, ModifiedOn = DateTime.Now }; relationship.RelatedThing.Add(this.elementDefinition1); relationship.RelatedThing.Add(this.elementDefinition2); relationship.RelatedThing.Add(this.elementDefinition3); this.iteration.Relationship.Add(relationship); var revision = typeof(Iteration).GetProperty("RevisionNumber"); revision.SetValue(this.iteration, 1); CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated); Assert.AreEqual(1, viewmodel.RelationshipTypes[1].ContainedRows.Count); //Modify element definition name this.elementDefinition3.Name = "EG"; var revisionE = typeof(ElementDefinition).GetProperty("RevisionNumber"); revisionE.SetValue(this.elementDefinition3, 1); CDPMessageBus.Current.SendObjectChangeEvent(this.elementDefinition3, EventKind.Updated); Assert.IsTrue(((MultiRelationshipRowViewModel)viewmodel.RelationshipTypes[1].ContainedRows[0]).Name.Contains("EG")); //Modify relationship content relationship.RelatedThing.Add(this.elementDefinition4); var revisionR = typeof(Relationship).GetProperty("RevisionNumber"); revisionR.SetValue(relationship, 1); CDPMessageBus.Current.SendObjectChangeEvent(relationship, EventKind.Updated); Assert.IsTrue(((MultiRelationshipRowViewModel)viewmodel.RelationshipTypes[1].ContainedRows[0]).Name.Contains("E4")); //Remove relationships this.iteration.Relationship.Clear(); revision.SetValue(this.iteration, 2); CDPMessageBus.Current.SendObjectChangeEvent(this.iteration, EventKind.Updated); Assert.AreEqual(0, viewmodel.RelationshipTypes[1].ContainedRows.Count); }
/// <summary> /// Serialize the <see cref="MultiRelationship"/> /// </summary> /// <param name="multiRelationship">The <see cref="MultiRelationship"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(MultiRelationship multiRelationship) { var jsonObject = new JObject(); jsonObject.Add("category", this.PropertySerializerMap["category"](multiRelationship.Category.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationship.ClassKind))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationship.Iid)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationship.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationship.Name)); jsonObject.Add("owner", this.PropertySerializerMap["owner"](multiRelationship.Owner)); jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](multiRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](multiRelationship.RelatedThing.OrderBy(x => x, this.guidComparer))); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationship.RevisionNumber)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationship.ThingPreference)); return(jsonObject); }
public void VerifyThatIfRuleIsNotViolatedNoViolationsAreReturned() { var rule = new MultiRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { RelationshipCategory = this.productCategory }; rule.RelatedCategory.Add(this.productCategory); var battery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); battery.Category.Add(this.batteryCategory); this.iteration.Element.Add(battery); var cell = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); cell.Category.Add(this.equipmentCategory); this.iteration.Element.Add(cell); var cellElementUsage = new ElementUsage(Guid.NewGuid(), this.cache, this.uri); cellElementUsage.ElementDefinition = cell; battery.ContainedElement.Add(cellElementUsage); var pcdu = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri); pcdu.Category.Add(this.equipmentCategory); this.iteration.Element.Add(pcdu); var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); multiRelationship.Category.Add(this.productCategory); this.iteration.Relationship.Add(multiRelationship); multiRelationship.RelatedThing.Add(battery); multiRelationship.RelatedThing.Add(cellElementUsage); multiRelationship.RelatedThing.Add(pcdu); var violations = rule.Verify(this.iteration); CollectionAssert.IsEmpty(violations); }
public void VerifyThatIfRelationshipViolatesRuleViolationIsReturned() { var rule = new MultiRelationshipRule(Guid.NewGuid(), this.cache, this.uri) { RelationshipCategory = this.lithiumBatteryCategory }; rule.RelatedCategory.Add(this.lithiumBatteryCategory); var battery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { ShortName = "BAT", Name = "Battery" }; battery.Category.Add(this.batteryCategory); this.iteration.Element.Add(battery); var lithiumBattery = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri) { ShortName = "LITBAT", Name = "Lithium Battery" }; lithiumBattery.Category.Add(this.lithiumBatteryCategory); this.iteration.Element.Add(lithiumBattery); var multiRelationship = new MultiRelationship(Guid.NewGuid(), this.cache, this.uri); multiRelationship.Category.Add(this.lithiumBatteryCategory); multiRelationship.RelatedThing.Add(battery); multiRelationship.RelatedThing.Add(lithiumBattery); this.iteration.Relationship.Add(multiRelationship); var violations = rule.Verify(this.iteration); var violation = violations.Single(); CollectionAssert.Contains(violation.ViolatingThing, multiRelationship.Iid); }
/// <summary> /// Initializes a new instance of the <see cref="MultiRelationshipRowViewModel"/> class /// </summary> /// <param name="relationship">The <see cref="MultiRelationship"/> associated with this row</param> /// <param name="session">The session</param> /// <param name="containerViewModel">The <see cref="IViewModelBase<Thing>"/></param> container public MultiRelationshipRowViewModel(MultiRelationship relationship, ISession session, IViewModelBase <Thing> containerViewModel) : base(relationship, session, containerViewModel) { this.UpdateProperties(); }
/// <summary> /// Persist the DTO composition to the ORM layer. /// </summary> /// <param name="transaction"> /// The transaction object. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="multiRelationship"> /// The multiRelationship instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool CreateContainment(NpgsqlTransaction transaction, string partition, MultiRelationship multiRelationship) { var results = new List <bool>(); foreach (var parameterValue in this.ResolveFromRequestCache(multiRelationship.ParameterValue)) { results.Add(this.RelationshipParameterValueService.CreateConcept(transaction, partition, parameterValue, multiRelationship)); } return(results.All(x => x)); }
/// <summary> /// Adds a <see cref="MultiRelationship"/> row view model to the tree. /// </summary> /// <param name="relationship">The <see cref="MultiRelationship"/> that this row will belong to.</param> private void AddMultiRelationshipRowViewModel(MultiRelationship relationship) { var row = new MultiRelationshipRowViewModel(relationship, this.Session, this); this.multiRelationshipsFolder.ContainedRows.Add(row); }