示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
 public void UnremoveRelation(int relationId)
 {
     if (_deletedRelationsById.ContainsKey(relationId))
     {
         DsmRelation relation = _deletedRelationsById[relationId];
         if (relation != null)
         {
             RegisterRelation(relation);
         }
     }
 }
示例#4
0
        public void ChangeRelationWeight(IDsmRelation relation, int weight)
        {
            DsmRelation changedRelation = relation as DsmRelation;

            if (changedRelation != null)
            {
                UnregisterRelation(changedRelation);

                changedRelation.Weight = weight;

                RegisterRelation(changedRelation);
            }
        }
示例#5
0
        public void ChangeRelationType(IDsmRelation relation, string type)
        {
            DsmRelation changedRelation = relation as DsmRelation;

            if (changedRelation != null)
            {
                UnregisterRelation(changedRelation);

                changedRelation.Type = type;

                RegisterRelation(changedRelation);
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }