예제 #1
0
        public static byte[] Pack(ClientData clientData)
        {
            if (clientData == null) throw new ArgumentNullException(nameof(clientData));

            var offset = 0;
            var buffer = new byte[GetBufferSize(clientData)];

            Write(buffer, ref offset, (short)clientData.ContextRows.Count);
            foreach (var row in clientData.ContextRows)
            {
                Write(buffer, ref offset, row.Id);
                Write(buffer, ref offset, row.Name);
            }

            Write(buffer, ref offset, (short)clientData.ExceptionRows.Count);
            foreach (var row in clientData.ExceptionRows)
            {
                Write(buffer, ref offset, row.Id);
                Write(buffer, ref offset, row.Contents);
            }

            Write(buffer, ref offset, (short)clientData.FeatureRows.Count);
            foreach (var row in clientData.FeatureRows)
            {
                Write(buffer, ref offset, row.Id);
                Write(buffer, ref offset, row.Name);
                Write(buffer, ref offset, row.ContextId);
            }

            Write(buffer, ref offset, (short)clientData.FeatureEntryRows.Count);
            foreach (var row in clientData.FeatureEntryRows)
            {
                Write(buffer, ref offset, row.Details);
                Write(buffer, ref offset, row.CreatedAt.ToBinary());
                Write(buffer, ref offset, row.FeatureId);
            }

            Write(buffer, ref offset, (short)clientData.ExceptionEntryRows.Count);
            foreach (var row in clientData.ExceptionEntryRows)
            {
                Write(buffer, ref offset, row.ExceptionId);
                Write(buffer, ref offset, row.CreatedAt.ToBinary());
                Write(buffer, ref offset, row.FeatureId);
            }

            return buffer;
        }
예제 #2
0
파일: Program.cs 프로젝트: ppetrov/Cchbc
        public static void SimulateDay(string serverDbPath, DateTime date)
        {
            var s = Stopwatch.StartNew();
            var replicationPerDay = 3;

            replicationPerDay = 1;

            var commonUsages = 100;
            var systemUsages = 25;

            var rnd = new Random();

            var versions = new[]
            {
                @"8.28.79.127",
                @"7.74.19.727",
                @"6.22.29.492",
                @"5.96.69.792",
                @"4.11.27.292",
                @"3.85.19.223",
            };

            var users = new List<string>();
            for (var i = 11; i < 1200; i++)
            {
                users.Add(@"BG" + (i.ToString()).PadLeft(6, '0'));
            }

            var replications = new List<Tuple<string, string>>(users.Count * replicationPerDay);
            foreach (var user in users)
            {
                for (var i = 0; i < replicationPerDay; i++)
                {
                    replications.Add(Tuple.Create(user, versions[rnd.Next(versions.Length)]));
                }
            }

            ServerData serverData;
            using (var client = new TransactionContextCreator(GetSqliteConnectionString(serverDbPath)).Create())
            {
                serverData = FeatureServerManager.GetServerData(client);
                client.Complete();
            }

            var fromDate = date.AddHours(7);
            var toDate = date.AddHours(19);
            var diff = (int)((toDate - fromDate).TotalSeconds);

            foreach (var replication in replications)
            {
                var referenceDate = fromDate.AddSeconds(rnd.Next(diff));

                var dbFeatureExceptionRows = new List<DbFeatureExceptionRow>
                {
                    new DbFeatureExceptionRow(rnd.Next(1,1024), @"System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
               at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
               at System.SQLite.SQLiteDataReader.GetOrdinal(String name)
               at SFA.BusinessLogic.DataAccess.OutletManagement.OutletAdapter.OutletSnapCreator(IDataReader r)
               at SFA.BusinessLogic.DataAccess.Helpers.QueryHelper.ExecuteReader[T](String query, Func`2 creator, IEnumerable`1 parameters, Int32 capacity)
               at SFA.BusinessLogic.DataAccess.Helpers.QueryHelper.ExecuteReader[T](String query, Func`2 creator, Int32 capacity)
               at SFA.BusinessLogic.DataAccess.OutletManagement.OutletAdapter.GetAll()
               at SFA.BusinessLogic.Helpers.DataHelper.Load(OutletAdapter outletAdapter, OutletHierLevelAdapter hierLevelAdapter, TradeChannelsAdapter channelsAdapter, OutletAssignmentAdapter assignmentAdapter, PayerAdapter payerAdapter, OutletAddressAdapter addressAdapter, MarketAttributesAdapter attributesAdapter, List`1 modifiedTables)
               at SFA.BusinessLogic.Cache.<>c__DisplayClass62_0.<Load>b__32()
               at SFA.BusinessLogic.Cache.Load(Boolean useDependancies)")
                };

                var dbFeatureContextRows = new List<DbFeatureContextRow>
                {
                    new DbFeatureContextRow(rnd.Next(1,1024), @"Cache"),
                    new DbFeatureContextRow(rnd.Next(1024,2024), @"Agenda"),
                };
                var dbFeatureRows = new List<DbFeatureRow>
                {
                    new DbFeatureRow(rnd.Next(1, 1024), @"Load", dbFeatureContextRows[0].Id),
                    new DbFeatureRow(rnd.Next(1024, 2024), @"Load", dbFeatureContextRows[1].Id),

                    new DbFeatureRow(rnd.Next(2024, 3024), @"Close Activity", dbFeatureContextRows[1].Id),
                    new DbFeatureRow(rnd.Next(3024, 4024), @"Cancel Activity", dbFeatureContextRows[1].Id),
                    new DbFeatureRow(rnd.Next(4024, 5024), @"Edit Activity", dbFeatureContextRows[1].Id),

                    new DbFeatureRow(rnd.Next(5024, 6024), @"Synchronize", dbFeatureContextRows[1].Id),
                    new DbFeatureRow(rnd.Next(6024, 7024), @"View Outlet Details", dbFeatureContextRows[1].Id),
                };
                var dbFeatureExceptionEntryRows = new List<DbFeatureExceptionEntryRow>
                {
                    new DbFeatureExceptionEntryRow(dbFeatureExceptionRows[0].Id, GetRandomDate(rnd, fromDate, referenceDate), dbFeatureRows[0].Id)
                };

                var dbFeatureEntryRows = new List<DbFeatureEntryRow>
                {
                    new DbFeatureEntryRow(string.Empty, DateTime.Now, dbFeatureRows[rnd.Next(dbFeatureRows.Count)].Id),
                    new DbFeatureEntryRow(string.Empty, DateTime.Now, dbFeatureRows[rnd.Next(dbFeatureRows.Count)].Id)
                };

                var clientData = new ClientData(dbFeatureContextRows, dbFeatureExceptionRows, dbFeatureRows, dbFeatureEntryRows, dbFeatureExceptionEntryRows);

                using (var ctx = new TransactionContextCreator(GetSqliteConnectionString(serverDbPath)).Create())
                {
                    FeatureServerManager.Replicate(replication.Item1, replication.Item2, ctx, clientData, serverData);
                    ctx.Complete();
                }
            }

            s.Stop();
            Console.WriteLine(s.ElapsedMilliseconds);
        }
예제 #3
0
파일: Program.cs 프로젝트: ppetrov/Cchbc
 private static void Replicate(string serverDb, ClientData data, string user, string version, ServerData serverData)
 {
     using (var server = new TransactionContextCreator(serverDb).Create())
     {
         FeatureServerManager.Replicate(user, version, server, data, serverData);
         server.Complete();
     }
 }
예제 #4
0
파일: Program.cs 프로젝트: ppetrov/Cchbc
        private static void Replicate(string serverDb, ClientData data, ServerData serverData)
        {
            var versions = new[]
            {
                @"8.28.79.127",
                @"7.74.19.727",
                @"6.22.29.492",
                @"5.96.69.792",
                @"4.11.27.292",
                @"3.85.19.223",
            };

            using (var ctx = new TransactionContextCreator(serverDb).Create())
            {
                for (var i = 11; i < 120; i++)
                {
                    var user = @"BG" + (i.ToString()).PadLeft(6, '0');

                    if (_r.Next(0, 10) == 0)
                    {
                        continue;
                    }

                    //Replicate(serverDb, data, user, versions[_r.Next(versions.Length)], serverData);
                    var version = versions[_r.Next(versions.Length)];

                    //Replicate(serverDb, data, user, version, serverData);

                    FeatureServerManager.Replicate(user, version, ctx, data, serverData);
                }
                ctx.Complete();
            }
        }
예제 #5
0
        private static int GetBufferSize(ClientData clientData)
        {
            // For the number of elements in every list
            var totalLists = 5;
            var size = totalLists * ShortSize;

            // Id
            size += IntSize * clientData.ContextRows.Count;
            foreach (var row in clientData.ContextRows)
            {
                // Name
                size += GetBufferSize(row.Name);
            }

            // Id
            size += IntSize * clientData.ExceptionRows.Count;
            foreach (var row in clientData.ExceptionRows)
            {
                // Contents
                size += GetBufferSize(row.Contents);
            }

            // Id & Context Id
            size += 2 * IntSize * clientData.FeatureRows.Count;
            foreach (var row in clientData.FeatureRows)
            {
                // Name
                size += GetBufferSize(row.Name);
            }

            // Id, CreatedAt
            size += LongSize * clientData.FeatureEntryRows.Count;
            // FeatureId
            size += IntSize * clientData.FeatureEntryRows.Count;
            // Details
            foreach (var row in clientData.FeatureEntryRows)
            {
                size += GetBufferSize(row.Details);
            }

            // Exception Id & Feature Id
            size += 2 * IntSize * clientData.ExceptionEntryRows.Count;
            // Created At
            size += LongSize * clientData.ExceptionEntryRows.Count;

            return size;
        }