public async Task ResetTimerTest() { // Arrange int callbackCalledCount = 0; Task Callback() { Interlocked.Increment(ref callbackCalledCount); return(Task.CompletedTask); } TimeSpan period = TimeSpan.FromSeconds(3); var resettableTimer = new ResettableTimer(Callback, period, null); // Act resettableTimer.Start(); for (int i = 0; i < 5; i++) { await Task.Delay(TimeSpan.FromSeconds(2)); resettableTimer.Reset(); } await Task.Delay(TimeSpan.FromSeconds(4)); // Assert Assert.Equal(1, callbackCalledCount); }
public ModuleClient(ISdkModuleClient inner, TimeSpan idleTimeout, bool closeOnIdleTimeout, UpstreamProtocol protocol) { this.inner = Preconditions.CheckNotNull(inner, nameof(inner)); this.UpstreamProtocol = protocol; this.inactivityTimer = new ResettableTimer(this.CloseOnInactivity, idleTimeout, Events.Log, closeOnIdleTimeout); this.inactivityTimer.Start(); }
public ChartPane() { InitializeComponent(); _drawTimer = new ResettableTimer(TimeSpan.FromSeconds(2)); _drawTimer.Elapsed += DrawTimerOnElapsed; ChartPanel.MinimumRange = 200; ChartPanel.IsInteracted = true; ChartPanel.IndicatorTypes.AddRange(AppConfig.Instance.Indicators); ChartPanel.SubscribeCandleElement += OnChartPanelSubscribeCandleElement; ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement; }
public ChartPane() { InitializeComponent(); _drawTimer = new ResettableTimer(TimeSpan.FromSeconds(2), "Chart"); _drawTimer.Elapsed += DrawTimerOnElapsed; ChartPanel.MinimumRange = 200; ChartPanel.IsInteracted = true; ChartPanel.FillIndicators(); ChartPanel.SubscribeCandleElement += OnChartPanelSubscribeCandleElement; ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement; ChartPanel.UnSubscribeElement += ChartPanelOnUnSubscribeElement; }
public StrategyInfoCodeContent() { InitializeComponent(); _timer = new ResettableTimer(TimeSpan.FromSeconds(1), "Compilation"); _timer.Elapsed += canProcess => GuiDispatcher.GlobalDispatcher.AddAction(CompileCode); var persSvc = ConfigManager.GetService<IPersistableService>(); CodePanel.References.AddRange(persSvc.GetReferences()); CodePanel.ReferencesUpdated += () => persSvc.SetReferences(CodePanel.References); CodePanel.SavingCode += SaveCode; CodePanel.CompilingCode += CompileCode; CodePanel.CodeChanged += _timer.Activate; var cmdSvc = ConfigManager.GetService<IStudioCommandService>(); cmdSvc.Register<CompileStrategyInfoResultCommand>(this, true, cmd => CodePanel.ShowCompilationResult(cmd.Result, GetStrategiesState())); cmdSvc.Register<EditReferencesCommand>(this, true, cmd => CodePanel.EditReferences()); }
public CompositeSecurityPanel() { InitializeComponent(); InputBorder.SetBindings(IsEnabledProperty, this, "IsStarted", BindingMode.OneWay, new InverseBooleanConverter()); MarketDataSettings = ConfigManager.GetService <MarketDataSettingsCache>().Settings.First(s => s.Id != Guid.Empty); DateFrom = DateTime.Today.AddDays(-180); DateTo = DateTime.Today; _timer = new ResettableTimer(TimeSpan.FromSeconds(30)); _timer.Elapsed += () => { GuiDispatcher.GlobalDispatcher.AddAction(() => IsStarted = false); _bufferedChart.IsAutoRange = false; }; _drawTimer = new ResettableTimer(TimeSpan.FromSeconds(2)); _drawTimer.Elapsed += DrawTimerOnElapsed; ChartPanel.SubscribeCandleElement += OnChartPanelSubscribeCandleElement; ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement; ChartPanel.UnSubscribeElement += OnChartPanelUnSubscribeElement; var indicatorTypes = ConfigManager .GetService <IAlgoService>() .IndicatorTypes; ChartPanel.IsInteracted = true; ChartPanel.MinimumRange = 200; ChartPanel.IndicatorTypes.AddRange(indicatorTypes); SecurityPicker.SetColumnVisibility("Id", Visibility.Visible); SecurityPicker.SetColumnVisibility("Code", Visibility.Collapsed); _candleManager.Container.CandlesKeepTime = TimeSpan.FromDays(5000); _candleManager.Processing += ProcessCandle; WhenLoaded(OnLoaded); _bufferedChart = new BufferedChart(ChartPanel); }
public StrategyInfoCodeContent() { InitializeComponent(); _timer = new ResettableTimer(TimeSpan.FromSeconds(1), "Compilation"); _timer.Elapsed += canProcess => GuiDispatcher.GlobalDispatcher.AddAction(CompileCode); var persSvc = ConfigManager.GetService <IPersistableService>(); CodePanel.References.AddRange(persSvc.GetReferences()); CodePanel.ReferencesUpdated += () => persSvc.SetReferences(CodePanel.References); CodePanel.SavingCode += SaveCode; CodePanel.CompilingCode += CompileCode; CodePanel.CodeChanged += _timer.Activate; var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <CompileStrategyInfoResultCommand>(this, true, cmd => CodePanel.ShowCompilationResult(cmd.Result, GetStrategiesState())); cmdSvc.Register <EditReferencesCommand>(this, true, cmd => CodePanel.EditReferences()); }
public CloudProxy(IClient client, IMessageConverterProvider messageConverterProvider, string clientId, Action <string, CloudConnectionStatus> connectionStatusChangedHandler, ICloudListener cloudListener, TimeSpan idleTimeout, bool closeOnIdleTimeout) { this.client = Preconditions.CheckNotNull(client, nameof(client)); this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider)); this.clientId = Preconditions.CheckNonWhiteSpace(clientId, nameof(clientId)); this.cloudReceiver = new CloudReceiver(this, Preconditions.CheckNotNull(cloudListener, nameof(cloudListener))); this.timer = new ResettableTimer(this.HandleIdleTimeout, idleTimeout, Events.Log, true); this.timer.Start(); this.closeOnIdleTimeout = closeOnIdleTimeout; if (connectionStatusChangedHandler != null) { this.connectionStatusChangedHandler = connectionStatusChangedHandler; } Events.Initialized(this); }
public async Task CreateAndStartTimerTest() { // Arrange int callbackCalledCount = 0; Task Callback() { Interlocked.Increment(ref callbackCalledCount); return(Task.CompletedTask); } TimeSpan period = TimeSpan.FromSeconds(15); var resettableTimer = new ResettableTimer(Callback, period, null); // Act resettableTimer.Start(); await Task.Delay(TimeSpan.FromSeconds(35)); // Assert Assert.Equal(2, callbackCalledCount); }
public CompositeSecurityPanel() { InitializeComponent(); InputBorder.SetBindings(IsEnabledProperty, this, "IsStarted", BindingMode.OneWay, new InverseBooleanConverter()); MarketDataSettings = ConfigManager.GetService<MarketDataSettingsCache>().Settings.First(s => s.Id != Guid.Empty); DateFrom = DateTime.Today.AddDays(-180); DateTo = DateTime.Today; _timer = new ResettableTimer(TimeSpan.FromSeconds(30), "Composite"); _timer.Elapsed += canProcess => { GuiDispatcher.GlobalDispatcher.AddAction(() => IsStarted = false); _bufferedChart.IsAutoRange = false; }; _drawTimer = new ResettableTimer(TimeSpan.FromSeconds(2), "Composite 2"); _drawTimer.Elapsed += DrawTimerOnElapsed; ChartPanel.SubscribeCandleElement += OnChartPanelSubscribeCandleElement; ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement; ChartPanel.UnSubscribeElement += OnChartPanelUnSubscribeElement; ChartPanel.IsInteracted = true; ChartPanel.MinimumRange = 200; ChartPanel.FillIndicators(); SecurityPicker.SetColumnVisibility("Id", Visibility.Visible); SecurityPicker.SetColumnVisibility("Code", Visibility.Collapsed); _candleManager.Container.CandlesKeepTime = TimeSpan.FromDays(5000); _candleManager.Processing += ProcessCandle; WhenLoaded(OnLoaded); _bufferedChart = new BufferedChart(ChartPanel); }