コード例 #1
0
        public async Task <bool> RefreshFeedsAsync()
        {
            try
            {
                string api_url = App.configVM.ConfigurationCollection.FirstOrDefault(c => c.Name == "Api Url").Value;
                string api_key = App.configVM.ConfigurationCollection.FirstOrDefault(c => c.Name == "Api Key").Value;

                ApiJsonClient   client = new ApiJsonClient();
                List <FeedItem> resp   = await client.GetFeedsListAsync(api_url, api_key);

                var confFeeds = from o in App.configVM.ConfigurationCollection where o.Type == Model.ConfigType.FEED select o;
                foreach (var confFeed in confFeeds)
                {
                    confFeed.Type = Model.ConfigType.FEED_TO_DELETE;
                }

                foreach (var feed in resp)
                {
                    Model.Configuration existingFeedConf = App.configVM.ConfigurationCollection.FirstOrDefault((o) => o.Type == Model.ConfigType.FEED_TO_DELETE && o.Id == feed.Id);
                    if (existingFeedConf != null)
                    {
                        existingFeedConf.Name          = feed.Name;
                        existingFeedConf.Type          = Model.ConfigType.FEED;
                        existingFeedConf.LastTimeStamp = Util.FromApiTime(feed.Time);
                        existingFeedConf.Value         = feed.Value;
                    }
                    else
                    {
                        App.configVM.ConfigurationCollection.Add(
                            new Model.Configuration
                        {
                            Name          = feed.Name,
                            Id            = feed.Id,
                            Type          = Model.ConfigType.FEED,
                            LastTimeStamp = Util.FromApiTime(feed.Time),
                            Value         = feed.Value
                        }
                            );
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #2
0
        public async Task<bool> RefreshFeedsAsync()
        {
            try
            {
                string api_url = App.configVM.ConfigurationCollection.FirstOrDefault(c => c.Name == "Api Url").Value;
                string api_key = App.configVM.ConfigurationCollection.FirstOrDefault(c => c.Name == "Api Key").Value;

                ApiJsonClient client = new ApiJsonClient();
                List<FeedItem> resp = await client.GetFeedsListAsync(api_url, api_key);

                var confFeeds = from o in App.configVM.ConfigurationCollection where o.Type == Model.ConfigType.FEED select o;
                foreach (var confFeed in confFeeds)
                {
                    confFeed.Type = Model.ConfigType.FEED_TO_DELETE;
                }

                foreach (var feed in resp)
                {
                    Model.Configuration existingFeedConf = App.configVM.ConfigurationCollection.FirstOrDefault((o) => o.Type == Model.ConfigType.FEED_TO_DELETE && o.Id == feed.Id);
                    if (existingFeedConf != null)
                    {
                        existingFeedConf.Name = feed.Name;
                        existingFeedConf.Type = Model.ConfigType.FEED;
                        existingFeedConf.LastTimeStamp = Util.FromApiTime(feed.Time);
                        existingFeedConf.Value = feed.Value;
                    }
                    else
                    {
                        App.configVM.ConfigurationCollection.Add(
                            new Model.Configuration
                            {
                                Name = feed.Name,
                                Id = feed.Id,
                                Type = Model.ConfigType.FEED,
                                LastTimeStamp = Util.FromApiTime(feed.Time),
                                Value = feed.Value
                            }
                        );
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }