Esempio n. 1
0
        public PersonReference()
        {
            ResolveReference(query =>
            {
                var (domain, identifier, defaultLabel) = query;

                var targetModel = CacheFetch(domain, identifier);

                if (targetModel != null)
                {
                    if (defaultLabel != null) targetModel.Name ??= defaultLabel;
                    return targetModel;
                }

                var referenceProbe = Person.ExternalReferences.Where(i =>
                    i.References.Any(j =>
                        j.Domain == domain &&
                        j.Key == identifier)).FirstOrDefault();

                // This will fetch the target model OR create an empty one. Let's also use the local DataSets so we can preserve any changes.
                targetModel = Set.Fetch(referenceProbe?.Id);

                // Default name? Save it as well.
                if (defaultLabel != null) targetModel.Name ??= defaultLabel;

                //Let's check/save the reference too.
                var targetReference = ReferenceSet.Fetch(targetModel.Id);
                targetReference.FetchReference(domain, identifier);

                CacheStore(domain, identifier, targetModel);

                return targetModel;
            });
        }
Esempio n. 2
0
        private static bool runCommand(ref ReferenceSet <Key> set, Key[] domain, Command cmd)
        {
            switch (cmd.type)
            {
            case CmdType.CREATE:
                set = new ReferenceSet <Key>((int)cmd.arg);
                break;

            case CmdType.ADD:
                return(set.add(domain[(int)cmd.arg]));

            case CmdType.DEL:
                return(set.delete(domain[(int)cmd.arg]));

            case CmdType.CLEAR:
                set.clear();
                break;

            case CmdType.UNION:
                set.unionWith(makeSet(domain, (IEnumerable <int>)cmd.arg));
                break;

            case CmdType.INTERSECT:
                set.intersectWith(makeSet(domain, (IEnumerable <int>)cmd.arg));
                break;
            }
            return(true);
        }
Esempio n. 3
0
        public void unionAndIntersectWithTest_nullArg()
        {
            ReferenceSet <Key> set = new ReferenceSet <Key>();

            Assert.Throws <ArgumentNullException>(() => set.unionWith(null));
            Assert.Throws <ArgumentNullException>(() => set.intersectWith(null));
        }
Esempio n. 4
0
        private T CreateOrDuplicateMaterial <T>(Reference _ref, ReferenceSet referenceSet) where T : Material, new()
        {
            Material mat = ((T)_ref.Material).CloneThis();

            mat.MaterialClassification = Session.Query <MaterialClassification>().SingleOrDefault(x => x.Code == "CREF");
            Session.Save(mat);

            Reference newRef = new Reference()
            {
                Material = mat, ReferenceSet = referenceSet
            };

            Session.Save(newRef);

            foreach (ReferenceLanguage rl in _ref.ReferenceLanguages)
            {
                ReferenceLanguage newRefLang = new ReferenceLanguage()
                {
                    Reference = newRef, Language = rl.Language
                };
                Session.Save(newRefLang);
                newRef.ReferenceLanguages.Add(newRefLang);
                Session.Save(newRef);
            }
            referenceSet.References.Add(newRef);
            Session.Save(referenceSet);

            return((T)mat);
        }
Esempio n. 5
0
        public void TestReferenceSet()
        {
            var set = new ReferenceSet <Order>();

            set.Fill(x => new Order {
                Id = x
            }, 10000);
            Assert.Equal(10000, set.Count);

            var list = new List <Order>();

            list.Fill(x => new Order {
                Id = x
            }, 10000);

            foreach (var item in list)
            {
                Assert.False(set.Contains(item));
            }

            for (var i = 1000; i < 3000; i++)
            {
                Assert.False(set.Remove(new Order {
                    Id = i
                }));
            }
            set.Clear();
            Assert.Equal(0, set.Count);

            var set2  = new ReferenceSet <Order>(10000);
            var list2 = new List <Order>();

            for (var i = 0; i < 10000; i++)
            {
                var order = new Order {
                    Id = i
                };
                set2.Add(order);
                list2.Add(order);
            }

            for (var i = 0; i < 10000; i++)
            {
                Assert.True(set2.Contains(list2[i]));
            }

            foreach (var item in set2)
            {
                Assert.True(list2.Contains(item));
            }

            for (var i = 1000; i < 3000; i++)
            {
                Assert.True(set2.Remove(list2[i]));
            }

            Assert.Equal(8000, set2.Count);
        }
Esempio n. 6
0
        public void TestReferenceSetCollectionOperations()
        {
            var set = new ReferenceSet <Order>();

            set.Fill(x => new Order {
                Id = x + 1
            });
            set.CollectionOperations <Order>(1000);
        }
Esempio n. 7
0
 /// <summary>
 /// Copy constructor for record
 /// </summary>
 /// <param name="record"></param>
 public NameRecord(INameRecord record)
 {
     Address      = record.Address;
     Type         = record.Type;
     Id           = record.Id;
     Name         = record.Name;
     Domain       = record.Domain;
     LastActivity = record.LastActivity;
     ReferenceSet.AddRange(record.References);
 }
Esempio n. 8
0
        public void findAddDeleteAndClearTest_nullKey()
        {
            var set = new ReferenceSet <Key>();

            set.add(new Key());
            set.add(new Key());

            Assert.Throws <ArgumentNullException>(() => set.add(null));
            Assert.Throws <ArgumentNullException>(() => set.find(null));
            Assert.Throws <ArgumentNullException>(() => set.delete(null));
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ReferenceSet model = base.BindModel(controllerContext, bindingContext) as ReferenceSet;

            model.Collection.RemoveEmptyItems();
            if (model.IsEmpty)
            {
                return(null);
            }
            return(model);
        }
Esempio n. 10
0
 /// <summary>
 /// Comparison
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 public bool Equals(INameRecord that)
 {
     return
         (IsEqual(Address, that.Address) &&
          IsEqual(Type, that.Type) &&
          IsEqual(Id, that.Id) &&
          IsEqual(Name, that.Name) &&
          IsEqual(Domain, that.Domain) &&
          IsEqual(LastActivity, that.LastActivity) &&
          ReferenceSet.SetEquals(that.References)
         );
 }
Esempio n. 11
0
        public void constructorTest()
        {
            ReferenceSet <Key> set;

            set = new ReferenceSet <Key>();
            Assert.Equal(0, set.count);

            set = new ReferenceSet <Key>(100);
            Assert.Equal(0, set.count);

            Assert.Throws <ArgumentOutOfRangeException>(() => new ReferenceSet <Key>(-1));
        }
Esempio n. 12
0
        private static ReferenceSet <Key> makeSet(Key[] domain, IEnumerable <int> keys)
        {
            var set = new ReferenceSet <Key>();

            if (keys != null)
            {
                foreach (int k in keys)
                {
                    set.add(domain[k]);
                }
            }
            return(set);
        }
Esempio n. 13
0
        public void unionAndIntersectWithTest(IEnumerable <Command> commands)
        {
            ReferenceSet <Key> set = null;

            Key[] domain = makeKeys(getDomainSize(commands));

            foreach (var cmd in commands)
            {
                bool result = runCommand(ref set, domain, cmd);
                Assert.True(result);
                assertSetHasKeys(set, domain, cmd.keysInSet);
            }
        }
Esempio n. 14
0
        public LocationReference()
        {
            GetReference(query =>
            {
                var(domain, identifier, referenceModel) = query;

                var targetModel = CacheFetch(domain, identifier);

                if (targetModel != null)
                {
                    if (referenceModel?.Name != null)
                    {
                        targetModel.Name ??= referenceModel.Name;
                    }
                    return(targetModel);
                }

                var referenceProbe = Location.ExternalReferences.Where(i =>
                                                                       i.References.Any(j =>
                                                                                        j.Domain == domain &&
                                                                                        j.Key == identifier)).FirstOrDefault();

                // This will fetch the target model OR create an empty one. Let's also use the local DataSets so we can preserve any changes.

                if (referenceProbe != null)
                {
                    targetModel = Set.Fetch(referenceProbe?.Id);
                }

                else
                {
                    targetModel = Set.Fetch(Resolve(referenceModel));
                }



                // Default name? Apply.
                if (referenceModel?.Name != null)
                {
                    targetModel.Name ??= referenceModel.Name;
                }

                //Let's check/save the reference too.
                var targetReference = ReferenceSet.Fetch(targetModel.Id);
                targetReference.FetchReference(domain, identifier);

                CacheStore(domain, identifier, targetModel);

                return(targetModel);
            });
        }
Esempio n. 15
0
        /// <summary>
        /// returns the volume of the passed reference set in kubicmeter
        /// </summary>
        /// <param name="refset"></param>
        /// <param name="workpart"></param>
        /// <param name="theSession"></param>
        /// <returns></returns>
        public static double GetRefSetVolume(ReferenceSet refset, Part workpart, Session theSession)
        {
            List <Body>    solidBodies = RefsetHelper.GetSolidBodiesFromRefset(workpart, refset);
            MeasureManager mManager    = theSession.Parts.Display.MeasureManager;
            List <Unit>    massUnits   = new List <Unit>();

            massUnits.Add(theSession.Parts.Display.UnitCollection.GetBase("Area"));
            massUnits.Add(theSession.Parts.Display.UnitCollection.GetBase("Volume"));
            massUnits.Add(theSession.Parts.Display.UnitCollection.GetBase("Mass"));
            massUnits.Add(theSession.Parts.Display.UnitCollection.GetBase("Length"));
            MeasureBodies measureBodies = mManager.NewMassProperties(massUnits.ToArray(),
                                                                     0.99, solidBodies.ToArray());

            return(measureBodies.Volume);
        }
Esempio n. 16
0
        public void enumeratorTest(IEnumerable <Command> commands)
        {
            ReferenceSet <Key> set = null;

            Key[] domain = makeKeys(getDomainSize(commands));

            foreach (Command cmd in commands)
            {
                runCommand(ref set, domain, cmd);

                var enumerator  = set.GetEnumerator();
                var enumerator2 = ((IEnumerable <Key>)set).GetEnumerator();
                var enumerator3 = ((IEnumerable)set).GetEnumerator();

                var enumResult1 = new List <Key>();
                while (enumerator.MoveNext())
                {
                    enumResult1.Add(enumerator.Current);
                }

                var enumResult2 = new List <Key>();
                while (enumerator2.MoveNext())
                {
                    enumResult2.Add(enumerator2.Current);
                }

                var enumResult3 = new List <Key>();
                while (enumerator3.MoveNext())
                {
                    enumResult3.Add(Assert.IsType <Key>(enumerator3.Current));
                }

                bool[] keyMap = makeKeyMap(domain.Length, cmd.keysInSet);

                for (int i = 0; i < domain.Length; i++)
                {
                    Assert.Equal(keyMap[i], enumResult1.Any(x => x == domain[i]));
                    Assert.Equal(keyMap[i], enumResult2.Any(x => x == domain[i]));
                    Assert.Equal(keyMap[i], enumResult3.Any(x => x == domain[i]));
                }

                Assert.Throws <NotImplementedException>(() => enumerator2.Reset());
                Assert.Throws <NotImplementedException>(() => enumerator3.Reset());

                enumerator.Dispose();
                enumerator2.Dispose();
            }
        }
Esempio n. 17
0
        /// <summary>
        /// returns all solid bodies in the passed reference set
        /// </summary>
        /// <param name="workpart"></param>
        /// <param name="refset"></param>
        /// <returns></returns>
        public static List <Body> GetSolidBodiesFromRefset(Part workpart, ReferenceSet refset)
        {
            List <Body>     solidBodies = new List <Body>();
            List <NXObject> objList     = refset.AskAllDirectMembers().ToList();

            foreach (NXObject obj in objList)
            {
                Body body = TryConvertNxObjectToBody(obj);
                if (body != null && body.IsSolidBody)
                {
                    solidBodies.Add(body);
                }
            }

            return(solidBodies);
        }
Esempio n. 18
0
        /// <summary>
        /// Copies members from passed in record
        /// </summary>
        /// <param name="record"></param>
        public INameRecord Assign(INameRecord record)
        {
            if (!Id.Equals(record.Id))
            {
                return(record);
            }

            Type         = record.Type;
            Name         = record.Name;
            Domain       = record.Domain;
            LastActivity = record.LastActivity;

            ReferenceSet.Clear();
            ReferenceSet.AddRange(record.References);
            return(this);
        }
Esempio n. 19
0
        public void unionAndIntersectWithTest_selfArg()
        {
            Key[] domain = makeKeys(30);
            ReferenceSet <Key> set;

            set = new ReferenceSet <Key>();
            set.unionWith(set);
            assertSetHasKeys(set, domain, Enumerable.Empty <int>());
            set.intersectWith(set);
            assertSetHasKeys(set, domain, Enumerable.Empty <int>());

            set = makeSet(domain, new[] { 1, 4, 5, 9, 11, 15, 17, 22, 23, 28 });
            set.unionWith(set);
            assertSetHasKeys(set, domain, new[] { 1, 4, 5, 9, 11, 15, 17, 22, 23, 28 });
            set.intersectWith(set);
            assertSetHasKeys(set, domain, new[] { 1, 4, 5, 9, 11, 15, 17, 22, 23, 28 });
        }
Esempio n. 20
0
        private void CheckAndDeleteDuplicatedMaterial <T>(Func <T, bool> predicate, ReferenceSet referenceSet) where T : Material
        {
            if (referenceSet.References == null || !referenceSet.References.Any())
            {
                return;
            }

            T duplicatedMaterialReference = referenceSet.References.Where(x => x.Material is T).Select(x => (T)x.Material).SingleOrDefault(predicate);

            if (duplicatedMaterialReference != null)
            {
                Reference _ref = referenceSet.References.Single(x => x.Material.Id == duplicatedMaterialReference.Id);
                referenceSet.References.Remove(_ref);
                Session.Delete(_ref);
                Session.Save(referenceSet);
            }
        }
Esempio n. 21
0
        public void toArrayTest(IEnumerable <Command> commands)
        {
            ReferenceSet <Key> set = null;

            Key[] domain = makeKeys(getDomainSize(commands));

            foreach (Command cmd in commands)
            {
                runCommand(ref set, domain, cmd);

                Key[]  array  = set.toArray();
                bool[] keyMap = makeKeyMap(domain.Length, cmd.keysInSet);

                Assert.Equal((cmd.keysInSet == null) ? 0 : cmd.keysInSet.Count(), array.Length);

                for (int i = 0; i < domain.Length; i++)
                {
                    Assert.Equal(keyMap[i], array.Any(x => x == domain[i]));
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Generates a sequence of tokens representing the value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public IEnumerable <Token <ModelTokenType> > GetTokens(object value)
        {
            ICycleDetector detector;

            switch (this.Settings.GraphCycles)
            {
            case GraphCycleType.MaxDepth:
            {
                detector = new DepthCounter(this.Settings.MaxDepth);
                break;
            }

            default:
            {
                detector = new ReferenceSet();
                break;
            }
            }

            List <Token <ModelTokenType> > tokens = new List <Token <ModelTokenType> >();

            this.GetTokens(tokens, detector, value);
            return(tokens);
        }
Esempio n. 23
0
        private static void assertSetHasKeys(ReferenceSet <Key> set, Key[] domain, IEnumerable <int> keys)
        {
            int keyCount = (keys == null) ? 0 : keys.Count();

            Assert.Equal(keyCount, set.count);

            bool[] keyMap = makeKeyMap(domain.Length, keys);

            for (int i = 0; i < domain.Length; i++)
            {
                if (keyMap[i])
                {
                    Assert.True(set.find(domain[i]));
                    Assert.False(set.add(domain[i]));
                }
                else
                {
                    Assert.False(set.find(domain[i]));
                    Assert.False(set.delete(domain[i]));
                }
            }

            Assert.Equal(keyCount, set.count);
        }
Esempio n. 24
0
 internal Enumerator(ReferenceSet <T> set)
 {
     m_slots = set.m_slots;
     m_index = set.m_count;
 }
Esempio n. 25
0
 /// <summary>
 /// Add a address
 /// </summary>
 /// <param name="address"></param>
 public void AddReference(Reference address) =>
 ReferenceSet.Add(address);
Esempio n. 26
0
 /// <summary>
 /// Add a address
 /// </summary>
 /// <param name="address"></param>
 public void RemoveReference(Reference address) =>
 ReferenceSet.Remove(address);