Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishMessagesMiddleware{TState, TProcessHandler}"/> class.
 /// </summary>
 /// <param name="commandBus">Command bus.</param>
 /// <param name="notificationBus">Notification bus.</param>
 /// <param name="store">Process manager command store.</param>
 public PublishMessagesMiddleware(
     ICommandBus <DefaultCommandBusOptions> commandBus,
     INotificationBus notificationBus,
     IProcessStore <TProcessHandler> store)
 {
     this.commandBus      = commandBus;
     this.notificationBus = notificationBus;
     this.store           = store;
 }
Exemplo n.º 2
0
 public LogViewModel(INotificationBus bus)
 {
     Notifications        = bus.Notifications.ToReactiveCollection();
     SelectedNotification = new ReactiveProperty <INotification>();
     Details = SelectedNotification?.Select(sn =>
     {
         return(sn is BackupNotification bn
                 ? new BackupLogDetailViewModel(bn.PositionWindowsByProcesses)
                 : default(object));
     }).ToReactiveProperty();
 }
Exemplo n.º 3
0
 public AuthenticationController(ICommandBus commandBus, IViewRepository viewRepository, INotificationBus notificationBus)
 {
     _viewRepository  = viewRepository;
     _notificationBus = notificationBus;
     _commandBus      = commandBus.CheckNull("commandBus");
 }
Exemplo n.º 4
0
 public UserEventHandler(IDocumentStore documentStore, INotificationBus bus)
 {
     _documentStore = documentStore;
     _bus           = bus;
 }
 public static IObservable <BackupAndRestorePosition.EventType> CreateFromSystemEvents(INotificationBus bus)
 {
     return(CreateFromSessionSwitch(bus)
            .Merge(CreateFromPowerMode(bus)));
 }
Exemplo n.º 6
0
 public MainViewModel(INotificationBus bus)
 {
     Testing = new TestingViewModel();
     Log     = new LogViewModel(bus);
 }
 private static IObservable <BackupAndRestorePosition.EventType> CreateFromPowerMode(INotificationBus bus)
 {
     return(Observable.FromEventPattern <PowerModeChangedEventHandler, PowerModeChangedEventArgs>(
                ev => SystemEvents.PowerModeChanged += ev,
                ev => SystemEvents.PowerModeChanged -= ev
                )
            .Select(eventPattern => eventPattern.EventArgs.Mode)
            .Where(mode => mode != PowerModes.StatusChange)
            .Select(mode =>
     {
         if (mode == PowerModes.Suspend)
         {
             bus.Emit(new BackupOrRestore("Backup triggered by Suspend event"));
             return BackupAndRestorePosition.EventType.Backup;
         }
         else
         {
             bus.Emit(new BackupOrRestore("Restore triggered by Power Event event"));
             return BackupAndRestorePosition.EventType.Restore;
         }
     }));
 }
 private static IObservable <BackupAndRestorePosition.EventType> CreateFromSessionSwitch(INotificationBus bus)
 {
     return(Observable.FromEventPattern <SessionSwitchEventHandler, SessionSwitchEventArgs>(
                ev => SystemEvents.SessionSwitch += ev,
                ev => SystemEvents.SessionSwitch -= ev)
            .Select(eventPattern => eventPattern.EventArgs.Reason)
            .Where(reason => reason == SessionSwitchReason.SessionLock || reason == SessionSwitchReason.SessionUnlock)
            .Select(reason =>
     {
         if (reason == SessionSwitchReason.SessionLock)
         {
             bus.Emit(new BackupOrRestore("Backup triggered by SessionLock event"));
             return BackupAndRestorePosition.EventType.Backup;
         }
         else
         {
             bus.Emit(new BackupOrRestore("Restore triggered by SessionUnlock event"));
             return BackupAndRestorePosition.EventType.Restore;
         }
     }));
 }
 public PostionRestoreOperator(INotificationBus notificationBus)
 {
     _notificationBus = notificationBus;
 }
Exemplo n.º 10
0
 public AuthenticationController(ICommandBus commandBus, IViewRepository viewRepository, INotificationBus notificationBus)
 {
     _viewRepository = viewRepository;
     _notificationBus = notificationBus;
     _commandBus = commandBus.CheckNull("commandBus");
 }
Exemplo n.º 11
0
        public BackupAndRestorePosition(IObservable <EventType> events, PositionWindowsByProcessCollector collector, PostionRestoreOperator restoreOperator, IReadOnlyCollection <string> excludedProcesses, INotificationBus bus)
        {
            _collector = collector;

            var options = new PositionWindowsByProcessCollectorOptions(
                window => string.IsNullOrWhiteSpace(window.Title)
                //|| window.Rectangle.IsEmpty
                //|| window.Rectangle.IsOffScreen() since there is a monitor left to main window, this does not work
                || window.Placement.showCmd == User32.ShowState.SW_HIDE ||
                !window.IsVisible
                ,
                process => excludedProcesses.Any(n => process.ProcessName.Contains(n))
                );

            _subscription = events
                            .Do(e =>
            {
                if (e == EventType.Backup)
                {
                    _positionWindowsByProcesses = _collector.Collect(options);
                    bus.Emit(new BackupNotification(_positionWindowsByProcesses));
                    Console.WriteLine($"{DateTime.Now} - BACKUP");
                }
                else
                {
                    restoreOperator.Restore(_positionWindowsByProcesses);
                    Console.WriteLine($"{DateTime.Now} - RESTORE");
                }
            })
                            .Subscribe();
        }