Exemplo n.º 1
0
 public static void Main(String[] args)
 {
     int count = int.Parse(args[0]);
     {
         Console.Write("Good hash function: ");
         Timer         t = new Timer();
         HashSet <int> good
             = MakeRandom(count, new GoodIntegerEqualityComparer());
         Console.WriteLine("({0} sec, {1} items)", t.Check(), good.Count);
         ISortedDictionary <int, int> bcd = good.BucketCostDistribution();
         foreach (KeyValuePair <int, int> entry in bcd)
         {
             Console.WriteLine("{0,7} bucket(s) with cost {1,5}",
                               entry.Value, entry.Key);
         }
     }
     {
         Console.Write("Bad hash function:  ");
         Timer         t   = new Timer();
         HashSet <int> bad = MakeRandom(count, new BadIntegerEqualityComparer());
         Console.WriteLine("({0} sec, {1} items)", t.Check(), bad.Count);
         ISortedDictionary <int, int> bcd = bad.BucketCostDistribution();
         foreach (KeyValuePair <int, int> entry in bcd)
         {
             Console.WriteLine("{0,7} bucket(s) with cost {1,5}",
                               entry.Value, entry.Key);
         }
     }
 }
Exemplo n.º 2
0
            public EnumeratorEnumeratorFilter(ISortedDictionary <TKey, TValue> target,
                                              IEnumerable <KeyValuePair <TSourceKey, TSourceValue> > source,
                                              ExtractKey <TSourceKey, TSourceValue, TKey> sourceKeyExtractor = null,
                                              bool lockWrap = false)
            {
                if (target == null)
                {
                    throw new ArgumentNullException("target");
                }
                if (source == null)
                {
                    throw new ArgumentNullException("source");
                }

                if (lockWrap)
                {
                    target.Locker.Lock(OperationType.Read);
                }
                _target             = (ISortedDictionaryOnDisk)((SpecializedStoreBase)target).Collection.Clone();
                _source             = source.GetEnumerator();
                _sourceKeyExtractor = sourceKeyExtractor;
                _lockWrap           = lockWrap;
                if (_sourceKeyExtractor == null)
                {
                    _sourceKeyExtractor = DefaultKeyExtractor <TSourceKey, TSourceValue, TKey>;
                }
            }
Exemplo n.º 3
0
        /// <summary>
        /// Sample code to test general application usage of SOP.
        /// This creates, populates and reads all records of 2 tables, People & Addresses.
        /// This also showcases technique to take advantage of SOP feature of
        /// "optimized" insertion/reading by doing said operations in batch per table.
        ///
        /// NOTE: this is purely for demo purposes only. Ideal implementation will not
        /// necessarily need two tables. Person and Address records may be merged
        /// to one table for real world use.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: BayWind demo started...", DateTime.Now);

            //** Create a Store Factory
            var storeFactory = new StoreFactory();

            ISortedDictionary <PersonKey, Person> PeopleStore =
                storeFactory.Get <PersonKey, Person>(Server.SystemFile.Store, "People", new PersonComparer());
            ISortedDictionary <int, Address> AddressStore =
                storeFactory.Get <int, Address>(Server.SystemFile.Store, "Address");

            const int MaxCount = 3000;

            if (PeopleStore.Count == 0)
            {
                Populate(PeopleStore, AddressStore, MaxCount);
                Server.Commit();
            }
            else
            {
                Read(PeopleStore, AddressStore, MaxCount);
            }
            Console.WriteLine("{0}: BayWind demo ended...", DateTime.Now);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sample code that uses this VirtualCache.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("{0}: Virtual Cache demo started...", DateTime.Now);
            VirtualCacheGenerics            vc     = new VirtualCacheGenerics();
            ISortedDictionary <int, Person> cache1 = vc.GetObjectCache(1);
            const int MaxCount = 40000;

            for (int i = 0; i < MaxCount; i++)
            {
                Person p = new Person();
                p.FirstName   = string.Format("Joe{0}", i);
                p.LastName    = "Castanas";
                p.PhoneNumber = "510-324-2222";
                p.Address     = string.Format("5434 {0} Coventry Court, Fremont, Ca. 94888, U.S.A.", i);
                cache1.Add(i, p);
            }

            Console.WriteLine("{0}: Finished inserting {1} records, reading 'em starts now...", DateTime.Now, MaxCount);
            cache1.MoveFirst();
            cache1.HintSequentialRead = true;
            for (int i = 0; i < MaxCount; i++)
            {
                Person p = cache1.CurrentValue;
                if (p == null ||
                    p.FirstName != string.Format("Joe{0}", i))
                {
                    Console.WriteLine("Error, data for iteration {0} not found.", i);
                }
                cache1.MoveNext();
            }
            Console.WriteLine("{0}: Virtual Cache demo ended... {1} records were read.", DateTime.Now, MaxCount);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sample code that tests creation and population of 400 tables with 5000 records each.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: Collection400 demo started...", DateTime.Now);
            const int CollCount = 40;

            StoreFactory StoreFactory = new Sop.StoreFactory();

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = StoreFactory.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Transaction.Commit();
                    server.BeginTransaction();
                }
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                if (Server.SystemFile.Store.Contains(CollectionName))
                {
                    ISortedDictionary <long, Person> store = StoreFactory.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                    ReadAll(store);
                }
            }
            Console.WriteLine("{0}: Collection400 demo ended...", DateTime.Now);
        }
Exemplo n.º 6
0
 internal SortedKeysCollection(ISortedDictionary <K, V> sorteddict, ISorted <KeyValuePair <K, V> > sortedpairs, SCG.IComparer <K> comparer, SCG.IEqualityComparer <K> itemequalityComparer)
     : base(itemequalityComparer)
 {
     this.sorteddict  = sorteddict;
     this.sortedpairs = sortedpairs;
     this.comparer    = comparer;
 }
Exemplo n.º 7
0
        private void SetupSql()
        {
            _commandBuilder = new SqlCommandBuilder();
            _db             = new SqlConnection("Server=(localdb)\\ProjectsV12;Database=TestDictionary;Trusted_Connection=True");
            _db.Open();
            var formatter = new ProtobufValueFormatter();

            _uut = new SqlSortedDictionary <string, string>(_tableName, _db, formatter, _commandBuilder, false);
        }
Exemplo n.º 8
0
        void ReadAll(ref ISortedDictionary <string, object> Store)
        {
            int       Ctr        = 0;
            string    key        = null;
            const int batchCount = 1000;

            string[] batch = new string[batchCount];
            for (int i = 0; i < MaxCount; i++)
            {
                Ctr++;
                switch (i % 4)
                {
                case 0:
                    key = string.Format("PersonBlob{0}", Ctr);
                    break;

                case 1:
                    key = string.Format("Person{0}", Ctr);
                    break;

                case 2:
                    key = string.Format("Address{0}", Ctr);
                    break;

                case 3:
                    key = string.Format("Dept{0}", Ctr);
                    break;
                }
                batch[i % batchCount] = key;
                if (i > 0 && i % batchCount == 0)
                {
                    QueryResult <string>[] result;
                    if (!Store.Query(batch.Select((a) => new QueryExpression <string>()
                    {
                        Key = a
                    }).ToArray(), out result))
                    {
                        Console.WriteLine("Failed! 'can't find object {0}.", key);
                    }
                    else
                    {
                        foreach (var o in result)
                        {
                            if (!o.Found)
                            {
                                Console.WriteLine("Failed! 'can't find object {0}.", o.Key);
                            }
                            if (o.Value == null)
                            {
                                Console.WriteLine("Failed! 'found object {0} has null Value.", o.Key);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Processed {0} records.", Ctr);
        }
Exemplo n.º 9
0
        // "Bulk" read all Person and Address records from respective Stores...
        private void Read(ISortedDictionary <PersonKey, Person> PeopleStore,
                          ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            PeopleStore.MoveFirst();
            // tell People Store it can do read ahead of 77 Persons.
            PeopleStore.HintBatchCount = 77;
            AddressStore.MoveFirst();
            // tell Address Store it can do read ahead of 78 Addresses.
            AddressStore.HintBatchCount = 78;
            KeyValuePair <int, int>[] AddressIDs = new KeyValuePair <int, int> [AddressBatchCount];
            int AddressBatchIndex = 0;

            for (int i = 1; i <= MaxCount; i++)
            {
                Person p = PeopleStore.CurrentValue;
                if (p.FirstName != string.Format("Joe{0}", i))
                {
                    Console.WriteLine("Error detected, expected Joe{0} not found in this sequence from disk", i);
                }
                else
                {
                    AddressIDs[AddressBatchIndex++] = new KeyValuePair <int, int>(p.AddressID, i);
                    if (AddressBatchIndex == AddressBatchCount)
                    {
                        int[] a2 = new int[AddressBatchCount];
                        for (int i2 = 0; i2 < AddressBatchCount; i2++)
                        {
                            a2[i2] = AddressIDs[i2].Key;
                        }
                        // Query a batch of 1000 addresses. NOTE: doing batch query is optimal operation
                        // as it minimizes segment jumps of the HDD "disk head".
                        QueryResult <int>[] Addresses;
                        if (AddressStore.Query(QueryExpression <int> .Package(a2), out Addresses))
                        {
                            for (int i2 = 0; i2 < AddressBatchCount; i2++)
                            {
                                Address addr = (Address)Addresses[i2].Value;
                                if (addr == null ||
                                    addr.Street != string.Format("143{0} LoveLane", AddressIDs[i2].Value))
                                {
                                    Console.WriteLine("Error detected, expected Address 143{0} not found in this sequence from disk",
                                                      AddressIDs[i2].Value);
                                }
                            }
                        }
                        AddressBatchIndex = 0;
                    }
                }
                PeopleStore.MoveNext();
            }
            if (!PeopleStore.EndOfTree())
            {
                Console.WriteLine("Expected EOT but isn't.");
            }
            Console.WriteLine("Reading all data({0}) ended.", MaxCount);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Shows how to use two Object Servers with separate transaction for each.
        /// </summary>
        public static void Run()
        {
            string CacheFilename = "OFile.dta";
            //** ObjectServer1 is to be physically stored in ...\Sop1 folder
            string ServerPath1 = "SopBin\\Sop1\\";
            //** ObjectServer2 is to be physically stored in ...\Sop2 folder
            string ServerPath2    = "SopBin\\Sop2\\";
            string ServerFilename = "OServer.dta";

            //** create 1st ObjectServer & its transaction
            ObjectServer server = Sop.ObjectServer.OpenWithTransaction(string.Format("{0}{1}", ServerPath1, ServerFilename),
                                                                       new Preferences());

            //** create 2nd ObjectServer & its transaction
            string       ServerFilename2 = "OServer2.dta";
            string       sfullpath2      = string.Format("{0}{1}", ServerPath2, ServerFilename2);
            ObjectServer server2         = Sop.ObjectServer.OpenWithTransaction(sfullpath2);

            string fn  = string.Format("{0}{1}{2}", ServerPath1, 1, CacheFilename);
            string fn2 = string.Format("{0}{1}{2}", ServerPath2, 2, CacheFilename);

            Sop.IFile f = server.FileSet[CacheFilename];
            if (f == null)
            {
                f = server.FileSet.Add(CacheFilename, fn);
            }

            IStoreFactory sf = new StoreFactory();
            ISortedDictionary <int, Person>
            store = sf.Get <int, Person>(f.Store, "VirtualCache");

            Sop.IFile f2 = server2.FileSet[CacheFilename];
            if (f2 == null)
            {
                f2 = server2.FileSet.Add(CacheFilename, fn2);
            }
            ISortedDictionary <int, Person>
            store2 = sf.Get <int, Person>(f2.Store, "VirtualCache");

            //** insert records
            Console.WriteLine("Start Insertion then Validation of records & their sequence...");

            object o  = store.Transaction;
            object o2 = store2.Transaction;

            InsertRecords(store, 20003, "Store1");
            ReadRecords(store, 20003, "Store1");
            store.Transaction.Rollback();

            InsertRecords(store2, 20501, "Store2");
            ReadRecords(store2, 20501, "Store2");
            store2.Transaction.Rollback();

            Console.WriteLine("Done...");
        }
Exemplo n.º 11
0
        void Populate(ISortedDictionary <string, object> Store)
        {
            for (int i = 0; i < MaxCount; i++)
            {
                int    pid   = (int)Store.GetNextSequence();
                string key   = string.Empty;
                object value = null;
                switch (i % 4)
                {
                case 0:
                    key   = string.Format("PersonBlob{0}", pid);
                    value = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    };
                    break;

                case 1:
                    key   = string.Format("Person{0}", pid);
                    value = new Person
                    {
                        FirstName = string.Format("Joe {0}", pid),
                        LastName  = string.Format("Curly {0}", pid)
                    };
                    break;

                case 2:
                    key   = string.Format("Address{0}", pid);
                    value = new Address
                    {
                        Street  = string.Format("123 Love Lane {0}", pid),
                        City    = "Fremont",
                        State   = "California",
                        Country = "U.S.A.",
                        ZipCode = 94599
                    };
                    break;

                case 3:
                    key   = string.Format("Dept{0}", pid);
                    value = new Department
                    {
                        Id   = pid,
                        Name = string.Format("Dept {0}", pid)
                    };
                    break;
                }
                Store.Add(key, value);
                if (i % 2000 == 0)
                {
                    Store.Flush();
                }
            }
        }
Exemplo n.º 12
0
        static long MeasureSuccessor <T>(uint[] itemSet, ISortedDictionary <uint, T> dict)
        {
            GC.Collect();
            var timer = Stopwatch.StartNew();

            for (int i = 0; i < itemSet.Length; i++)
            {
                dict.Higher(itemSet[i]);
            }
            timer.Stop();
            return(timer.ElapsedMilliseconds);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sample code to show how to create nested Sorted Dictionaries.
        /// I.e. - Collections within Collection scenario.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: NestedSortedDictionary demo started...", DateTime.Now);

            const int    CollCount = 50;
            ITransaction Trans;

            IStoreFactory Factory = new StoreFactory();

            //** Create/Get the Main Collection which we will store the nested "People" Sorted Dictionaries in below code...
            ISortedDictionary <string, GeneralPurpose <long, Person> > Collections =
                Factory.Get <string, GeneralPurpose <long, Person> >(Server.SystemFile.Store, "MainCollection");

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName);
                Trans = store.Transaction;
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Flush();
                    //store.Dispose();
                }
                //else
                //    store.Dispose();
                if (i >= 10)
                {
                    //** get the table 5 tables "ago"
                    store = Factory.Get <long, Person>(Collections, string.Format("People{0}", i - 5));
                    //** delete the table retrieved...
                    //store.Clear();

                    store.Rename("foo");

                    ISortedDictionary <long, Person> fooStore = Factory.Get <long, Person>(Collections, "foo");
                    //store.Delete();
                }
                Trans.Commit();
                server.BeginTransaction();
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = Factory.Get <long, Person>(Collections, CollectionName, createIfNotExist: false);
                if (store != null)
                {
                    ReadAll(store);
                    //store.Dispose();
                }
            }
            Console.WriteLine("{0}: NestedSortedDictionary demo ended...", DateTime.Now);
        }
Exemplo n.º 14
0
 static void InsertRecords(ISortedDictionary <int, Person> store, int MaxCount, string Salt)
 {
     for (int i = 0; i < MaxCount; i++)
     {
         Person p = new Person();
         p.FirstName   = string.Format("Joe{0}{1}", i, Salt);
         p.LastName    = "Castanas";
         p.PhoneNumber = "510-324-2222";
         p.Address     = string.Format("5434 {0} Coventry Court, Fremont, Ca. 94888, U.S.A.", i);
         store.Add(i, p);
     }
     Console.WriteLine("InsertRecords ({0}) end.", MaxCount);
 }
Exemplo n.º 15
0
 public EnumerableKeysFilter(ISortedDictionary <TKey, TValue> store, TKey[] keys, bool lockWrap = false)
 {
     if (keys == null)
     {
         throw new ArgumentNullException("keys");
     }
     if (store == null)
     {
         throw new ArgumentNullException("store");
     }
     _store    = store;
     _keys     = keys;
     _lockWrap = lockWrap;
 }
Exemplo n.º 16
0
 void ReadAll(ObjectServer server,
              ISortedDictionary <long, Person> PeopleStore,
              int maxCount
              )
 {
     for (int i = 0; i < maxCount; i++)
     {
         var v = PeopleStore.CurrentValue;
         if (!PeopleStore.MoveNext())
         {
             break;
         }
     }
 }
Exemplo n.º 17
0
        private void Populate(ISortedDictionary <PersonKey, Person> PeopleStore,
                              ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            int[] AddressIDs        = new int[AddressBatchCount];
            int   AddressBatchIndex = 0;

            // insert Person and Address records onto PeopleStore and AddressStore in batch (bulk insert!)
            for (int i = 1; i <= MaxCount; i++)
            {
                Address addr = new Address();
                addr.AddressID = (int)AddressStore.GetNextSequence();
                addr.City      = "Fremont";
                addr.Country   = "USA";
                addr.State     = "California";
                addr.Street    = string.Format("143{0} LoveLane", i);
                addr.ZipCode   = "99999";
                AddressStore.Add(addr.AddressID, addr);

                AddressIDs[AddressBatchIndex++] = addr.AddressID;
                //** in this block we've caused People to be inserted in batch of 1000
                if (AddressBatchIndex == AddressBatchCount)
                {
                    //** insert People in batch of 1000
                    int PhoneCtr = 1000;
                    for (int AddressID = 0; AddressID < AddressIDs.Length; AddressID++)
                    {
                        Person p = new Person();
                        p.AddressID   = AddressIDs[AddressID];
                        p.FirstName   = string.Format("{0}Joe", p.AddressID);
                        p.LastName    = "Peter";
                        p.PhoneNumber = string.Format("510-555-{0}", PhoneCtr++);
                        PeopleStore.Add(p.GetKey(), p);
                    }
                    AddressBatchIndex = 0;
                }
            }
            // if last batch wasn't inserted yet, then insert it
            if (AddressBatchIndex > 0)
            {
                for (int AddressID = 0; AddressID < AddressBatchIndex; AddressID++)
                {
                    Person p = new Person();
                    p.AddressID   = AddressIDs[AddressID];
                    p.FirstName   = string.Format("Joe{0}", p.AddressID);
                    p.LastName    = "Peter";
                    p.PhoneNumber = "510-555-9999";
                    PeopleStore.Add(p.GetKey(), p);
                }
            }
        }
        void Populate(ISortedDictionary <object, object> PeopleStore)
        {
            int ZipCodeCtr = 5000;

            CacheRecord[] BatchedRecords = new CacheRecord[BatchCount];
            int           BatchedIndex   = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    FirstName = string.Format("Joe{0}", pid),
                    LastName  = string.Format("Peter{0}", pid)
                };
                BatchedRecords[BatchedIndex] = new CacheRecord()
                {
                    p    = p,
                    blob = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    }
                };
                BatchedRecords[BatchedIndex].blob.Blob[0] = 1;
                BatchedRecords[BatchedIndex].blob.Blob[5] = 54;
                BatchedIndex++;
                if (BatchedIndex == BatchCount)
                {
                    for (int i2 = 0; i2 < BatchedIndex; i2++)
                    {
                        PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                    }
                    PeopleStore.Flush();
                    if (i % 500 == 0)
                    {
                        ZipCodeCtr++;
                    }
                    BatchedIndex = 0;
                }
            }
            if (BatchedIndex > 0)
            {
                for (int i2 = 0; i2 < BatchedIndex; i2++)
                {
                    PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                }
                PeopleStore.Flush();
            }
        }
Exemplo n.º 19
0
        private void SetupSqlCe()
        {
            _commandBuilder = new SqlCeCommandBuilder();
            if (File.Exists("TestingData.sdf"))
            {
                File.Delete("TestingData.sdf");
            }
            var engine = new SqlCeEngine("Data Source=TestingData.sdf;Persist Security Info=False;");

            engine.CreateDatabase();
            _db = new SqlCeConnection(engine.LocalConnectionString);
            _db.Open();
            var formatter = new ProtobufValueFormatter();

            _uut = new SqlCeSortedDictionary <string, string>(_tableName, _db, formatter, _commandBuilder);
        }
Exemplo n.º 20
0
        void Populate(ObjectServer server,
                      ISortedDictionary <long, Person> PeopleStore,
                      int maxCount,
                      int seed
                      )
        {
            int ZipCodeCtr = 5000;

            for (int i = seed; i < maxCount; i++)
            {
                if (i == maxCount - 2)
                {
                    object o = 90;
                }
                int     aid  = i;
                Address addr = new Address()
                {
                    AddressID = aid,
                    Key       = new AddressKey()
                    {
                        Street  = string.Format("143{0} LoveLane", aid),
                        City    = "Fremont",
                        Country = "USA",
                        State   = "California",
                        ZipCode = ZipCodeCtr.ToString()
                    }
                };
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    PersonID  = pid,
                    AddressID = addr.AddressID,
                    Key       = new PersonKey()
                    {
                        FirstName = string.Format("Joe{0}", pid),
                        LastName  = string.Format("Peter{0}", pid)
                    },
                    PhoneNumber = "510-555-9999"
                };
                PeopleStore.Add(p.PersonID, p);
                if (i % 5000 == 0)
                {
                    ZipCodeCtr++;
                    PeopleStore.Flush();
                }
            }
        }
Exemplo n.º 21
0
 void Populate(ISortedDictionary <long, Person> PeopleStore)
 {
     for (int i = 0; i < MaxCount; i++)
     {
         int    pid = (int)PeopleStore.GetNextSequence();
         Person p   = new Person()
         {
             PersonID = pid,
             Key      = new PersonKey()
             {
                 FirstName = string.Format("Joe{0}", pid),
                 LastName  = string.Format("Peter{0}", pid)
             },
             PhoneNumber = "510-555-9999"
         };
         PeopleStore.Add(p.PersonID, p);
     }
 }
Exemplo n.º 22
0
 public EnumeratorKeysFilter(ISortedDictionary <TKey, TValue> store, TKey[] keys, bool lockWrap = false)
 {
     if (keys == null || keys.Length == 0)
     {
         throw new ArgumentNullException("keys");
     }
     if (store == null)
     {
         throw new ArgumentNullException("store");
     }
     _lockWrap = lockWrap;
     if (lockWrap)
     {
         store.Locker.Lock(OperationType.Read);
     }
     _store = (ISortedDictionaryOnDisk)((SpecializedStoreBase)store).Collection.Clone();
     _keys  = keys;
 }
Exemplo n.º 23
0
 public EnumerableEnumeratorFilter(ISortedDictionary <TKey, TValue> target,
                                   IEnumerable <KeyValuePair <TSourceKey, TSourceValue> > source,
                                   ExtractKey <TSourceKey, TSourceValue, TKey> sourceKeyExtractor = null,
                                   bool lockWrap = false)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     _target             = target;
     _source             = source;
     _sourceKeyExtractor = sourceKeyExtractor;
     _lockWrap           = lockWrap;
 }
Exemplo n.º 24
0
        void Populate(ISortedDictionary <int, Person> PeopleStore,
                      ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            Person[] NewPeople      = new Person[1000];
            int      NewPeopleIndex = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                Address addr = new Address();
                addr.AddressID = (int)AddressStore.GetNextSequence();
                addr.City      = "Fremont";
                addr.Country   = "USA";
                addr.State     = "California";
                addr.Street    = string.Format("143{0} LoveLane", i);
                addr.ZipCode   = "99999";
                AddressStore.Add(addr.AddressID, addr);

                Person p = new Person();
                p.AddressID   = addr.AddressID;
                p.FirstName   = string.Format("Joe{0}", i);
                p.LastName    = "Peter";
                p.PhoneNumber = "510-555-9999";
                NewPeople[NewPeopleIndex++] = p;
                //** Batch add New People each set of 1000
                if (NewPeopleIndex == 1000)
                {
                    foreach (Person np in NewPeople)
                    {
                        PeopleStore.Add((int)PeopleStore.CurrentSequence, np);
                    }
                    NewPeopleIndex = 0;
                }
            }
            //** add any left over new People haven't been added yet...
            if (NewPeopleIndex > 0)
            {
                for (int i2 = 0; i2 < NewPeopleIndex; i2++)
                {
                    Person np = NewPeople[i2];
                    PeopleStore.Add((int)PeopleStore.CurrentSequence, np);
                }
                NewPeopleIndex = 0;
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Sample code that creates 50 tables and deletes 40 of them.
        /// Reads all the records of the leftover 10 tables. Intention of
        /// this example is to test table space recycling and to show to the
        /// user feature to delete a table in SOP.
        /// </summary>
        public void Run()
        {
            Console.WriteLine("{0}: CollectionRecycling demo started...", DateTime.Now);

            const int     CollCount = 50;
            ITransaction  Trans;
            IStoreFactory sf = new StoreFactory();

            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = sf.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                Trans = store.Transaction;
                if (store.Count == 0)
                {
                    Populate(store);
                    store.Flush();
                    //store.Dispose();
                }
                //else
                //    store.Dispose();
                if (i >= 10)
                {
                    //** get the table 5 tables "ago"
                    store = sf.Get <long, Person>(Server.SystemFile.Store, string.Format("People{0}", i - 5));
                    //** delete the table retrieved...
                    store.Delete();
                }
                Trans.Commit();
                server.BeginTransaction();
            }
            for (int i = 0; i < CollCount; i++)
            {
                string CollectionName = string.Format("People{0}", i);
                ISortedDictionary <long, Person> store = sf.Get <long, Person>(Server.SystemFile.Store, CollectionName);
                if (store != null)
                {
                    ReadAll(store);
                    //store.Dispose();
                }
            }
            Console.WriteLine("{0}: CollectionRecycling demo ended...", DateTime.Now);
        }
Exemplo n.º 26
0
 static void ReadRecords(ISortedDictionary <int, Person> store, int MaxCount, string Salt)
 {
     store.MoveFirst();
     store.HintBatchCount = 99;
     for (int i = 0; i < MaxCount; i++)
     {
         Person p = store.CurrentValue;
         if (p == null ||
             p.FirstName != string.Format("Joe{0}{1}", i, Salt))
         {
             Console.WriteLine("Error, data for iteration {0} not found.", i);
         }
         store.MoveNext();
     }
     if (store.EndOfTree())
     {
         Console.WriteLine("Store's End of tree reached.");
     }
 }
        void ReadAll(ref ISortedDictionary <Person, PersonBlob> PeopleStore)
        {
            var personBatch = new Person[1000];
            int Ctr         = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                Ctr++;
                var p = new Person()
                {
                    FirstName = string.Format("Joe{0}", Ctr),
                    LastName  = string.Format("Peter{0}", Ctr)
                };
                if (PeopleStore.AddIfNotExist(p, null))
                {
                    Console.WriteLine("Failed! 'expected add to fail due to duplicate key. {0}", p.FirstName);
                }
            }
            Console.WriteLine("Processed {0} records.", Ctr);
        }
Exemplo n.º 28
0
 void ReadAll(ISortedDictionary <long, Person> PeopleStore)
 {
     if (PeopleStore.MoveFirst())
     {
         PeopleStore.HintBatchCount = 103;
         int Ctr = 0;
         do
         {
             Ctr++;
             Person p = PeopleStore.CurrentValue;
         } while (PeopleStore.MoveNext());
         if (Ctr != PeopleStore.Count)
         {
             Console.WriteLine("Failed! Read {0}, expected {1}", Ctr, PeopleStore.Count);
         }
         else
         {
             Console.WriteLine("Read {0} items.", Ctr);
         }
     }
 }
        void ReadAll(ref ISortedDictionary <object, object> PeopleStore)
        {
            var personBatch = new Person[1000];
            int Ctr         = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                Ctr++;
                var p = new Person()
                {
                    FirstName = string.Format("Joe{0}", Ctr),
                    LastName  = string.Format("Peter{0}", Ctr)
                };
                var personBlob = PeopleStore[p];
                if (personBlob == null)
                {
                    Console.WriteLine("Failed! 'can't find person {0}.", p.FirstName);
                }
            }
            Console.WriteLine("Processed {0} records.", Ctr);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Shows how to store two different kinds of entities(People & Addresses)
        /// on two Object Stores residing on two different Files.
        ///
        /// NOTE: target folder paths (c:\SopBin & c:\SopBin2) should exist before running this program or else, it will
        /// throw when opening the Files due to path not found.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("{0}: MultipleFiles demo started...", DateTime.Now);
            MultipleFiles MultipleFiles = new MultipleFiles();
            ISortedDictionary <int, Person>  PeopleStore  = MultipleFiles.GetObjectStore <Person>("People");
            ISortedDictionary <int, Address> AddressStore = MultipleFiles.GetObjectStore <Address>("Address", "OFile2",
                                                                                                   "SopBin2\\oFile2.dta");
            const int MaxCount = 25000;

            if (PeopleStore.Count == 0)
            {
                MultipleFiles.Populate(PeopleStore, AddressStore, MaxCount);
            }
            else
            {
                Console.WriteLine("Processing {0} People", PeopleStore.Count);
                MultipleFiles.Stress(PeopleStore, AddressStore, MaxCount);
                MultipleFiles.ReadAll(PeopleStore, AddressStore, MaxCount);
            }
            PeopleStore.Transaction.Commit();
            Console.WriteLine("{0}: MultipleFiles demo ended...", DateTime.Now);
        }