Ejemplo n.º 1
0
 public OverlayService()
 {
     using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
     {
         _show = new Subject <OverlayViewModel>()
                 .DisposeWith(this);
     }
 }
Ejemplo n.º 2
0
        static CultureService()
        {
            using (Duration.Measure(Logger, "Constructor - " + typeof(CultureService).Name))
            {
                Thread.CurrentThread.CurrentCulture   = Cultures.First().Value;
                Thread.CurrentThread.CurrentUICulture = Cultures.First().Value;

                Changed = new BehaviorSubject <string>(Cultures.First().Key);
            }
        }
Ejemplo n.º 3
0
        public GesturesService()
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                _timer = new DispatcherTimer(TimeSpan.Zero, DispatcherPriority.ApplicationIdle, TimerCallback,
                                             Application.Current.Dispatcher);
                _timer.Stop();
            }

            Disposable.Create(() => _timer.Stop())
            .DisposeWith(this);
        }
Ejemplo n.º 4
0
        public HeartbeatService(TimeSpan interval, ISchedulerService schedulerService)
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                _listen = Observable.Interval(interval, schedulerService.TaskPool)
                          .AsUnit()
                          .Publish();

                _listen.Connect()
                .DisposeWith(this);
            }
        }
Ejemplo n.º 5
0
        public IdleService(ISchedulerService schedulerService)
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                var mainWindow = Application.Current.MainWindow;
                if (mainWindow == null)
                {
                    throw new Exception("Main window has not been created yet!");
                }

                _idleObservable = Observable.FromEventPattern(h => mainWindow.Dispatcher.Hooks.DispatcherInactive += h,
                                                              h => mainWindow.Dispatcher.Hooks.DispatcherInactive -= h, schedulerService.TaskPool)
                                  .Publish();

                _idleObservable.Connect()
                .DisposeWith(this);
            }
        }
Ejemplo n.º 6
0
        public DiagnosticsService(IIdleService idleService, ISchedulerService schedulerService)
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                _disposable = new CompositeDisposable()
                              .DisposeWith(this);

                _sync = new object();

                _countersObservable = CreatePerformanceCountersAsync()
                                      .DelaySubscription(Constants.UI.Diagnostics.DiagnosticsSubscriptionDelay, schedulerService.TaskPool)
                                      .SubscribeOn(schedulerService.TaskPool)
                                      .ObserveOn(schedulerService.TaskPool)
                                      .CombineLatest(
                    idleService.Idling.Buffer(Constants.UI.Diagnostics.DiagnosticsIdleBuffer,
                                              schedulerService.TaskPool).Where(x => x.Any()), (x, y) => x)
                                      .Replay(1);
            }
        }
Ejemplo n.º 7
0
        public SettingsService(ISchedulerService schedulerService)
        {
            using (Duration.Measure(Logger, "Constructor - " + GetType().Name))
            {
                _persist = new Subject <bool>()
                           .DisposeWith(this);

                _persist.ObserveOn(schedulerService.TaskPool)
                .Synchronize(_persistSync)
                .Subscribe(_ => Persist())
                .DisposeWith(this);

                _settings = new Dictionary <string, ISettings>();

                var serializedSettings = Properties.Settings.Default.GlobalSettings;

                if (!string.IsNullOrEmpty(serializedSettings))
                {
                    JsonConvert.DeserializeObject <Dictionary <string, IEnumerable <Dtos.Setting> > >(
                        serializedSettings, _serializerSettings)
                    .ForEach(y => _settings.Add(y.Key, CreateSettings(y.Value)));
                }
            }
        }
Ejemplo n.º 8
0
        private static IObservable <Counters> CreatePerformanceCountersAsync()
        {
            return(Observable.Create <Counters>(x =>
            {
                var disposable = new CompositeDisposable();

                try
                {
                    var processName = GetProcessInstanceName();

                    Logger.Info(
                        "Creating performance counter 'Working Set'");

                    var workingSetCounter =
                        new PerformanceCounter("Process",
                                               "Working Set", processName);
                    disposable.Add(workingSetCounter);

                    Logger.Info(
                        "Creating performance counter '% Processor Time'");

                    var cpuCounter =
                        new PerformanceCounter("Process",
                                               "% Processor Time", processName);
                    disposable.Add(cpuCounter);

                    using (
                        Duration.Measure(Logger,
                                         "Initialising performance counters (after creation)")
                        )
                    {
                        workingSetCounter.NextValue();
                        cpuCounter.NextValue();
                    }

                    x.OnNext(new Counters(workingSetCounter,
                                          cpuCounter));

                    Logger.Info("Ready");
                }
                catch (ArgumentException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (InvalidOperationException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (Win32Exception exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (PlatformNotSupportedException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }
                catch (UnauthorizedAccessException exn)
                {
                    LogFailToCreatePerformanceCounter(x, exn);
                }

                return disposable;
            }));
        }