当前位置: 首页>>代码示例>>C#>>正文


C# RestClient.ExecutTaskAsync方法代码示例

本文整理汇总了C#中RestSharp.RestClient.ExecutTaskAsync方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.ExecutTaskAsync方法的具体用法?C# RestClient.ExecutTaskAsync怎么用?C# RestClient.ExecutTaskAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestSharp.RestClient的用法示例。


在下文中一共展示了RestClient.ExecutTaskAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetConnections

        public async Task<SearchResult> GetConnections(string from, string to, DateTime time, bool isArrival = false)
        {
            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return null;

            var client = new RestClient("http://transport.opendata.ch/v1/");
            var request =
                new RestRequest("connections")
                    .AddParameter("from", from)
                    .AddParameter("to", to)
                    .AddParameter("date", time.ToString("yyyy-MM-dd"))
                    .AddParameter("time", time.ToString("HH:mm"))
                    .AddParameter("isArrivalTime", isArrival ? 1 : 0);

            try
            {
                return 
                    await
                    client
                        .ExecutTaskAsync(request)
                        .ContinueWith(task => JObject.Parse(task.Result.Content).ToObject<SearchResult>());
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:27,代码来源:CacheTimeTable.cs

示例2: GetLocations

        public async Task<IEnumerable<Station>> GetLocations(string locationName)
        {
            // First search in cache
            var cached = GetCachedLocation(locationName);
            if (cached != null) return cached as IEnumerable<Station>;

            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return Enumerable.Empty<Station>();

            // If nothing found in cache query sbb.ch
            var client = new RestClient("http://transport.opendata.ch/v1/");
            var request =
                new RestRequest("locations")
                    .WithRootElement("stations")
                    .WithFormat(DataFormat.Json)
                    .AddParameter("query", locationName);

            try
            {
                var result =
                    await
                    client
                        .ExecutTaskAsync<List<Station>>(request)
                        .ContinueWith(task => task.Result.Data);

                UpdateCachedLocation(locationName, result);

                return result;
            }
            catch (Exception)
            {
                return Enumerable.Empty<Station>();
            }
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:34,代码来源:CacheTimeTable.cs

示例3: GetLocations

        public Task<IEnumerable<Station>> GetLocations(string locationName)
        {
            var client = new RestClient("http://transport.opendata.ch/v1/");
            var request =
                new RestRequest("locations")
                    .WithRootElement("stations")
                    .WithFormat(DataFormat.Json)
                    .AddParameter("query", locationName);

            return
                client
                    .ExecutTaskAsync<List<Station>>(request)
                    .ContinueWith(task => task.Result.Data as IEnumerable<Station>);
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:14,代码来源:TimeTable.cs

示例4: GetConnections

        public Task<SearchResult> GetConnections(string from, string to, DateTime time, bool isArrival = false)
        {
            var client = new RestClient("http://transport.opendata.ch/v1/");
            var request =
                new RestRequest("connections")
                    .AddParameter("from", from)
                    .AddParameter("to", to)
                    .AddParameter("date", time.ToString("yyyy-MM-dd"))
                    .AddParameter("time", time.ToString("HH:mm"))
                    .AddParameter("isArrivalTime", isArrival ? 1 : 0);

            return
                client
                    .ExecutTaskAsync(request)
                    .ContinueWith(task => JObject.Parse(task.Result.Content).ToObject<SearchResult>());
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:16,代码来源:TimeTable.cs

示例5: LoginAsync

        public async Task<Token> LoginAsync(Token token)
        {
            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return null;

            var client = new RestClient("http://trainshare.herokuapp.com/v1/");
            var request =
                new RestRequest("login", Method.POST)
                    .AddJson(
                        new JObject(
                            new JProperty("network", token.Network),
                            new JProperty("access_token", token.AccessToken),
                            new JProperty("access_token_secret", token.AccessTokenSecret)));

            request.RequestFormat = DataFormat.Json;

            try
            {
                var json =
                    await
                    client
                        .ExecutTaskAsync(request)
                        .ContinueWith(task => JObject.Parse(task.Result.Content));

                InsertOrUpdateToken(
                    new Token
                    {
                        Network = "trainshare",
                        AccessToken = json["trainshare_id"].Value<string>(),
                        AccessTokenSecret = json["trainshare_token"].Value<string>()
                    });

                Events.Publish(Token);

                return Token;
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return null;
            }
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:42,代码来源:TrainshareClient.cs

示例6: GetFriends

        public async Task<List<TrainshareFriend>> GetFriends()
        {
            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return new List<TrainshareFriend>();

            var client = new RestClient("http://trainshare.herokuapp.com/v1/");
            var request =
                new RestRequest("read", Method.POST)
                    .AddParameter("trainshare_id", Token.AccessToken)
                    .AddParameter("trainshare_token", Token.AccessTokenSecret);

            try
            {
                return
                    await
                    client
                        .ExecutTaskAsync<List<TrainshareFriend>>(request)
                        .ContinueWith(task => task.Result.Data);
            }
            catch(Exception e)
            {
                _logger.Error(e);

                return new List<TrainshareFriend>();
            }
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:26,代码来源:TrainshareClient.cs

示例7: Checkin

        /*
         *     departure_station: "Bern",
         *     departure_time: "16:34",
         *     arrival_station: "Basel SBB",
         *     arrival_time: "17:29",
         *     train_id: "IC 1080"
         */
        public async Task Checkin(Checkin checkin)
        {
            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return;

            var client = new RestClient("http://trainshare.herokuapp.com/v1/");
            var request =
                new RestRequest("checkin", Method.POST)
                    .AddJson(
                        new JObject(
                            new JProperty("trainshare_id", Token.AccessToken),
                            new JProperty("trainshare_token", Token.AccessTokenSecret),
                            new JProperty("data",
                                          new JArray(
                                              checkin
                                                  .Sections
                                                  .Select(
                                                      section =>
                                                      new JObject(
                                                          new JProperty("departure_station", section.DepartureStation),
                                                          new JProperty("departure_time",
                                                                        section.DepartureTime.ToString("HH:mm")),
                                                          new JProperty("arrival_station", section.ArrivalStation),
                                                          new JProperty("arrival_time",
                                                                        section.ArrivalTime.ToString("HH:mm")),
                                                          new JProperty("train_id", section.TrainId),
                                                          new JProperty("position", checkin.Position)))))));

            try
            {
                //Skipping the result on purpouse
                await client.ExecutTaskAsync(request);

                AddCheckin(checkin);
                CurrentCheckin = checkin;

                Events.Publish(CurrentCheckin);
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:50,代码来源:TrainshareClient.cs

示例8: GetUserInfo

        private static Task<JObject> GetUserInfo(string accessToken)
        {
            var client = new RestClient("https://graph.facebook.com/me");
            var request =
                new RestRequest()
                    .AddParameter("access_token", accessToken);

            return
                client
                    .ExecutTaskAsync(request)
                    .ContinueWith(task => JObject.Parse(task.Result.Content));
        }
开发者ID:trainshare,项目名称:TrainShareApp,代码行数:12,代码来源:FacebookClient.cs


注:本文中的RestSharp.RestClient.ExecutTaskAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。