コード例 #1
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);
                }
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Adds a new accounting transaction.
        /// </summary>
        /// <param name="transaction">The accounting transaction.</param>
        /// <returns>Identificador de transaccion</returns>
        public Guid AddTransaction(NewTransaction transaction)
        {
            Requires(transaction != null, "Nueva transaccion invalida");
            Requires(transaction.Entries != null, "Asientos contables en la transaccion invalidos");
            Requires(transaction.Entries.Count > 0, "Nueva transaccion sin asientos contables");
            Requires(transaction.Entries.Sum(x => x.Value) == 0, "Nueva transaccion cuyas sumas no son iguales");
            Requires(transaction.Entries.All(x => _accountDataByCode.ContainsKey(x.AccountCode)), "Codigo de cuenta no existe");

            var now           = DateTimeOffset.Now;
            var transactionId = Guid.NewGuid();

            var transactionData = new TransactionData();

            transactionData.Holder  = transaction.Holder;
            transactionData.Entries = new List <TransactionEntryData>();
            transactionData.Time    = now;

            var balanceIncrements = new Dictionary <string, decimal>();

            foreach (var item in transaction.Entries)
            {
                var entryId = Guid.NewGuid();

                var transactionEntryData = new TransactionEntryData();
                transactionEntryData.AccountCode = item.AccountCode;
                transactionEntryData.Value       = item.Value;
                transactionEntryData.EntryId     = entryId;
                if (transactionEntryData.Value > 0)
                {
                    transactionData.Total += transactionEntryData.Value;
                }
                transactionData.Entries.Add(transactionEntryData);

                ISortedDictionary <Guid, AccountingEntryData> recordDictionary;
                _repository.Get(GetAccountRecordsLookupTableName(item.AccountCode), out recordDictionary);

                var accountingEntryData = new AccountingEntryData();
                accountingEntryData.Time          = now;
                accountingEntryData.AccountCode   = item.AccountCode;
                accountingEntryData.Value         = item.Value;
                accountingEntryData.TransactionId = transactionId;
                recordDictionary.Add(entryId, accountingEntryData);

                decimal increment;
                if (balanceIncrements.TryGetValue(item.AccountCode, out increment))
                {
                    balanceIncrements[item.AccountCode] = increment + transactionEntryData.Value;
                }
                else
                {
                    balanceIncrements.Add(item.AccountCode, transactionEntryData.Value);
                }
            }

            _accountBalanceByCode.Increment(balanceIncrements);
            _transactionsById.Add(transactionId, transactionData);

            return(transactionId);
        }
コード例 #5
0
ファイル: MultipleFiles.cs プロジェクト: kouweizhong/Sop
        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;
            }
        }
コード例 #6
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();
                }
            }
        }
コード例 #7
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);
 }
コード例 #8
0
ファイル: PrivateWallet.cs プロジェクト: LAToken/lachain
        public void AddTpkePrivateKeyAfterBlock(ulong block, PrivateKey key)
        {
            if (_tpkeKeys.Contains(block))
            {
                _tpkeKeys.Update(block, key);
                Logger.LogWarning($"TpkePrivateKey for block {block} is overwritten");
            }
            else
            {
                _tpkeKeys.Add(block, key);
            }

            SaveWallet(_walletPath, _walletPassword);
        }
コード例 #9
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();
                }
            }
        }
コード例 #10
0
ファイル: UnitTest1.cs プロジェクト: jairov4/Braidwood
        public void TristanySortedDictionary_Add()
        {
            const int n = 1000;

            for (int i = 0; i < n; i++)
            {
                _uut.Add("hola" + i, "mundo" + i);
            }

            Assert.AreEqual(n, _uut.Count);
        }
コード例 #11
0
        public void AddAccount(NewAccount newAccount)
        {
            Requires(newAccount != null, "Nueva cuenta invalida");
            Requires(!string.IsNullOrWhiteSpace(newAccount.Code), "Codigo de nueva cuenta invalido");
            Requires(!_accountDataByCode.ContainsKey(newAccount.Code), "Codigo de cuenta ya esta en uso");
            Requires(!_accountBalanceByCode.ContainsKey(newAccount.Code), "Codigo de cuenta ya esta en uso");
            Ensures(_accountDataByCode.ContainsKey(newAccount.Code));
            Ensures(_accountBalanceByCode.ContainsKey(newAccount.Code));

            var accountData = new AccountData();

            accountData.Code   = newAccount.Code;
            accountData.Name   = newAccount.Name;
            accountData.Nature = newAccount.Nature;
            _accountDataByCode.Add(accountData.Code, accountData);
            _accountBalanceByCode.Add(accountData.Code, newAccount.InitialBalance);
        }
コード例 #12
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);
     }
 }
コード例 #13
0
ファイル: MultipleFiles.cs プロジェクト: kouweizhong/Sop
        void Stress(ISortedDictionary <int, Person> PeopleStore,
                    ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            PeopleStore.HintBatchCount  = 100;
            AddressStore.HintBatchCount = 100;
            PeopleStore.MoveLast();
            int    mx  = MaxCount;
            Random rdm = new Random(mx);

            //** NOTE: no batching implemented here, just basic operations...
            //** see Populate function how to do batch Add in set of 1000 which optimizes SOP/Disk buffer usage
            //** batch remove can also be done to optimize usage of such buffers & minimize file pointer jumps.
            for (int i = 0; i < MaxCount / 10; i++)
            {
                int    no = rdm.Next(mx);
                Person p;

                if (i % 2 == 0)
                {
                    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);

                    p           = new Person();
                    p.AddressID = addr.AddressID;
                    int i2 = no;
                    p.FirstName   = string.Format("Joe{0}", i2);
                    p.LastName    = "Peter";
                    p.PhoneNumber = "510-555-9999";
                    PeopleStore.Add(i2, p);
                }
                else
                {
                    if (PeopleStore.TryGetValue(no, out p))
                    {
                        AddressStore.Remove(p.AddressID);
                        PeopleStore.Remove(no);
                    }
                }
                if (i % 500 <= 1)
                {
                    if (i % 2 == 0)
                    {
                        PeopleStore.Transaction.Commit();
                    }
                    else
                    {
                        PeopleStore.Flush();
                        AddressStore.Flush();
                        PeopleStore.Transaction.Rollback();
                    }
                    server.BeginTransaction();
                }
            }
            Console.WriteLine("Stress ended.");
        }