private async void StopStrategy(object param)
        {
            await SetCommandVisibility(StrategyRunnerCommandVisibility.Connecting).ConfigureAwait(false);

            var strategyParameters = new CoreStrategy.StrategyParameters {
                StrategyName = Strategy.Name
            };
            var strategyParametersJson = JsonConvert.SerializeObject(strategyParameters);

            await StopAsync(strategyParametersJson).ConfigureAwait(false);

            await SetCommandVisibility(StrategyRunnerCommandVisibility.ServerAvailable).ConfigureAwait(false);
        }
Esempio n. 2
0
        private async Task <bool> IsStrategyRunningAsync()
        {
            try
            {
                if (!IsValidSelectServer())
                {
                    return(false);
                }

                var strategyParameters = new CoreStrategy.StrategyParameters {
                    StrategyName = Strategy.Name
                };
                var strategyParametersJson = JsonConvert.SerializeObject(strategyParameters);

                var response = await CoreStrategy.StrategyRunnerClient.PostAsync(new Uri($"{SelectedServer.Uri}isstrategyrunning"), strategyParametersJson);

                var content = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(content.Equals("YES"));
                }
                else
                {
                    ViewModelContext.UiDispatcher.Invoke(() =>
                    {
                        NotificationsAdd(
                            new Message
                        {
                            MessageType = response.StatusCode == System.Net.HttpStatusCode.OK ? MessageType.Info : MessageType.Error,
                            Text        = response.StatusCode.ToString(),
                            TextVerbose = JsonConvert.SerializeObject(content, Formatting.Indented)
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"IsStrategyRunningAsync {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High);

                NotificationsAdd(new Message {
                    MessageType = MessageType.Error, Text = $"Unable to connect to the remote server.", TextVerbose = ex.ToString()
                });
            }

            return(false);
        }
        private async Task <bool> IsStrategyRunningAsync()
        {
            HttpResponseMessage response = null;

            try
            {
                var strategyParameters = new CoreStrategy.StrategyParameters {
                    StrategyName = Strategy.Name
                };
                var strategyParametersJson = JsonConvert.SerializeObject(strategyParameters);

                response = await CoreStrategy.StrategyRunnerClient.PostAsync(httpClientManager.HttpClientInstance, new Uri($"{SelectedServer.Uri}isstrategyrunning"), strategyParametersJson, cancellationTokenSource.Token).ConfigureAwait(false);

                var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(content == "YES");
                }
                else
                {
                    ViewModelContext.UiDispatcher.Invoke(() =>
                    {
                        NotificationsAdd(
                            new Message
                        {
                            MessageType = response.StatusCode == System.Net.HttpStatusCode.OK ? MessageType.Info : MessageType.Error,
                            Text        = response.StatusCode.ToString(),
                            TextVerbose = JsonConvert.SerializeObject(content, Formatting.Indented)
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"IsStrategyRunningAsync {ex}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High);
            }
            finally
            {
                response.Content.Dispose();
                response.Dispose();
            }

            return(false);
        }