Exemplo n.º 1
0
        public void TestReset()
        {
            var mock   = new Mock <Infrastructures.IStopwatch>();
            var called = false;

            mock.Setup(m => m.Reset()).Callback(() => called = true);

            using (var sw = new StopwatchService(mock.Object))
                using (var are = new AutoResetEvent(false))
                {
                    sw.ObserveProperty(x => x.Ellapsed, false)
                    .Subscribe(_ => are.Set());

                    sw.Start();
                    sw.Lap();
                    sw.Lap();
                    sw.Lap();
                    are.WaitOne(10);
                    sw.Reset();

                    Assert.IsTrue(called);
                    Assert.IsTrue(are.WaitOne(10));
                    Assert.AreEqual(TimeSpan.Zero, sw.Ellapsed);
                    Assert.AreEqual(0, sw.LapTimes.Count);
                }
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            // Setup authentication.
            app.UseBasicAuthentication("stopwatch", Authenticate.Basic);
            app.UseAPIKeyAuthentication(Authenticate.APIKey);

            // Build DI container. This is shared between Web API and SignalR.
            var stopwatchService = new StopwatchService(
                new InMemoryTimestampRepository(), // Uncomment to use in-memory data storage.
                //new AzureTableStorageTimestampRepository(), // Uncomment to use Azure Table Storage.
                () => DateTime.UtcNow.Ticks);
            var container = new Container();

            container.RegisterSingleton(typeof(IStopwatchService), stopwatchService);
            // That's the SignalR timer to broadcast elapsed time to user each second.
            container.RegisterSingleton(
                typeof(IObservable <Unit>),
                Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ => Unit.Default));

            // Setup Web API.
            var httpConfiguration = new HttpConfiguration();

            ConfigureWebApi(httpConfiguration, container);
            app.UseWebApi(httpConfiguration);

            // Setup SignalR.
            var hubConfiguration = new HubConfiguration();

            ConfigureSignalR(hubConfiguration, container);
            app.MapSignalR(hubConfiguration);
        }
Exemplo n.º 3
0
        public void Configuration(IAppBuilder app)
        {
            // Setup authentication.
            app.UseBasicAuthentication("stopwatch", Authenticate.Basic);
            app.UseAPIKeyAuthentication(Authenticate.APIKey);

            // Build DI container. This is shared between Web API and SignalR.
            long initialTicks     = DateTime.UtcNow.Ticks;
            var  stopwatchService = new StopwatchService(
                new InMemoryTimestampRepository(), // Uncomment to use in-memory data storage.
                //new AzureTableStorageTimestampRepository(), // Uncomment to use Azure Table Storage.
                () =>                              // Timer will advance 1ms each time it is queried.
            {
                initialTicks += TimeSpan.TicksPerMillisecond;
                return(initialTicks);
            });
            var container = new Container();

            container.RegisterSingleton(typeof(IStopwatchService), stopwatchService);
            // That's the SignalR timer to broadcast elapsed time to user when subject requests.
            container.RegisterSingleton(typeof(IObservable <Unit>), StopwatchHubTest.Subject.AsObservable());

            // Setup Web API.
            var httpConfiguration = new HttpConfiguration();

            ConfigureWebApi(httpConfiguration, container);
            app.UseWebApi(httpConfiguration);

            // Setup SignalR.
            var hubConfiguration = new HubConfiguration();

            ConfigureSignalR(hubConfiguration, container);
            app.MapSignalR(hubConfiguration);
        }
Exemplo n.º 4
0
        void AppState_BusyComplete(object sender, EventArgs e)
        {
            StopwatchService.StopWatch(_performanceWatchTimerId);

            NewRelicBrowserAgentHelper.InlineHit(new NewRelicInlineHitCommand("EmployeeView")
            {
                FeTime      = StopwatchService.Elapsed(_performanceWatchTimerId),
                TotalBeTime = StopwatchService.Elapsed(_performanceWatchTimerId + "_TotalBeTime"),
            });

            GSPApplicationService.Current.AppState.BusyComplete -= AppState_BusyComplete;
        }
Exemplo n.º 5
0
        public void TestEllapsed()
        {
            var mock   = new Mock <Infrastructures.IStopwatch>();
            var called = false;

            mock.Setup(m => m.Elapsed).Callback(() => called = true);

            using (var sw = new StopwatchService(mock.Object))
            {
                var ellapsed = sw.Ellapsed;
                Assert.IsTrue(called);
            }
        }
Exemplo n.º 6
0
        public void TestLap()
        {
            var mock = new Mock <Infrastructures.IStopwatch>();

            using (var sw = new StopwatchService(mock.Object))
            {
                sw.Start();

                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(10));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(30));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(60));
                sw.Lap();
                mock.Setup(m => m.Elapsed).Returns(TimeSpan.FromMilliseconds(100));
                sw.Stop();

                Assert.AreEqual(10, sw.LapTimes[0].TotalMilliseconds);
                Assert.AreEqual(20, sw.LapTimes[1].TotalMilliseconds);
                Assert.AreEqual(30, sw.LapTimes[2].TotalMilliseconds);
                Assert.AreEqual(40, sw.LapTimes[3].TotalMilliseconds);
            }
        }
Exemplo n.º 7
0
        public void TestIsRunning()
        {
            var mock   = new Mock <Infrastructures.IStopwatch>();
            var called = false;

            mock.Setup(m => m.IsRunning).Callback(() => called = true);

            using (var sw = new StopwatchService(mock.Object))
                using (var are = new AutoResetEvent(false))
                {
                    sw.ObserveProperty(x => x.IsRunning, false)
                    .Subscribe(_ => are.Set());

                    var isRunning = sw.IsRunning;
                    Assert.IsTrue(called);

                    sw.Start();
                    Assert.IsTrue(are.WaitOne(10));

                    sw.Stop();
                    Assert.IsTrue(are.WaitOne(10));
                }
        }
Exemplo n.º 8
0
        private void LoadEmployee(int employeeId, DateTime?searchDate, Action action)
        {
            var query = new QueryEmployeeById
            {
                EmployeeId             = employeeId,
                BetweenStartAndEndDate = searchDate
            };

            StopwatchService.StartWatch(_performanceWatchTimerId + "_TotalBeTime");

            // Reload employee from server
            EmployeeService.GetEmployee(query, (res, err) =>
            {
                StopwatchService.StopWatch(_performanceWatchTimerId + "_TotalBeTime");

                if (err.HasErrors)
                {
                    if (err.ApiErrorMessage == "NoAccess")
                    {
                        //Thread.CurrentThread.CurrentCulture = new CultureInfo(GSPApplicationService.Current.CurrentLangId);
                        //Thread.CurrentThread.CurrentUICulture = new CultureInfo(GSPApplicationService.Current.CurrentLangId);
                        var dialogMessage = string.Format(UIResources.Resources.Global_NoAccessMessge, UIResources.Resources.Global_Employee);
                        ThreadHelper.ExecuteOnUI(
                            () => Dialog.ShowDialog(UIResources.Resources.Global_NoAccessTitle, dialogMessage, false, null));
                        GspNavigation.CloseView("EmployeeView", ViewId);
                    }
                    return;
                }
                ThreadHelper.ExecuteOnUI(() =>
                {
                    Employee = res;
                    LoadChildViewmodels();
                    action.Invoke();
                });
            });
        }
Exemplo n.º 9
0
 public StopwatchFilter(StopwatchService watchService)
 {
     this.watchService = watchService;
 }
Exemplo n.º 10
0
 private void StartPerformanceTimer()
 {
     GSPApplicationService.Current.AppState.BusyComplete += AppState_BusyComplete;
     StopwatchService.StartWatch(_performanceWatchTimerId);
 }
Exemplo n.º 11
0
        static async Task Main(string[] args)
        {
            var logPath = @"E:\proj\my\ImageGallery\log\pexel";

            var pixel_dbPath = @"E:\proj\my\ImageGallery\pixel.db";

            //var im_dbPath = @"E:\proj\my\ImageGallery\im.db";
            var im_dbPath = @"E:\proj\my\ImageGallery\test.im.db";

            //var jsonDbPath= @"E:\proj\my\ImageGallery\db.json";
            var jsonDbPath = @"E:\proj\my\ImageGallery\test.db.json";


            var userAgentsPath      = @"E:\proj\github\ichensky\ImageGallery\data\useragents.txt";
            var pixelMigrationsPath = @"E:\proj\github\ichensky\ImageGallery\src\db\pixel.txt";
            var imMigrationsPath    = @"E:\proj\github\ichensky\ImageGallery\src\db\im.txt";

            var pathToGoogleKeys = @"E:\proj\github\ichensky\ImageGallery\keys\google";
            var msVisionKeysPath = @"E:\proj\github\ichensky\ImageGallery\keys\msvisionkeys.txt";

            LogManager.Configuration = LoggerService.DefaultConfiguration(logPath);
            var logger = LogManager.GetLogger(Services.Logger.log.ToString());

            var userAgents = await File.ReadAllLinesAsync(userAgentsPath);

            var userAgentsService = new UserAgentService(logger, userAgents);

            var stopwatchService = new StopwatchService(logger);
            var attemptService   = new AttemptService(logger);

            var httpClientSerive = new HttpClientService(logger, stopwatchService, userAgentsService);
            var usersParser      = new UsersParser(logger, httpClientSerive, attemptService);
            var imagesParser     = new ImagesParser(logger, httpClientSerive, attemptService);
            var imageMetaParser  = new ImageMetaParser(logger, httpClientSerive, attemptService);
            var fileLoader       = new FileLoader(logger, httpClientSerive, attemptService);

            var googleService = new GoogleService(logger, pathToGoogleKeys);

            var msvisionService = new MSVisionService(logger, msVisionKeysPath);

            var pixel_builder = new DbContextOptionsBuilder().UseSqlite($"Data Source={pixel_dbPath}");

            var imBuilder = new DbContextOptionsBuilder().UseSqlite($"Data Source={im_dbPath}");


            //await googleService.Clean();

            //var migrationService = new MigrationsService(pixel_builder.Options);
            //logger.Info("Applying migrations to database.");
            //await migrationService.MigrateAsync(migrationsPath);

            var pixelService = new PixelService(logger, pixel_builder.Options,
                                                usersParser, imagesParser, imageMetaParser,
                                                fileLoader, googleService, msvisionService);

            //await pixelService.UpdateUsers(5514);
            //await pixelService.UpdateUsersImages(16124);
            //await pixelService.UpdateImagesMeta(388970);

            //await pixelService.PixelImagesToGoogle();
            //await pixelService.CleanGoogleImages();

            //--
            //--
            //await pixelService.LoadMSVisionMeta();
            //--
            //--
            //var jsonDb = await pixelService.GenJsonDb();
            //File.WriteAllText(jsonDbPath, jsonDb);
            //--
            //--



            if (File.Exists(im_dbPath))
            {
                var err = "Deleting database file ...";
                logger.Warn(err);
                File.Delete(im_dbPath);
            }
            var migrationService = new MigrationsService(imBuilder.Options);

            logger.Info("Applying migrations to database.");
            await migrationService.MigrateAsync(imMigrationsPath);



            //var im_connection = new Microsoft.Data.Sqlite.SqliteConnection($"DataSource={im_dbPath}");
            //im_connection.Open();
            //var connectionInMemory = new Microsoft.Data.Sqlite.SqliteConnection("DataSource=:memory:");
            //connectionInMemory.Open();
            //var builderInMemory = new DbContextOptionsBuilder().UseSqlite(connectionInMemory);
            //im_connection.BackupDatabase(connectionInMemory);

            var pixelToImageGalleryService = new PixelToImageGalleryService(
                logger, pixel_builder.Options,
                imBuilder.Options);

            //builderInMemory.Options);

            //--
            //var jsonDb = await pixelToImageGalleryService.GenJsonDb();
            //File.WriteAllText(jsonDbPath, jsonDb);
            //--

            var json = File.ReadAllText(jsonDbPath);
            await pixelToImageGalleryService.GenDb(json);

            //connectionInMemory.BackupDatabase(im_connection);

            Console.WriteLine("Hello World!");
        }
Exemplo n.º 12
0
 public HobbitsController(IDatabase database, StopwatchService watchService, IConsoleLogger loggingService)
 {
     this.database       = database;
     this.watchService   = watchService;
     this.loggingService = loggingService;
 }
Exemplo n.º 13
0
 public HobbitsController(IDatabase database, ILogger logger, StopwatchService watchService)
 {
     this.database     = database;
     this.logger       = logger;
     this.watchService = watchService;
 }