Exemplo n.º 1
0
        public async Task <Boolean> AddStockDiscussion(Int32 stockId, DiscussionItem discussionItem)
        {
            var uri = _dns.Resolve(_serviceName).Result;

            string baseUrl = string.Format(_stockDiscussion, uri.OriginalString);

            var loggerFactory = new LoggerFactory();
            var logger        = loggerFactory.CreateLogger <StockDiscussionPublisher>();


            var connection = await ConnectAsync(baseUrl);

            try
            {
                var cts = new CancellationTokenSource();

                await connection.InvokeAsync <DiscussionItem>("addStockDiscussion", stockId, discussionItem, cts.Token);

                return(true);
            }
            catch (AggregateException aex) when(aex.InnerExceptions.All(e => e is OperationCanceledException))
            {
                return(false);
            }
            catch (OperationCanceledException)
            {
                return(false);
            }
            finally
            {
                await connection.DisposeAsync();
            }
        }
Exemplo n.º 2
0
        public Task <IEnumerable <CommonStock> > GetList(int startIndex, int pageSize)
        {
            var client = new RestClient(_dns.Resolve(_serviceName).Result);

            string template = string.Format(_getCommonStocks, startIndex, pageSize);

            var request = new RestRequest(template, Method.GET);

            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();

            var response = client.Execute(request);
            var content  = response.Content; // raw content as string

            var stocks = JsonConvert.DeserializeObject <IEnumerable <CommonStock> >(content);

            return(Task.FromResult <IEnumerable <CommonStock> >(stocks));
        }
Exemplo n.º 3
0
        public Task <Member> Active(string token)
        {
            var client = new RestClient(_dns.Resolve(_serviceName).Result);


            var request = new RestRequest(_getActiveMember, Method.GET);

            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();

            var response = client.Execute(request);
            var content  = response.Content; // raw content as string

            var member = JsonConvert.DeserializeObject <Member>(content);

            return(Task.FromResult <Member>(member));
        }
Exemplo n.º 4
0
        public Task <IEnumerable <Eod> > GetList(string symbol, DateTime startDate, DateTime endDate)
        {
            var client = new RestClient(_dns.Resolve(_serviceName).Result);

            string template = string.Format(_getEods, symbol, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));

            var request = new RestRequest(template, Method.GET);

            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();

            var response = client.Execute(request);
            var content  = response.Content; // raw content as string

            var eods = JsonConvert.DeserializeObject <IEnumerable <Eod> >(content);

            return(Task.FromResult <IEnumerable <Eod> >(eods));
        }
Exemplo n.º 5
0
        public Task <String> Authen(string username, string password)
        {
            var client = new RestClient(_dns.Resolve(_serviceName).Result);

            var request = new RestRequest(_postIdentityToken, Method.POST);

            request.AddHeader("Accept", "application/json");
            request.Parameters.Clear();

            var requestModel = new Login()
            {
                Username = username, Password = password
            };

            request.AddParameter("application/json", JsonConvert.SerializeObject(requestModel), ParameterType.RequestBody);

            var response = client.Execute(request);
            var content  = response.Content; // raw content as string

            return(Task.FromResult(content));
        }