public IDsmRelation ImportRelation(int relationId, int consumerId, int providerId, string type, int weight, bool deleted) { Logger.LogDataModelMessage("Import relation relationId={relationId} consumerId={consumerId} providerId={providerId} type={type} weight={weight}"); if (relationId > _lastRelationId) { _lastRelationId = relationId; } DsmRelation relation = null; if (consumerId != providerId) { relation = new DsmRelation(relationId, consumerId, providerId, type, weight) { IsDeleted = deleted }; if (deleted) { UnregisterRelation(relation); } else { RegisterRelation(relation); } } return(relation); }
private void UnregisterRelation(DsmRelation relation) { relation.IsDeleted = true; _relationsById.Remove(relation.Id); if (_relationsByProvider.ContainsKey(relation.ProviderId) && _relationsByProvider[relation.ProviderId].ContainsKey(relation.ConsumerId) && _relationsByProvider[relation.ProviderId][relation.ConsumerId].ContainsKey(relation.Type)) { _relationsByProvider[relation.ProviderId][relation.ConsumerId].Remove(relation.Type); } if (_relationsByConsumer.ContainsKey(relation.ConsumerId) && _relationsByConsumer[relation.ConsumerId].ContainsKey(relation.ProviderId) && _relationsByConsumer[relation.ConsumerId][relation.ProviderId].ContainsKey(relation.Type)) { _relationsByConsumer[relation.ConsumerId][relation.ProviderId].Remove(relation.Type); } _deletedRelationsById[relation.Id] = relation; if (_directWeights.ContainsKey(relation.ConsumerId) && _directWeights[relation.ConsumerId].ContainsKey(relation.ProviderId)) { _directWeights[relation.ConsumerId][relation.ProviderId] -= relation.Weight; } UpdateWeights(relation, RemoveWeight); }
public void UnremoveRelation(int relationId) { if (_deletedRelationsById.ContainsKey(relationId)) { DsmRelation relation = _deletedRelationsById[relationId]; if (relation != null) { RegisterRelation(relation); } } }
public void ChangeRelationWeight(IDsmRelation relation, int weight) { DsmRelation changedRelation = relation as DsmRelation; if (changedRelation != null) { UnregisterRelation(changedRelation); changedRelation.Weight = weight; RegisterRelation(changedRelation); } }
public void ChangeRelationType(IDsmRelation relation, string type) { DsmRelation changedRelation = relation as DsmRelation; if (changedRelation != null) { UnregisterRelation(changedRelation); changedRelation.Type = type; RegisterRelation(changedRelation); } }
private void RegisterRelation(DsmRelation relation) { relation.IsDeleted = false; _relationsById[relation.Id] = relation; if (_deletedRelationsById.ContainsKey(relation.Id)) { _deletedRelationsById.Remove(relation.Id); } if (!_relationsByProvider.ContainsKey(relation.ProviderId)) { _relationsByProvider[relation.ProviderId] = new Dictionary <int, Dictionary <string, DsmRelation> >(); } if (!_relationsByProvider[relation.ProviderId].ContainsKey(relation.ConsumerId)) { _relationsByProvider[relation.ProviderId][relation.ConsumerId] = new Dictionary <string, DsmRelation>(); } _relationsByProvider[relation.ProviderId][relation.ConsumerId][relation.Type] = relation; if (!_relationsByConsumer.ContainsKey(relation.ConsumerId)) { _relationsByConsumer[relation.ConsumerId] = new Dictionary <int, Dictionary <string, DsmRelation> >(); } if (!_relationsByConsumer[relation.ConsumerId].ContainsKey(relation.ProviderId)) { _relationsByConsumer[relation.ConsumerId][relation.ProviderId] = new Dictionary <string, DsmRelation>(); } _relationsByConsumer[relation.ConsumerId][relation.ProviderId][relation.Type] = relation; if (!_directWeights.ContainsKey(relation.ConsumerId)) { _directWeights[relation.ConsumerId] = new Dictionary <int, int>(); } if (_directWeights[relation.ConsumerId].ContainsKey(relation.ProviderId)) { _directWeights[relation.ConsumerId][relation.ProviderId] += relation.Weight; } else { _directWeights[relation.ConsumerId][relation.ProviderId] = relation.Weight; } UpdateWeights(relation, AddWeight); }
public IDsmRelation AddRelation(int consumerId, int providerId, string type, int weight) { Logger.LogDataModelMessage("Add relation consumerId={consumerId} providerId={providerId} type={type} weight={weight}"); DsmRelation relation = null; if (consumerId != providerId) { _lastRelationId++; relation = new DsmRelation(_lastRelationId, consumerId, providerId, type, weight) { IsDeleted = false }; RegisterRelation(relation); } return(relation); }