示例#1
0
        public bool Add(ITerm <Value> Term, Dictionary <long, RiskItemCharacteristicIDAttributes> CoverageIdAttrMap,
                        Dictionary <string, HashSet <long> > ResolvedSchedule, bool CheckForPerRisk = true)
        {
            Subject NodeIdentity = Term.GetSubject();

            bool IsAddSuccessful = true;

            if (NodeIdentity == null)
            {
                NodeIdentity = EMPTYSUBJECTCONSTRAINT;
            }

            TermCollection TermCollection = (IdentityMap.ContainsKey(NodeIdentity) ?
                                             IdentityMap[NodeIdentity].GetContent() : new TermCollection(NodeIdentity));

            // Switching off the following check intentionally, in order to allow redundant terms
            //if (TermCollection.Contains(Term))
            //    throw new ArgumentException("A term node with the same identity (i.e. subject) already contains this term in its collection!");

            IsAddSuccessful = TermCollection.Add(Term);

            if (IsAddSuccessful && !IdentityMap.ContainsKey(NodeIdentity))
            {
                TermNode _TermNode = new TermNode(TermCollection);

                IsAddSuccessful &= base.Add(_TermNode);

                if (IsAddSuccessful)
                {
                    IdentityMap.Add(NodeIdentity, _TermNode);
                    // A newly added term node (i.e. with no parent or child links) is both a root and a leaf, trivially.
                    IsAddSuccessful &= RootNodes.Add(_TermNode);
                    ExecutionState.RegisterModificationInGraphTopology();
                }
            }

            return(IsAddSuccessful);
        }
示例#2
0
        public void Store(object entity)
        {
            Type         entityType       = entity.GetType();
            PropertyInfo identityProperty = CouchDatabase.CouchDocumentConvention.GetIdentityPropertyFor(entityType);

            object id = null;

            if (identityProperty != null)
            {
                id = GetIdentityValueFor(entity, identityProperty);

                if (id == null)
                {
                    id = CouchDatabase.CouchDocumentConvention.GenerateIdentityFor(identityProperty.PropertyType);
                    identityProperty.SetValue(entity, id, null);
                }
            }

            if (id != null)
            {
                if (IdentityMap.ContainsKey(id.ToString()))
                {
                    if (ReferenceEquals(IdentityMap[id.ToString()], entity))
                    {
                        return;
                    }

                    throw new NonUniqueEntityException("Attempted to associate a different entity with id '" + id + "'.");
                }

                var entityMetadata = new EntityMetadata {
                    Key = id.ToString(), Revision = String.Empty
                };
                EntityMetadataMap.Add(entity, entityMetadata);
                IdentityMap[id.ToString()] = entity;
            }
        }