コード例 #1
0
ファイル: DispatcherPage.xaml.cs プロジェクト: sung-su/maui
        void OnTimerClicked(object sender, EventArgs e)
        {
            if (_timer != null)
            {
                _timer.Stop();
                _timer          = null;
                timerLabel.Text = "Stopped!";
                return;
            }

            var now     = DateTime.Now;
            var counter = 0;

            _timer = timerLabel.Dispatcher.CreateTimer();

            _timer.Interval    = TimeSpan.FromSeconds(3);
            _timer.IsRepeating = true;
            _timer.Start();

            timerLabel.Text = "Started!";

            _timer.Tick += (_, _) =>
            {
                var later = DateTime.Now;
                counter++;
                timerLabel.Text = $"I am on a 3 second timer! {counter} ticks => {later - now}";
            };
        }
コード例 #2
0
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, string startupDirectory, ShellProfile shellProfile,
                                 IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            Title = DefaultTitle;

            _connectedEvent = new ManualResetEventSlim(false);

            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.KeyBindingsChanged         += OnKeyBindingsChanged;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _trayProcessCommunicationService.TerminalExited += OnTerminalExited;

            _dialogService          = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            _startupDirectory       = startupDirectory;
            _shellProfile           = shellProfile;
            _applicationView        = applicationView;
            _clipboardService       = clipboardService;

            _resizeOverlayTimer          = dispatcherTimer;
            _resizeOverlayTimer.Interval = new TimeSpan(0, 0, 2);
            _resizeOverlayTimer.Tick    += OnResizeOverlayTimerFinished;

            CloseCommand            = new RelayCommand(async() => await TryClose().ConfigureAwait(false));
            FindNextCommand         = new RelayCommand(async() => await FindNext().ConfigureAwait(false));
            FindPreviousCommand     = new RelayCommand(async() => await FindPrevious().ConfigureAwait(false));
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);
        }
コード例 #3
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ShellProfileAdded          += OnShellProfileAdded;
            _settingsService.ShellProfileDeleted        += OnShellProfileDeleted;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), () => AddTerminal(null, false, Guid.Empty));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), () => AddTerminal(null, true, Guid.Empty));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), () => SelectedTerminal.EditTitle());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), () => NewWindow(false));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewWindow), () => NewWindow(true));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ShowSettings), ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ToggleFullScreen), ToggleFullScreen);

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), () => AddTerminal(profile.WorkingDirectory, false, profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false, Guid.Empty));
            ShowAboutCommand    = new RelayCommand(ShowAbout);
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
コード例 #4
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(Command.NewTab, () => AddTerminal(null, false));
            _keyboardCommandService.RegisterCommandHandler(Command.ConfigurableNewTab, () => AddTerminal(null, true));
            _keyboardCommandService.RegisterCommandHandler(Command.CloseTab, CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NextTab, SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(Command.PreviousTab, SelectPreviousTab);
            _keyboardCommandService.RegisterCommandHandler(Command.NewWindow, NewWindow);
            _keyboardCommandService.RegisterCommandHandler(Command.ShowSettings, ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(Command.ToggleFullScreen, ToggleFullScreen);
            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false));
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
コード例 #5
0
ファイル: BaseClock.cs プロジェクト: ruban258/SimpleWPFTimer
 protected BaseClock(ILogger logger, IConfigurationValues config, IDispatcherTimer timer)
 {
     _timer          = timer ?? throw new ArgumentNullException(nameof(timer));
     _logger         = logger;
     _timer.Interval = TimeSpan.FromSeconds(config?.TimerInterval ?? 1);
     RegisterEvents();
 }
コード例 #6
0
        public AgeUpdatingService(IEnumerable <IBirthday> participants, IDispatcherTimer timer, int capacity = 4)
        {
            _timer        = timer;
            _timer.Tick  += OnTick;
            _participants = new OrderedList <KeyValuePair <TimeSpan, IBirthday> >(capacity, new KeyComparer <TimeSpan, IBirthday>());
            _participants.AddRange(participants.Select(p => new KeyValuePair <TimeSpan, IBirthday>(p.DateTimeBirth.TimeOfDay, p)));

            if (_participants.Any())
            {
                TimeSpan nowTime = DateTime.Now.TimeOfDay;
                _nextIndex = _participants.BinarySearch(new KeyValuePair <TimeSpan, IBirthday>(nowTime, null));
                if (_nextIndex < 0)
                {
                    _nextIndex = ~_nextIndex;
                }
                TimeSpan interval;
                if (_nextIndex >= _participants.Count)
                {
                    _nextIndex = 0;
                    interval   = TimeSpan.FromDays(1) - nowTime + _participants[0].Key;
                }
                else
                {
                    interval = _participants[_nextIndex].Key - nowTime;
                }
                StartTimer(interval);
            }
        }
コード例 #7
0
ファイル: Utils.cs プロジェクト: senlinms/ffmediaelement
 /// <summary>
 /// Initializes static members of the <see cref="Utils"/> class.
 /// </summary>
 static Utils()
 {
     LogOutputter           = Platform.CreateTimer(CoreDispatcherPriority.Background);
     LogOutputter.Interval  = Constants.LogOutputterUpdateInterval;
     LogOutputter.Tick     += LogOutputter_Tick;
     LogOutputter.IsEnabled = true;
     LogOutputter.Start();
 }
コード例 #8
0
        public OverlayBoardViewModel(IBoardViewModel boardViewModel, IDispatcherTimer dispatcherTimer)
        {
            _dispatcherTimer = dispatcherTimer;
            _boardViewModel  = boardViewModel;

            _dispatcherTimer.Tick += (s, e) => {
                _dispatcherTimer.Stop();
                BoardViewModel.Visible = false;
            };
        }
コード例 #9
0
        public OverlayHoleCardsViewModel(IHoleCardsViewModel holeCardsViewModel, IDispatcherTimer dispatcherTimer)
        {
            _dispatcherTimer    = dispatcherTimer;
            _holeCardsViewModel = holeCardsViewModel;

            _dispatcherTimer.Tick += (s, e) => {
                _dispatcherTimer.Stop();
                HoleCardsViewModel.Visible = false;
            };
        }
コード例 #10
0
ファイル: CountdownTimer.cs プロジェクト: tbentropy/GoOutside
 internal CountdownTimer(
     ITimeProvider timeProvider,
     TimeSpan duration,
     TimeSpan interval)
 {
     _TimeProvider = timeProvider;
     _Duration = duration;
     _IntervalTimer = timeProvider.CreateDispatcherTimer(interval);
     _IntervalTimer.Tick += OnTick;
 }
コード例 #11
0
#pragma warning restore SA1401 // Fields must be private
        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MediaElementCore"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="isInDesignTime">if set to <c>true</c> [is in design time].</param>
        public MediaElementCore(object parent, bool isInDesignTime)
        {
            Parent   = parent;
            Logger   = new GenericMediaLogger <MediaElementCore>(this);
            Commands = new MediaCommandManager(this);

            if (!isInDesignTime)
            {
                // The UI Property update timer is responsible for timely updates to properties outside of the worker threads
                // We use the loaded priority because it is the priority right below the Render one.
                UIPropertyUpdateTimer          = Platform.CreateTimer(CoreDispatcherPriority.Loaded);
                UIPropertyUpdateTimer.Interval = Constants.UIPropertyUpdateInterval;

                // The tick callback performs the updates
                UIPropertyUpdateTimer.Tick += (s, e) =>
                {
                    UpdatePosition(IsOpen ? Clock?.Position ?? TimeSpan.Zero : TimeSpan.Zero);

                    if (HasMediaEnded == false && CanReadMorePackets && (IsOpening || IsOpen))
                    {
                        var bufferedLength = Container?.Components?.PacketBufferLength ?? 0d;
                        BufferingProgress = Math.Min(1d, bufferedLength / BufferCacheLength);
                        var oldIsBugffering = IsBuffering;
                        var newIsBuffering  = bufferedLength < BufferCacheLength;

                        if (oldIsBugffering == false && newIsBuffering)
                        {
                            RaiseBufferingStartedEvent();
                        }
                        else if (oldIsBugffering && newIsBuffering == false)
                        {
                            RaiseBufferingEndedEvent();
                        }

                        IsBuffering = HasMediaEnded == false && newIsBuffering;
                    }
                    else
                    {
                        BufferingProgress = 0;
                        IsBuffering       = false;
                    }

                    var downloadProgress = Math.Min(1d, Math.Round((Container?.Components.PacketBufferLength ?? 0d) / DownloadCacheLength, 3));
                    if (double.IsNaN(downloadProgress))
                    {
                        downloadProgress = 0;
                    }
                    DownloadProgress = downloadProgress;
                };

                // Go ahead and fire up the continuous updates
                UIPropertyUpdateTimer.IsEnabled = true;
                UIPropertyUpdateTimer.Start();
            }
        }
コード例 #12
0
ファイル: BotMain.cs プロジェクト: ssznakabulgarian/BitMods
 public BotMain(IDispatcher dispatcher, string id)
 {
     if (dispatcher == null)
     {
         throw new ArgumentNullException();
     }
     Id                     = id;
     mDispatcher            = dispatcher;
     mProtocolTimeout       = mDispatcher.CreateTimer();
     mProtocolTimeout.Tick += MProtocolTimeout_Tick;
 }
コード例 #13
0
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, ShellProfile shellProfile,
                                 IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService, string terminalState = null)
        {
            SettingsService = settingsService;
            SettingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            SettingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            SettingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            SettingsService.KeyBindingsChanged         += OnKeyBindingsChanged;

            _terminalOptions = SettingsService.GetTerminalOptions();

            TrayProcessCommunicationService = trayProcessCommunicationService;

            DialogService           = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            ApplicationView         = applicationView;
            ClipboardService        = clipboardService;

            ShellProfile  = shellProfile;
            TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId);

            TabThemes = new ObservableCollection <TabTheme>(SettingsService.GetTabThemes());
            TabTheme  = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

            CloseCommand            = new RelayCommand(async() => await TryClose().ConfigureAwait(false));
            CloseLeftTabsCommand    = new RelayCommand(CloseLeftTabs);
            CloseRightTabsCommand   = new RelayCommand(CloseRightTabs);
            CloseOtherTabsCommand   = new RelayCommand(CloseOtherTabs);
            FindNextCommand         = new RelayCommand(FindNext);
            FindPreviousCommand     = new RelayCommand(FindPrevious);
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);
            SelectTabThemeCommand   = new RelayCommand <string>(SelectTabTheme);
            EditTitleCommand        = new AsyncCommand(EditTitle);
            DuplicateTabCommand     = new RelayCommand(DuplicateTab);

            if (!String.IsNullOrEmpty(terminalState))
            {
                Restore(terminalState);
            }

            Terminal = new Terminal(TrayProcessCommunicationService, _terminalId);
            Terminal.KeyboardCommandReceived += Terminal_KeyboardCommandReceived;
            Terminal.OutputReceived          += Terminal_OutputReceived;
            Terminal.SizeChanged             += Terminal_SizeChanged;
            Terminal.TitleChanged            += Terminal_TitleChanged;
            Terminal.Exited += Terminal_Exited;
            Terminal.Closed += Terminal_Closed;

            Overlay = new OverlayViewModel(dispatcherTimer);
        }
コード例 #14
0
        public TerminalViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService,
                                 IKeyboardCommandService keyboardCommandService, ApplicationSettings applicationSettings, string startupDirectory, ShellProfile shellProfile,
                                 IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            SettingsService = settingsService;
            SettingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            SettingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            SettingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            SettingsService.KeyBindingsChanged         += OnKeyBindingsChanged;

            TrayProcessCommunicationService = trayProcessCommunicationService;

            DialogService           = dialogService;
            _keyboardCommandService = keyboardCommandService;
            ApplicationSettings     = applicationSettings;
            StartupDirectory        = startupDirectory;
            ApplicationView         = applicationView;
            ClipboardService        = clipboardService;

            ShellProfile  = shellProfile;
            TerminalTheme = shellProfile.TerminalThemeId == Guid.Empty ? SettingsService.GetCurrentTheme() : SettingsService.GetTheme(shellProfile.TerminalThemeId);

            TabThemes = new ObservableCollection <TabTheme>(SettingsService.GetTabThemes());
            TabTheme  = TabThemes.FirstOrDefault(t => t.Id == ShellProfile.TabThemeId);

            _resizeOverlayTimer          = dispatcherTimer;
            _resizeOverlayTimer.Interval = new TimeSpan(0, 0, 2);
            _resizeOverlayTimer.Tick    += OnResizeOverlayTimerFinished;

            CloseCommand            = new RelayCommand(async() => await TryClose().ConfigureAwait(false));
            FindNextCommand         = new RelayCommand(FindNext);
            FindPreviousCommand     = new RelayCommand(FindPrevious);
            CloseSearchPanelCommand = new RelayCommand(CloseSearchPanel);
            SelectTabThemeCommand   = new RelayCommand <string>(SelectTabTheme);
            EditTitleCommand        = new AsyncCommand(EditTitle);

            if (!string.IsNullOrWhiteSpace(StartupDirectory))
            {
                ShellProfile.WorkingDirectory = StartupDirectory;
            }

            Terminal = new Terminal(TrayProcessCommunicationService);
            Terminal.KeyboardCommandReceived += Terminal_KeyboardCommandReceived;
            Terminal.OutputReceived          += Terminal_OutputReceived;
            Terminal.SizeChanged             += Terminal_SizeChanged;
            Terminal.TitleChanged            += Terminal_TitleChanged;
            Terminal.Closed += Terminal_Closed;
        }
コード例 #15
0
ファイル: Search.cs プロジェクト: Sykorajakku/FileWalker
        public Query(string searchedWord, string directory, int queueSize, IDispatcher dispatcher, IDispatcherTimer dispatcherTimer)
        {
            Dispatcher               = dispatcher;
            DispatcherTimer          = dispatcherTimer;
            DispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);

            FileProcessor = new FileProcessor(searchedWord, Dispatcher);

            DispatcherTimer.Handler = (sender, args) => {
                FileProcessor.Results.CurrentTime = DateTime.Now;
            };

            Files     = new FileProvider(directory).GetEnumerator();
            QueueSize = queueSize;
            Queue     = new Queue <FileInfo>();
        }
コード例 #16
0
        protected override void OnAppearing()
        {
            _timer = Dispatcher.CreateTimer();

            _timer.Interval    = TimeSpan.FromMilliseconds(15);
            _timer.IsRepeating = true;
            _timer.Start();

            double total = polyline.StrokeDashArray[0] + polyline.StrokeDashArray[1];

            _timer.Tick += (_, _) =>
            {
                double secs = DateTime.Now.TimeOfDay.TotalSeconds;
                polyline.StrokeDashOffset = total * (secs % 1);
            };
        }
コード例 #17
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _trayProcessCommunicationService             = trayProcessCommunicationService;
            _dialogService          = dialogService;
            _applicationView        = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(Command.NewTab, () => AddTerminal(null, false));
            _keyboardCommandService.RegisterCommandHandler(Command.ConfigurableNewTab, () => AddTerminal(null, true));
            _keyboardCommandService.RegisterCommandHandler(Command.CloseTab, CloseCurrentTab);

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                Command switchCmd = Command.SwitchToTerm1 + i;
                int     tabNumber = i;
                Action  handler   = () => SelectTabNumber(tabNumber);
                _keyboardCommandService.RegisterCommandHandler(switchCmd, handler);
            }
            _keyboardCommandService.RegisterCommandHandler(Command.NextTab, SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(Command.PreviousTab, SelectPreviousTab);

            _keyboardCommandService.RegisterCommandHandler(Command.NewWindow, NewWindow);
            _keyboardCommandService.RegisterCommandHandler(Command.ShowSettings, ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(Command.ToggleFullScreen, ToggleFullScreen);
            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddTerminalCommand  = new RelayCommand(() => AddTerminal(null, false));
            ShowAboutCommand    = new RelayCommand(ShowAbout);
            ShowSettingsCommand = new RelayCommand(ShowSettings);

            _applicationView.CloseRequested += OnCloseRequest;
            Terminals.CollectionChanged     += OnTerminalsCollectionChanged;
        }
コード例 #18
0
        public GameHistoryViewModel(
            ISettings settings,
            IDimensionsViewModel dimensions,
            IHandHistoryViewModel handHistoryViewModel,
            IDispatcherTimer scrollToNewestHandTimer,
            ICollectionValidator collectionValidator)
        {
            _settings                = settings;
            CurrentHandHistory       = handHistoryViewModel;
            _scrollToNewestHandTimer = scrollToNewestHandTimer;
            _collectionValidator     = collectionValidator;

            Dimensions = dimensions.InitializeWith(settings.RetrieveRectangle(DimensionsKey, new Rectangle(0, 0, 600, 200)));

            _convertedHands = new List <IConvertedPokerHand>();

            RegisterEvents();
        }
コード例 #19
0
        public IOverlayToTableAttacher InitializeWith(
            IWindowManager tableOverlayWindow,
            IDispatcherTimer watchTableTimer,
            IDispatcherTimer waitThenTryToFindTableAgainTimer,
            IPokerRoomInfo pokerRoomInfo,
            string tableName)
        {
            _pokerRoomInfo      = pokerRoomInfo;
            _tableOverlayWindow = tableOverlayWindow;

            TableName    = tableName;
            _processName = pokerRoomInfo.ProcessName;

            _watchTableTimer       = watchTableTimer;
            _watchTableTimer.Tick += WatchTableTimer_Tick;

            _waitThenTryToFindTableAgainTimer       = waitThenTryToFindTableAgainTimer;
            _waitThenTryToFindTableAgainTimer.Tick += (sender, args) => AttachToTableWith(TableName, _processName);

            return(this);
        }
        //// ===========================================================================================================
        //// Constructors
        //// ===========================================================================================================

        /// <summary>
        /// Creates a new <see cref="LongRunningProcessProgressViewModel"/>.
        /// </summary>
        /// <param name="attachedStartCommand">The command to run when the start button is clicked.</param>
        /// <param name="timer">The timer to use. This is mainly for unit tests.</param>
        /// <param name="getNowFunc">A function that returns the current time. This is mainly for unit tests.</param>
        public LongRunningProcessProgressViewModel(
            IViewModelAsyncCommand attachedStartCommand,
            IDispatcherTimer?timer     = null,
            Func <DateTime>?getNowFunc = null)
        {
            _timer           = timer ?? new WrappedDispatcherTimer();
            _timer.Interval  = TimeSpan.FromMilliseconds(500);
            _timer.IsEnabled = false;
            _timer.Tick     += OnTimerTick;

            _getNowFunc = getNowFunc ?? (() => DateTime.Now);

            // Create the start command and route events from the wrapped command to the exposed command.
            StartCommand = new RelayAsyncCommand(
                CreateStartCommandFunc(attachedStartCommand),
                attachedStartCommand.IsEnabled);

            attachedStartCommand.CanExecuteChanged      +=
                (sender, args) => StartCommand.IsEnabled = attachedStartCommand.IsEnabled;

            // Create the cancel command.
            CancelCommand = new RelayCommand(ExecuteCancelCommand, isEnabled: false);
        }
コード例 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AcxiomTabViewModel"/> class.
        /// </summary>
        public AcxiomTabViewModel(IAcxiomTabView view,
                                  IIntentManager intentManager,
                                  IDispatcherTimer dispatcherTimer,
                                  IDependencyInjectionContainer container,
                                  IAcxiomConstants acxiomConstants)
            : base(isCloseable: true)
        {
            mIntentManager   = intentManager;
            mContainer       = container;
            mDispatcherTimer = dispatcherTimer;
            mAcxiomConstants = acxiomConstants;
            Header           = AcxiomStringResources.TabHeader;        //Tab Header text
            HeaderTooltip    = AcxiomStringResources.TabHeaderTooltip; //Tab header tooltip

            mBaseURL           = mAcxiomConstants.ExternalSubsetGenerationUri.ToString();
            PageLocation       = mBaseURL;
            mJavaScriptHandler = new JavaScriptHandler(this);

            SetAsViewModelForView(view);
            //All is ok, start to render html UI
            mDispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);
            mDispatcherTimer.Tick    += CheckForHtmlReady;
            mDispatcherTimer.Start();
        }
コード例 #22
0
        public MainViewModel(ISettingsService settingsService, ITrayProcessCommunicationService trayProcessCommunicationService, IDialogService dialogService, IKeyboardCommandService keyboardCommandService,
                             IApplicationView applicationView, IDispatcherTimer dispatcherTimer, IClipboardService clipboardService)
        {
            _settingsService = settingsService;
            _settingsService.CurrentThemeChanged        += OnCurrentThemeChanged;
            _settingsService.ApplicationSettingsChanged += OnApplicationSettingsChanged;
            _settingsService.TerminalOptionsChanged     += OnTerminalOptionsChanged;
            _settingsService.ShellProfileAdded          += OnShellProfileAdded;
            _settingsService.ShellProfileDeleted        += OnShellProfileDeleted;
            _settingsService.SshProfileAdded            += OnSshProfileAdded;
            _settingsService.SshProfileDeleted          += OnSshProfileDeleted;

            _trayProcessCommunicationService = trayProcessCommunicationService;
            _dialogService          = dialogService;
            ApplicationView         = applicationView;
            _dispatcherTimer        = dispatcherTimer;
            _clipboardService       = clipboardService;
            _keyboardCommandService = keyboardCommandService;
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewTab), async() => await AddLocalTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshTab), async() => await AddSshTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandTab), async() => await AddCustomCommandTabAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewTab), async() => await AddConfigurableTerminal());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ChangeTabTitle), async() => await SelectedTerminal.EditTitle());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.CloseTab), CloseCurrentTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.SavedSshNewTab), async() => await AddSavedSshTerminalAsync());
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.SavedSshNewWindow), () => NewWindow(NewWindowAction.ShowSshProfileSelection));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewSshWindow), () => NewWindow(NewWindowAction.ShowSshInfoDialog));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewCustomCommandWindow), () => NewWindow(NewWindowAction.ShowCustomCommandDialog));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.DuplicateTab), async() => await AddTerminalAsync(SelectedTerminal.ShellProfile.Clone()));

            // Add all of the commands for switching to a tab of a given ID, if there's one open there
            for (int i = 0; i < 9; i++)
            {
                var switchCmd = Command.SwitchToTerm1 + i;
                int tabNumber = i;
                // ReSharper disable once InconsistentNaming
                void handler() => SelectTabNumber(tabNumber);

                _keyboardCommandService.RegisterCommandHandler(switchCmd.ToString(), handler);
            }

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NextTab), SelectNextTab);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.PreviousTab), SelectPreviousTab);

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.NewWindow), () => NewWindow(NewWindowAction.StartDefaultLocalTerminal));
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ConfigurableNewWindow), () => NewWindow(NewWindowAction.ShowProfileSelection));

            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ShowSettings), ShowSettings);
            _keyboardCommandService.RegisterCommandHandler(nameof(Command.ToggleFullScreen), ToggleFullScreen);

            foreach (ShellProfile profile in _settingsService.GetShellProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddLocalTabOrWindowAsync(profile.Id));
            }

            foreach (SshProfile profile in _settingsService.GetSshProfiles())
            {
                _keyboardCommandService.RegisterCommandHandler(profile.Id.ToString(), async() => await AddSshTabOrWindowAsync(profile.Id));
            }

            var currentTheme = _settingsService.GetCurrentTheme();
            var options      = _settingsService.GetTerminalOptions();

            Background           = currentTheme.Colors.Background;
            BackgroundOpacity    = options.BackgroundOpacity;
            _applicationSettings = _settingsService.GetApplicationSettings();
            TabsPosition         = _applicationSettings.TabsPosition;

            AddLocalShellCommand = new RelayCommand(async() => await AddLocalTabAsync());
            AddSshShellCommand   = new RelayCommand(async() => await AddSshTabAsync());
            AddQuickShellCommand = new RelayCommand(async() => await AddCustomCommandTabAsync());
            ShowAboutCommand     = new RelayCommand(ShowAbout);
            ShowSettingsCommand  = new RelayCommand(ShowSettings);

            ApplicationView.CloseRequested += OnCloseRequest;
            ApplicationView.Closed         += OnClosed;
            Terminals.CollectionChanged    += OnTerminalsCollectionChanged;
        }
コード例 #23
0
 public RepositoryUpdater(IDispatcherTimer dispatcherTimer, IRepositoryList repositoryList)
 {
     _dispatcherTimer = dispatcherTimer;
     _repositoryList  = repositoryList;
 }
コード例 #24
0
 public OverlayViewModel(IDispatcherTimer dispatcherTimer)
 {
     _overlayTimer          = dispatcherTimer;
     _overlayTimer.Interval = new TimeSpan(0, 0, 2);
 }
コード例 #25
0
 public OverlayViewModel(IDispatcherTimer dispatcherTimer)
 {
     _overlayTimer          = dispatcherTimer;
     _overlayTimer.Interval = new TimeSpan(0, 0, 2);
     _overlayTimer.Tick    += OnResizeOverlayTimerFinished;
 }
コード例 #26
0
ファイル: TimerClock.cs プロジェクト: ruban258/SimpleWPFTimer
 public TimerClock(IConfigurationValues config, ILogger logger, IDispatcherTimer timer) : base(logger, config, timer)
 {
     _config         = config;
     _primaryBtnMode = PrimaryButtonMode.Stopped;
 }
コード例 #27
0
        MyMoq TestAgeUpdatingSetInterval(params DateTime[] birthDateTimes)
        {
            if (birthDateTimes == null || birthDateTimes.Length < 2)
            {
                throw new ArgumentException("must include at least 2 birthDateTimes");
            }

            var moqArgs      = new MoqTimerEventArgs(true);
            var participants = GetParticipants(moqArgs, birthDateTimes);

            var expectedTimesFromNow = TimesFromNow(birthDateTimes, moqArgs.StartAt);

            var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict);

            mockTimer.SetupProperty(m => m.Interval);
            mockTimer.Setup(m => m.Start());
            mockTimer.Setup(m => m.Stop());
            TimeSpan expectedInterval = expectedTimesFromNow[0];
            TimeSpan tolerance        = TimeSpan.FromSeconds(defaultSecsTolerance);
            bool     requiresInterval = true;

            mockTimer.SetupSet(m => m.Interval = It.IsAny <TimeSpan>()).Callback <TimeSpan>(i =>
            {
                string usrMsg = string.Format(intervalLogTemplate, i, expectedInterval, tolerance);
                if (requiresInterval && (i < expectedInterval - tolerance || i > expectedInterval + tolerance))
                {
                    throw new ArgumentOutOfRangeException("Interval", usrMsg);
                }
                else
                {
                    Console.WriteLine(usrMsg);
                }
            });
            IDispatcherTimer timer = mockTimer.Object;

            Console.WriteLine("instantiating AgeUpdatingService");
            var ageService = new AgeUpdatingService(participants, timer);

            Console.WriteLine("finished instantiation");
            mockTimer.Verify(m => m.Start(), Times.AtLeastOnce);

            Action <TimeSpan, TimeSpan> validateIntervals = new Action <TimeSpan, TimeSpan>((last, curr) => {
                if (curr.Ticks > 0)
                {
                    moqArgs.StartAt             += last;
                    expectedInterval             = curr;
                    mockTimer.Raise(m => m.Tick += null, moqArgs);
                }
            });

            moqArgs.StartAt += expectedTimesFromNow.First(); //will have been set during instantiation
            expectedTimesFromNow.AggregatePairSelect((prev, cur) => cur - prev)
            .Where(t => t.Ticks != 0)
            .AggregatePairForEach(new TimeSpan(), validateIntervals);
            requiresInterval             = false;
            mockTimer.Raise(m => m.Tick += null, moqArgs);

            Console.WriteLine("Adding new participants");
            moqArgs.StartAt = DateTime.Now;
            foreach (var addedInterval in (new int[] { 10, -10 }).Select(i => TimeSpan.FromSeconds(i)))
            {
                participants.Add(new ParticipantListItemViewModel(
                                     new ParticipantBaseModel
                {
                    Id            = participants.Count + 1,
                    DateTimeBirth = moqArgs.StartAt - TimeSpan.FromDays(1) + addedInterval
                }));
                ageService.AddParticipant(participants[participants.Count - 1]);
            }
            requiresInterval = true;
            moqArgs.StartAt += TimeSpan.FromSeconds(10);

            expectedTimesFromNow = TimesFromNow(from p in participants where p.AgeDays <= 28 select p.DateTimeBirth, moqArgs.StartAt);

            expectedTimesFromNow.AggregatePairSelect(new TimeSpan(), (prev, cur) => cur - prev)
            .Where(t => t.Ticks != 0)
            .AggregatePairForEach(new TimeSpan(), validateIntervals);

            requiresInterval             = false;
            mockTimer.Raise(m => m.Tick += null, moqArgs);

            return(new MyMoq {
                AgeService = ageService, Moq = mockTimer
            });
        }
コード例 #28
0
        public void TestAgeUpdatingStartOnAdd()
        {
            var moqArgs   = new MoqTimerEventArgs(true);
            var mockTimer = new Mock <IDispatcherTimer>(MockBehavior.Strict);

            mockTimer.SetupProperty(m => m.Interval);
            mockTimer.Setup(m => m.Start()).Verifiable();
            mockTimer.Setup(m => m.Stop()).Verifiable();
            IDispatcherTimer timer = mockTimer.Object;

            var ageService = new AgeUpdatingService(new ParticipantListItemViewModel[0], timer);

            mockTimer.Verify(m => m.Start(), Times.Never);

            TimeSpan toDob = TimeSpan.FromMinutes(-10);
            var      p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 1,
                DateTimeBirth = moqArgs.StartAt + toDob
            });

            TimeSpan expectedInterval = TimeSpan.FromDays(1) + toDob;
            TimeSpan tolerance        = TimeSpan.FromSeconds(defaultSecsTolerance);

            mockTimer.SetupSet(m => m.Interval = It.IsAny <TimeSpan>()).Callback <TimeSpan>(i =>
            {
                string usrMsg = string.Format(intervalLogTemplate, i, expectedInterval, tolerance);
                if (i < expectedInterval - tolerance || i > expectedInterval + tolerance)
                {
                    throw new ArgumentOutOfRangeException("Interval", usrMsg);
                }
                else
                {
                    Console.WriteLine(usrMsg);
                }
            });
            ageService.AddParticipant(p);
            mockTimer.Verify(m => m.Start(), Times.Once);

            TimeSpan laterDayversary = TimeSpan.FromMinutes(-5);

            p = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + laterDayversary
            });
            ageService.AddParticipant(p);

            toDob = TimeSpan.FromMinutes(-30);
            p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + toDob
            });
            expectedInterval = TimeSpan.FromDays(1) + toDob;

            ageService.AddParticipant(p);

            toDob = TimeSpan.FromDays(-1).Add(TimeSpan.FromMinutes(5));
            p     = new ParticipantListItemViewModel(
                new ParticipantBaseModel
            {
                Id            = 2,
                DateTimeBirth = moqArgs.StartAt + toDob
            });
            expectedInterval = TimeSpan.FromDays(1) + toDob;

            ageService.AddParticipant(p);
        }
コード例 #29
0
 protected override void OnDisappearing()
 {
     _timer.Stop();
     _timer = null;
 }
コード例 #30
0
ファイル: BotMain.cs プロジェクト: ssznakabulgarian/BitMods
 private void MProtocolTimeout_Tick(IDispatcherTimer timer)
 {
     mState = ProtocolState.Finished;
     ProtocolError("Communication timeout.");
 }