public DsmResolvedRelation(IDsmModel model, IDsmRelation relation) { Id = relation.Id; ConsumerElement = model.GetElementById(relation.ConsumerId); ProviderElement = model.GetElementById(relation.ProviderId); Type = relation.Type; Weight = relation.Weight; }
public RelationEditWeightViewModel(IDsmApplication application, IDsmRelation relation) { _application = application; _relation = relation; Title = "Edit relation"; Weight = relation.Weight; AcceptChangeCommand = new RelayCommand <object>(AcceptChangeExecute, AcceptChangeCanExecute); }
public RelationEditTypeViewModel(IDsmApplication application, IDsmRelation relation) { _application = application; _relation = relation; Title = "Edit relation type"; Type = relation.Type; AcceptChangeCommand = new RelayCommand <object>(AcceptChangeExecute, AcceptChangeCanExecute); }
public void WhenRelationIsImportedThenRelationIsAddedToModel() { _dsmModel.Setup(x => x.AddRelation(ConsumerId, ProviderId, RelationType, RelationWeight)).Returns(_createdRelation.Object); CreateNewModelPolicy policy = new CreateNewModelPolicy(_dsmModel.Object); IDsmRelation relation = policy.ImportRelation(ConsumerId, ProviderId, RelationType, RelationWeight); Assert.AreEqual(_createdRelation.Object, relation); _dsmModel.Verify(x => x.AddRelation(ConsumerId, ProviderId, RelationType, RelationWeight), Times.Once()); }
public IDsmElement GetRelationProvider(string memberName) { IDsmElement provider = null; IDsmRelation relation = GetRelation(memberName); if (relation != null) { provider = _model.GetElementById(relation.ProviderId) ?? _model.GetDeletedElementById(relation.ProviderId); } return(provider); }
public IDsmElement GetRelationConsumer(string memberName) { IDsmElement consumer = null; IDsmRelation relation = GetRelation(memberName); if (relation != null) { consumer = _model.GetElementById(relation.ConsumerId) ?? _model.GetDeletedElementById(relation.ConsumerId); } return(consumer); }
private void DeleteRelationExecute(object parameter) { if ((SelectedConsumer != null) && (SelectedProvider != null)) { IEnumerable <IDsmRelation> relations = _application.FindRelations(SelectedConsumer, SelectedProvider); IDsmRelation relation = relations.FirstOrDefault(); if (relation != null) { _application.DeleteRelation(relation); } } }
public IDsmRelation FindRelation(int consumerId, int providerId, string type) { IDsmRelation relation = null; if (_relationsByConsumer.ContainsKey(consumerId) && _relationsByConsumer[consumerId].ContainsKey(providerId) && _relationsByConsumer[consumerId][providerId].ContainsKey(type)) { relation = _relationsByConsumer[consumerId][providerId][type]; } return(relation); }
public void GivenModelIsEmptyWhenImportRelationIsCalledThenItsHasOneRelation() { DsmRelationModel model = new DsmRelationModel(_elementsDataModel); Assert.AreEqual(0, model.GetExportedRelationCount()); IDsmRelation relation = model.ImportRelation(1, _a.Id, _b.Id, "type", 1, false); Assert.IsNotNull(relation); Assert.AreEqual(1, model.GetExportedRelationCount()); }
private void ChangeRelationTypeExecute(object parameter) { if ((SelectedConsumer != null) && (SelectedProvider != null)) { IEnumerable <IDsmRelation> relations = _application.FindRelations(SelectedConsumer, SelectedProvider); IDsmRelation relation = relations.FirstOrDefault(); if (relation != null) { RelationEditTypeViewModel relationEditViewModel = new RelationEditTypeViewModel(_application, relation); RelationEditTypeStarted?.Invoke(this, relationEditViewModel); } } }
public void ChangeRelationType(IDsmRelation relation, string type) { DsmRelation changedRelation = relation as DsmRelation; if (changedRelation != null) { UnregisterRelation(changedRelation); changedRelation.Type = type; RegisterRelation(changedRelation); } }
public void ChangeRelationWeight(IDsmRelation relation, int weight) { DsmRelation changedRelation = relation as DsmRelation; if (changedRelation != null) { UnregisterRelation(changedRelation); changedRelation.Weight = weight; RegisterRelation(changedRelation); } }
public void GivenRelationIsInModelWithTheOtherWeightWhenRelationIsImportedThenRelationUpdateWeigthActionIsExecuted() { IDsmRelation foundRelation = _existingRelation.Object; _dsmModel.Setup(x => x.FindRelation(ConsumerId, ProviderId, RelationType)).Returns(foundRelation); UpdateExistingModelPolicy policy = new UpdateExistingModelPolicy(_dsmModel.Object, DsmFilename, _actionManager.Object, null); IDsmRelation relation = policy.ImportRelation(ConsumerId, ProviderId, RelationType, NewRelationWeight); Assert.AreEqual(_existingRelation.Object, relation); _actionManager.Verify(x => x.Execute(It.IsAny <RelationChangeWeightAction>()), Times.Once); }
public void GivenModelIsFilledWhenRemovingRelationThenReducesRelationCount() { DsmRelationModel model = new DsmRelationModel(_elementsDataModel); CreateElementRelations(model); int relationCountBefore = model.GetRelationCount(); IDsmRelation relation = model.FindRelations(_a2, _b2).FirstOrDefault(); Assert.IsNotNull(relation); model.RemoveRelation(relation.Id); Assert.AreEqual(relationCountBefore - 1, model.GetRelationCount()); }
public void GivenModelIsFilledWhenUnremovingRelationThenRestoresCalculatedDerivedWeights() { DsmRelationModel model = new DsmRelationModel(_elementsDataModel); CreateElementRelations(model); Assert.AreEqual(1000, model.GetDependencyWeight(_a1.Id, _b1.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a1.Id, _b2.Id)); Assert.AreEqual(4, model.GetDependencyWeight(_a2.Id, _b2.Id)); Assert.AreEqual(1030, model.GetDependencyWeight(_a1.Id, _b.Id)); Assert.AreEqual(204, model.GetDependencyWeight(_a2.Id, _b.Id)); Assert.AreEqual(1200, model.GetDependencyWeight(_a.Id, _b1.Id)); Assert.AreEqual(34, model.GetDependencyWeight(_a.Id, _b2.Id)); Assert.AreEqual(1234, model.GetDependencyWeight(_a.Id, _b.Id)); IDsmRelation relation = model.FindRelations(_a2, _b2).FirstOrDefault(); Assert.IsNotNull(relation); model.RemoveRelation(relation.Id); Assert.AreEqual(1000, model.GetDependencyWeight(_a1.Id, _b1.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a1.Id, _b2.Id)); Assert.AreEqual(0, model.GetDependencyWeight(_a2.Id, _b2.Id)); Assert.AreEqual(1030, model.GetDependencyWeight(_a1.Id, _b.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b.Id)); Assert.AreEqual(1200, model.GetDependencyWeight(_a.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a.Id, _b2.Id)); Assert.AreEqual(1230, model.GetDependencyWeight(_a.Id, _b.Id)); model.UnremoveRelation(relation.Id); Assert.AreEqual(1000, model.GetDependencyWeight(_a1.Id, _b1.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a1.Id, _b2.Id)); Assert.AreEqual(4, model.GetDependencyWeight(_a2.Id, _b2.Id)); Assert.AreEqual(1030, model.GetDependencyWeight(_a1.Id, _b.Id)); Assert.AreEqual(204, model.GetDependencyWeight(_a2.Id, _b.Id)); Assert.AreEqual(1200, model.GetDependencyWeight(_a.Id, _b1.Id)); Assert.AreEqual(34, model.GetDependencyWeight(_a.Id, _b2.Id)); Assert.AreEqual(1234, model.GetDependencyWeight(_a.Id, _b.Id)); }
public RelationDeleteAction(IDsmModel model, IDsmRelation relation) { _model = model; Debug.Assert(_model != null); _relation = relation; Debug.Assert(_relation != null); _consumer = model.GetElementById(_relation.ConsumerId); Debug.Assert(_consumer != null); _provider = model.GetElementById(_relation.ProviderId); Debug.Assert(_provider != null); }
private void WriteRelation(XmlWriter writer, IDsmRelation relation, IProgress <ProgressInfo> progress) { writer.WriteStartElement(RelationXmlNode); writer.WriteAttributeString(RelationIdXmlAttribute, relation.Id.ToString()); writer.WriteAttributeString(RelationFromXmlAttribute, relation.ConsumerId.ToString()); writer.WriteAttributeString(RelationToXmlAttribute, relation.ProviderId.ToString()); writer.WriteAttributeString(RelationTypeXmlAttribute, relation.Type); writer.WriteAttributeString(RelationWeightXmlAttribute, relation.Weight.ToString()); if (relation.IsDeleted) { writer.WriteAttributeString(RelationDeletedXmlAttribute, "true"); } writer.WriteEndElement(); _progressedRelationCount++; UpdateProgress(progress); }
public RelationChangeWeightAction(IDsmModel model, IDsmRelation relation, int weight) { _model = model; Debug.Assert(_model != null); _relation = relation; Debug.Assert(_relation != null); _consumer = model.GetElementById(_relation.ConsumerId); Debug.Assert(_consumer != null); _provider = model.GetElementById(_relation.ProviderId); Debug.Assert(_provider != null); _old = relation.Weight; _new = weight; }
public RelationChangeTypeAction(IDsmModel model, IDsmRelation relation, string type) { _model = model; Debug.Assert(_model != null); _relation = relation; Debug.Assert(_relation != null); _consumer = model.GetElementById(_relation.ConsumerId); Debug.Assert(_consumer != null); _provider = model.GetElementById(_relation.ProviderId); Debug.Assert(_provider != null); _old = relation.Type; _new = type; }
private void UpdateWeights(IDsmRelation relation, ModifyWeight modifyWeight) { int consumerId = relation.ConsumerId; int providerId = relation.ProviderId; IDsmElement currentConsumer = _elementsDataModel.FindElementById(consumerId); while (currentConsumer != null) { IDsmElement currentProvider = _elementsDataModel.FindElementById(providerId); while (currentProvider != null) { modifyWeight(currentConsumer.Id, currentProvider.Id, relation.Weight); currentProvider = currentProvider.Parent; } currentConsumer = currentConsumer.Parent; } }
public void GivenRelationIsInModelButNotImportedAgainWhenImportIsFinalizedThenRelationDeleteActionIsExecuted() { IDsmRelation foundRelation = _existingRelation.Object; _dsmModel.Setup(x => x.FindRelation(ConsumerId, ProviderId, RelationType)).Returns(foundRelation); List <IDsmRelation> relations = new List <IDsmRelation>() { _existingRelation.Object }; _dsmModel.Setup(x => x.GetRelations()).Returns(relations); UpdateExistingModelPolicy policy = new UpdateExistingModelPolicy(_dsmModel.Object, DsmFilename, _actionManager.Object, null); policy.FinalizeImport(null); _actionManager.Verify(x => x.Execute(It.IsAny <RelationDeleteAction>()), Times.Once); }
public RelationDeleteAction(object[] args) { Debug.Assert(args.Length == 2); _model = args[0] as IDsmModel; Debug.Assert(_model != null); IReadOnlyDictionary <string, string> data = args[1] as IReadOnlyDictionary <string, string>; Debug.Assert(data != null); ActionReadOnlyAttributes attributes = new ActionReadOnlyAttributes(_model, data); _relation = attributes.GetRelation(nameof(_relation)); Debug.Assert(_relation != null); _consumer = attributes.GetRelationConsumer(nameof(_relation)); Debug.Assert(_consumer != null); _provider = attributes.GetRelationProvider(nameof(_relation)); Debug.Assert(_provider != null); }
public IDsmRelation ImportRelation(int consumerId, int providerId, string type, int weight) { IDsmRelation relation = _dsmModel.FindRelation(consumerId, providerId, type); if (relation == null) { RelationCreateAction action = new RelationCreateAction(_dsmModel, consumerId, providerId, type, weight); relation = _actionManager.Execute(action) as IDsmRelation; Debug.Assert(relation != null); } else { _notFoundRelations.Remove(relation.Id); if (relation.Weight != weight) { RelationChangeWeightAction action = new RelationChangeWeightAction(_dsmModel, relation, weight); _actionManager.Execute(action); } } return(relation); }
public void GivenModelIsFilledWhenChangeRelationWeightThenUpdatesCalculatedDerivedWeights() { DsmRelationModel model = new DsmRelationModel(_elementsDataModel); CreateElementRelations(model); Assert.AreEqual(1000, model.GetDependencyWeight(_a1.Id, _b1.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a1.Id, _b2.Id)); Assert.AreEqual(4, model.GetDependencyWeight(_a2.Id, _b2.Id)); Assert.AreEqual(1030, model.GetDependencyWeight(_a1.Id, _b.Id)); Assert.AreEqual(204, model.GetDependencyWeight(_a2.Id, _b.Id)); Assert.AreEqual(1200, model.GetDependencyWeight(_a.Id, _b1.Id)); Assert.AreEqual(34, model.GetDependencyWeight(_a.Id, _b2.Id)); Assert.AreEqual(1234, model.GetDependencyWeight(_a.Id, _b.Id)); IDsmRelation relation = model.FindRelations(_a2, _b2).FirstOrDefault(); Assert.IsNotNull(relation); model.ChangeRelationWeight(relation, 5); Assert.AreEqual(1000, model.GetDependencyWeight(_a1.Id, _b1.Id)); Assert.AreEqual(200, model.GetDependencyWeight(_a2.Id, _b1.Id)); Assert.AreEqual(30, model.GetDependencyWeight(_a1.Id, _b2.Id)); Assert.AreEqual(5, model.GetDependencyWeight(_a2.Id, _b2.Id)); Assert.AreEqual(1030, model.GetDependencyWeight(_a1.Id, _b.Id)); Assert.AreEqual(205, model.GetDependencyWeight(_a2.Id, _b.Id)); Assert.AreEqual(1200, model.GetDependencyWeight(_a.Id, _b1.Id)); Assert.AreEqual(35, model.GetDependencyWeight(_a.Id, _b2.Id)); Assert.AreEqual(1235, model.GetDependencyWeight(_a.Id, _b.Id)); }
public object Do() { _relation = _model.AddRelation(_consumer.Id, _provider.Id, _type, _weight); Debug.Assert(_relation != null); return(_relation); }
public void ChangeRelationType(IDsmRelation relation, string type) { RelationChangeTypeAction action = new RelationChangeTypeAction(_dsmModel, relation, type); _actionManager.Execute(action); }
public void ChangeRelationWeight(IDsmRelation relation, int weight) { RelationChangeWeightAction action = new RelationChangeWeightAction(_dsmModel, relation, weight); _actionManager.Execute(action); }
public void ChangeRelationWeight(IDsmRelation relation, int weight) { _relationsDataModel.ChangeRelationWeight(relation, weight); }
public void ChangeRelationType(IDsmRelation relation, string type) { _relationsDataModel.ChangeRelationType(relation, type); }
public void DeleteRelation(IDsmRelation relation) { RelationDeleteAction action = new RelationDeleteAction(_dsmModel, relation); _actionManager.Execute(action); }