Example #1
0
        public NetworkModel(INMSDatabase db)
        {
            DMSType[] types = ModelResourcesDesc.TypeIdsInInsertOrder;
            containers = new Dictionary <DMSType, Container>(types.Length);
            counters   = new Dictionary <DMSType, int>(types.Length);

            for (int i = 0; i < types.Length; ++i)
            {
                DMSType t = types[i];
                containers.Add(t, new Container(db.GetList(t)));
                counters.Add(t, 0);
            }

            Dictionary <ModelCode, long> refs = new Dictionary <ModelCode, long>();

            foreach (KeyValuePair <DMSType, Container> container in containers)
            {
                foreach (KeyValuePair <long, IdentifiedObject> io in container.Value)
                {
                    refs.Clear();
                    io.Value.GetSourceReferences(refs);

                    foreach (KeyValuePair <ModelCode, long> r in refs)
                    {
                        IdentifiedObject target;

                        if (!TryGetEntity(r.Value, out target))
                        {
                            continue;
                        }

                        target.AddTargetReference(r.Key, io.Value.GID);
                    }
                }
            }

            foreach (KeyValuePair <DMSType, int> pair in db.GetCounters())
            {
                counters[pair.Key] = pair.Value;
            }

            this.db = db;
            rwLock  = new ReaderWriterLockSlim();
        }
Example #2
0
        public NetworkModel(NetworkModel nm)
        {
            nm.rwLock.EnterReadLock();

            try
            {
                containers = new Dictionary <DMSType, Container>(nm.containers.Count);

                foreach (KeyValuePair <DMSType, Container> container in nm.containers)
                {
                    containers.Add(container.Key, new Container(container.Value));
                }

                counters = new Dictionary <DMSType, int>(nm.counters);

                db     = nm.db;
                rwLock = new ReaderWriterLockSlim();
            }
            finally
            {
                nm.rwLock.ExitReadLock();
            }
        }