Esempio n. 1
0
        private void Produce <T>(Bag <T> bag, string indent)
        {
            var id = DataBinding.GetId <T>(bag);

            if (!StateSet.Contains(id))
            {
                Console.WriteLine(indent + id);
                bag.Accept(new Visitor <T>(this, indent + "  "));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create partial data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="bag"></param>
        public void Create <T>(Bag <T> bag)
        {
            var id = DataBinding.GetId(bag);

            if (DataStorage.Exist(id))
            {
                return;
            }
            bag.Accept(new CreateVisitor <T>(this, id));
        }
Esempio n. 3
0
 public void Set <T>(Bag <T> bag, string bagId)
 {
     if (BagToId.ContainsKey(bag))
     {
         return;
     }
     if (IdToBag.ContainsKey(bagId))
     {
         throw new Exception(
                   "two bags can't have the same name: " + bagId);
     }
     IdToBag[bagId] = bag;
     BagToId[bag]   = bagId;
     bag.Accept(new SetVisitor <T>(this, bagId));
 }
Esempio n. 4
0
        public void TestAccept2()
        {
            Bag <string> b = new Bag <string>();

            b.Add("5");
            b.Add("4");
            b.Add("3");
            b.Add("2");

            TrackingVisitor <KeyValuePair <string, int> > visitor = new TrackingVisitor <KeyValuePair <string, int> >();

            b.Accept(visitor);

            Assert.AreEqual(visitor.TrackingList.Count, 4);
            Assert.AreEqual(visitor.TrackingList.Contains(new KeyValuePair <string, int>("5", 1)), true);
            Assert.AreEqual(visitor.TrackingList.Contains(new KeyValuePair <string, int>("4", 1)), true);
            Assert.AreEqual(visitor.TrackingList.Contains(new KeyValuePair <string, int>("3", 1)), true);
            Assert.AreEqual(visitor.TrackingList.Contains(new KeyValuePair <string, int>("2", 1)), true);
        }
Esempio n. 5
0
        public void TestAccept()
        {
            Bag <string> b = new Bag <string>();

            b.Add("5");
            b.Add("4");
            b.Add("3");
            b.Add("2");

            TrackingVisitor <string> visitor = new TrackingVisitor <string>();

            b.Accept(visitor);

            Assert.AreEqual(visitor.TrackingList.Count, 4);
            Assert.AreEqual(visitor.TrackingList.Contains("5"), true);
            Assert.AreEqual(visitor.TrackingList.Contains("4"), true);
            Assert.AreEqual(visitor.TrackingList.Contains("3"), true);
            Assert.AreEqual(visitor.TrackingList.Contains("2"), true);
        }
 public IEnumerable <T> Get <T>(Bag <T> bag)
 => bag.Accept(new Visitor <T>(this));
 public IObservable <T> Get <T>(Bag <T> bag)
 => Map.GetOrCreate(
     bag,
     () => bag.Accept(new CreateVisitor <T>(this)));
Esempio n. 8
0
        public void TestInvalidAccept2()
        {
            Bag <string> b = new Bag <string>();

            b.Accept((IVisitor <KeyValuePair <string, int> >)null);
        }
Esempio n. 9
0
        public void TestInvalidAccept1()
        {
            Bag <string> b = new Bag <string>();

            b.Accept((IVisitor <string>)null);
        }
Esempio n. 10
0
        public void TestNullVisitor1()
        {
            Bag <string> b = new Bag <string>();

            b.Accept((IVisitor <string>)null);
        }
Esempio n. 11
0
 public Aliq.Void Visit <T>(Bag <T> bag)
 => bag.Accept(new CreateVisitor <T>(Node, Id));