Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
		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());
		}
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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());
        }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
        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);
		}