Esempio n. 1
0
        private static void CreateSchema(string connectionString)
        {
            var creator = new TransactionContextCreator(connectionString);
            try
            {
                using (var serverContext = creator.Create())
                {
                    FeatureServerManager.DropSchema(serverContext);
                    serverContext.Complete();

                    Console.WriteLine(@"Drop schema");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            using (var serverContext = creator.Create())
            {
                FeatureServerManager.CreateSchema(serverContext);
                serverContext.Complete();

                Console.WriteLine(@"Schema created");
            }
        }
Esempio n. 2
0
        private static void GenerateData(string path)
        {
            var contextCreator = new TransactionContextCreator(GetSqliteConnectionString(path));

            var featureManager = new FeatureManager();

            if (!File.Exists(path))
            {
                // Create the schema
                FeatureManager.CreateSchema(contextCreator.Create);
            }

            // Load the manager
            featureManager.Load(contextCreator.Create);

            // TODO : !!!
            // Generate exceptions
            // Generate more scenarios
            var s = Stopwatch.StartNew();
            //var scenarios = new[]
            //{
            //	GetUploadImageFeature(),
            //	GetDownloadImageFeature(),
            //	GetLoadImagesAsync(),
            //	GetDeleteImageAsync(),
            //	GetSetAsDefaultAsync(),
            //	GetCreateActivityData(),
            //};
            //foreach (var data in scenarios)
            //{
            //	featureManager.MarkUsageAsync(data);
            //	//featureManager.Write(data);
            //}

            var f = Feature.StartNew(@"Images", @"Upload");
            try
            {
                throw new Exception(@"Unable to display feature");

                featureManager.Write(f);
            }
            catch (Exception ex)
            {
                featureManager.Write(f, ex);
            }

            s.Stop();

            Console.WriteLine(s.ElapsedMilliseconds);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var freshDbPath = @"C:\Users\PetarPetrov\Desktop\data.sqlite";
            var clientDbPath = @"C:\Users\PetarPetrov\Desktop\features.sqlite";
            var serverDbPath = @"C:\Users\PetarPetrov\Desktop\server.sqlite";

            try
            {
                //var addViewModel = new AddActivityViewModel(new ActivityCreator(), new ConsoleDialog());
                //using (var dbContext = new TransactionContextCreator(string.Empty).Create())
                //{
                //	var modelData = new AddActivityViewModelData(dbContext);
                //	modelData.Load();

                //	addViewModel.Load(modelData);

                //	dbContext.Complete();
                //}

                var context = new AppContext((msg, level) =>
                {
                    Console.WriteLine(level + @":" + msg);
                },
                () => new DbContext(GetSqliteConnectionString(freshDbPath)),
                new ConsoleDialog());

                var module = new AppModule(context);
                module.Init();
                module.Load();

                return;

                if (!File.Exists(serverDbPath))
                {
                    CreateSchema(GetSqliteConnectionString(serverDbPath));
                }
                foreach (var date in new[]
                {
                    DateTime.Today.AddDays(-10),
                    DateTime.Today.AddDays(-9),
                    DateTime.Today.AddDays(-8),
                    DateTime.Today.AddDays(-7),
                    DateTime.Today.AddDays(-6),
                    DateTime.Today.AddDays(-5),
                    DateTime.Today.AddDays(-4),
                    DateTime.Today.AddDays(-3),
                    DateTime.Today.AddDays(-2),
                    DateTime.Today.AddDays(-1),
                    DateTime.Today,
                })
                {
                    ClientDataReplication.SimulateDay(serverDbPath, date);
                }

                var fm = new FeatureManager();

                fm.Load(null);

                return;

                //GenerateData(clientDbPath);
                //return;

                //WeatherTest();
                //return;

                if (!File.Exists(serverDbPath))
                {
                    CreateSchema(GetSqliteConnectionString(serverDbPath));
                }

                var w = Stopwatch.StartNew();
                GenerateData(clientDbPath);

                Console.WriteLine(@"Load client data");
                var s = Stopwatch.StartNew();

                ClientData clientData;
                using (var client = new TransactionContextCreator(GetSqliteConnectionString(clientDbPath)).Create())
                {
                    clientData = FeatureAdapter.GetData(client);
                    clientData.FeatureEntryRows.Clear();
                    client.Complete();
                }

                File.Delete(clientDbPath);

                s.Stop();
                Console.WriteLine(s.ElapsedMilliseconds);

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

                while (true)
                {
                    s.Restart();
                    Replicate(GetSqliteConnectionString(serverDbPath), clientData, serverData);
                    s.Stop();
                    Console.WriteLine(s.ElapsedMilliseconds);
                    //Console.ReadLine();
                }

                w.Stop();
                Console.WriteLine(w.ElapsedMilliseconds);
                return;

                var viewModel = new ExceptionsViewModel(
                    new TransactionContextCreator(GetSqliteConnectionString(serverDbPath)).Create,
                    ExceptionsSettings.Default);

                for (var i = 0; i < 100; i++)
                {
                    viewModel.Load(
                    ExceptionsDataProvider.GetTimePeriods,
                    ExceptionsDataProvider.GetVersions,
                    ExceptionsDataProvider.GetExceptions,
                    ExceptionsDataProvider.GetExceptionsCounts);
                }

                w.Stop();
                Console.WriteLine(w.ElapsedMilliseconds);

                Console.WriteLine(@"Time Periods");
                foreach (var v in viewModel.TimePeriods)
                {
                    Console.WriteLine('\t' + string.Empty + v.Name);
                }
                Console.WriteLine();

                Console.WriteLine(@"Versions");
                foreach (var v in viewModel.Versions)
                {
                    Console.WriteLine('\t' + string.Empty + v.Name);
                }
                Console.WriteLine();

                Console.WriteLine(@"Exceptions");
                foreach (var vm in viewModel.LatestExceptions)
                {
                    Console.WriteLine('\t' + string.Empty + new string(vm.Message.Take(40).ToArray()) + $@"... ({vm.CreatedAt.ToString(@"T")}) " + vm.User.Name + $@"({vm.Version.Name})");
                }
                Console.WriteLine();

                return;
                //SearchSourceCode();
                //return;
                //DisplayHistogram();
                //return;

                //GenerateDayReport(serverDbPath);

                //
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return;

            var c = @"Data Source = C:\Users\PetarPetrov\Desktop\ifsa.sqlite; Version = 3;";

            ClientData data;
            using (var client = new TransactionContextCreator(c).Create())
            {
                data = FeatureAdapter.GetData(client);
                client.Complete();
            }

            data.FeatureEntryRows.Add(new DbFeatureEntryRow(@"#", DateTime.Today.AddDays(-1), -4));

            //var s = Stopwatch.StartNew();
            //var result = ClientDataPacker.Pack(data);

            //s.Stop();
            //Console.WriteLine(s.ElapsedMilliseconds);

            //s.Restart();
            //var back = ClientDataPacker.Unpack(result);
            //s.Stop();
            //Console.WriteLine(s.ElapsedMilliseconds);
            //Console.WriteLine(back);

            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine();

            //Console.WriteLine(result.Length);

            return;

            //GenerateProject(PhoenixModel(), @"C:\temp\IfsaBuilder\IfsaBuilder\Phoenix");

            //GenerateProject(WordpressModel(), @"C:\temp\IfsaBuilder\IfsaBuilder\Wordpress");

            //var prj = new ClrProject();
            //prj.Save(@"C:\temp\IfsaBuilder\IfsaBuilder\", project);

            //var AppContext = new AppContext();
            //AppContext.DbContextCreator = new TransactionContextCreator(string.Empty);
            //AppContext.ModalDialog = new ConsoleDialog();
            //var viewModel = new LoginsViewModel(AppContext, new LoginAdapter());
            //try
            //{
            //	viewModel.InsertAsync(new Login(1, @"PPetrov", @"Password", DateTime.Now, false)).Wait();

            //	Console.WriteLine(@"Done");
            //}
            //catch (Exception ex)
            //{
            //	Console.WriteLine(ex);
            //}

            //return;

            //// Register helpers
            //var cache = AppContext.DataCache;
            //cache.Add(new BrandHelper());
            //cache.Add(new FlavorHelper());
            //cache.Add(new ArticleHelper());

            //try
            //{
            //	File.WriteAllText(@"C:\temp\diagnostics.txt", string.Empty);

            //	//var viewModel = new LoginsViewModel(AppContext, new LoginAdapter());
            //	//viewModel.LoadData();

            //	//var v = new LoginViewModel(new Login(1, @"PPetrov", @"QWE234!", DateTime.Now, true));
            //	//var dialog = new ConsoleDialog();
            //	//viewModel.AddAsync(v, dialog).Wait();
            //	//viewModel.AddAsync(v, dialog).Wait();
            //	//viewModel.ChangePasswordAsync(v, dialog, @"sc1f1r3hack").Wait();
            //	//viewModel.AddAsync(v, dialog).Wait();
            //	//viewModel.ChangePasswordAsync(v, dialog, @"sc1f1r3hackV2").Wait();

            //	//foreach (var login in viewModel.Logins)
            //	//{
            //	//	Console.WriteLine(login.Name + " " + v.Password);
            //	//}
            //}
            //catch (Exception e)
            //{
            //	Console.WriteLine(e);
            //}
        }
Esempio n. 5
0
        private static void ReplicateData(string clientDb, string serverDb)
        {
            Console.WriteLine(@"Load client data");
            var s = Stopwatch.StartNew();

            ClientData data;
            using (var client = new TransactionContextCreator(clientDb).Create())
            {
                data = FeatureAdapter.GetData(client);
                client.Complete();
            }

            s.Stop();
            Console.WriteLine(s.ElapsedMilliseconds);

            //Replicate(serverDb, data, null);
        }
Esempio n. 6
0
 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();
     }
 }
Esempio n. 7
0
        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();
            }
        }