コード例 #1
0
ファイル: NewsViewModel.cs プロジェクト: randyrod/OneBreak
        public async Task LoadNews()
        {
            Loading = true;
            var result = await NewsRequestHelper.GetGpuNews();

            //Note: this solution should be temporary, do not leave it here plz!!! :)
            var gpuProviderText = await App.GetStringFromResources(GpuProviderKey, false);

            if (result == null || result.Count <= 0)
            {
                Loading = false;
                return;
            }

            if (News.Count > 0 && News[0].Title == result[0].Title)
            {
                Loading = false;
                return;
            }

            News.Clear();
            foreach (var item in result)
            {
                //Lazyness taking over
                if (item.Title.Contains("Video") || item.Title.Contains("video"))
                {
                    continue;
                }
                item.Provider = gpuProviderText;
                News.Add(item);
            }

            Loading = false;
        }
コード例 #2
0
                public void UpdateNews(List <RockNews> sourceNews)
                {
                    // free existing news
                    FreeImageResources( );

                    News.Clear( );

                    // copy the new news.
                    int i;

                    for (i = 0; i < sourceNews.Count; i++)
                    {
                        NewsEntry newsEntry = new NewsEntry();
                        News.Add(newsEntry);

                        newsEntry.News = sourceNews[i];
                        // see if we can load the file
                        bool fileFound = TryLoadCachedImageAsync(newsEntry, newsEntry.News.ImageName);
                        if (fileFound == false)
                        {
                            // if not, download it
                            string widthParam = string.Format("width={0}", NavbarFragment.GetCurrentContainerDisplayWidth( ));
                            string requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(newsEntry.News.ImageURL, widthParam);

                            FileCache.Instance.DownloadFileToCache(requestUrl, newsEntry.News.ImageName, null,
                                                                   delegate
                            {
                                // and THEN load it
                                TryLoadCachedImageAsync(newsEntry, newsEntry.News.ImageName);
                            });
                        }
                    }
                }
コード例 #3
0
ファイル: NewsViewModel.cs プロジェクト: yyg1987/HT.APPStore
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.NewsService.GetNewsAsync(position, pageIndex);

            if (result.Success)
            {
                var news = JsonConvert.DeserializeObject <List <News> >(result.Message.ToString());
                if (news.Count > 0)
                {
                    if (pageIndex == 1 && News.Count > 0)
                    {
                        News.Clear();
                    }
                    News.AddRange(news);
                    pageIndex++;
                    LoadStatus  = LoadMoreStatus.StausDefault;
                    CanLoadMore = true;
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SendLog("NewsViewModel.GetNewsAsync:" + result.Message);
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
コード例 #4
0
ファイル: NewsViewModel.cs プロジェクト: 132329/Punchando
        private async void LoadNews()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            List <Models.News> newsItemList = new List <Models.News>();

            try
            {
                newsItemList = await DataHelper.Instance.Get();
            }
            catch (Exception ex)
            {
                if (await MessageHelper.YesNoMessage(ex.Message))
                {
                    var appManage = DependencyService.Get <Dependecies.IAppManage>();
                    if (appManage != null)
                    {
                        appManage.Close();
                    }
                }
            }
            News.Clear();
            foreach (Models.News newsItem in newsItemList)
            {
                News.Add(newsItem);
            }

            IsBusy = false;
        }
コード例 #5
0
        public void ExecuteLoadNewsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            if (News != null)
            {
                News.Clear();
            }

            XDocument xDoc = XDocument.Load("https://www.aims.org.au/news/rss");

            db.DeleteAllNews();
            foreach (var item in xDoc.Descendants("item"))
            {
                var date = DateTime.ParseExact((string)item.Element("pubDate"),
                                               "ddd',' dd MMM yyyy HH:mm:ss K",
                                               CultureInfo.InvariantCulture);
                db.InsertNews(new NewsModel()
                {
                    Title         = (string)item.Element("title"),
                    Link          = (string)item.Element("link"),
                    Description   = (string)item.Element("description"),
                    DatePublished = date.ToString("ddd dd MMM yyyy")
                });
            }

            News   = new ObservableCollection <NewsModel>(db.GetAllNews());
            IsBusy = false;
        }
コード例 #6
0
 private void AddingData(IEnumerable <NewsItem> collection)
 {
     News.Clear();
     foreach (var item in collection)
     {
         News.Add(item);
     }
 }
コード例 #7
0
        public CollectedTopicsFragment()
        {
            InitializeComponent();
            LabelPanel.ItemsSource = _tabs;
            async Task <IEnumerable <TopicModel> > loadData()
            {
                var model = LabelPanel.SelectedItem as CollectedListModel;
                var html  = await ApiClient.GetTopicsWithTab(model.Name);

                var dom = new HtmlParser().ParseDocument(html);

                return(DomParse.ParseTopics(dom));
            }

            var selectionChanged = Observable
                                   .FromEventPattern <SelectionChangedEventArgs>(LabelPanel, nameof(LabelPanel.SelectionChanged))
                                   .SelectMany(x => loadData())
                                   .Retry(10)
                                   .ObserveOnCoreDispatcher()
                                   .Subscribe(x =>
            {
                News.Clear();
                foreach (var item in x)
                {
                    News.Add(item);
                }
            });
            var click = Observable.FromEventPattern <ItemClickEventArgs>(NewsList, nameof(NewsList.ItemClick))
                        .Select(x => x.EventArgs.ClickedItem as TopicModel)
                        .ObserveOnCoreDispatcher()
                        .Subscribe(x => PageStack.Next("Left", "Right", typeof(RepliesAndTopicView), x.Id));
            var refresh = Observable.FromEventPattern <TappedRoutedEventArgs>(Refresh, nameof(Refresh.Tapped))
                          .SelectMany(x => loadData())
                          .Retry(10)
                          .ObserveOnCoreDispatcher()
                          .Subscribe(x =>
            {
                News.Clear();
                foreach (var item in x)
                {
                    News.Add(item);
                }
            });

            LabelPanel.SelectedIndex = 0;

            this.Unloaded += (s, e) =>
            {
                selectionChanged.Dispose();
                click.Dispose();
                refresh.Dispose();
            };
        }
コード例 #8
0
        private async void GetNews()
        {
            var newsItems = await _newsProvider.GetNewsAsync();

            if (newsItems == null)
            {
                return;
            }

            News.Clear();
            newsItems.ToList().ForEach(n => News.Add(new NewsDisplayModel(n)));
            //News.First().ReadMoreExpanded = true;
        }
コード例 #9
0
        /// <summary>
        /// Load the data to display in the "What's new" part.
        /// </summary>
        private void LoadNews()
        {
            var resource = Application.GetResourceStream(new Uri($"/ClipboardZanager;component/Assets/news/news.{CurrentLanguage}.json", UriKind.RelativeOrAbsolute));

            News.Clear();
            if (resource != null)
            {
                foreach (var softwareNewItem in JsonConvert.DeserializeObject <ObservableCollection <SoftwareNewItem> >(new StreamReader(resource.Stream).ReadToEnd()))
                {
                    News.Add(softwareNewItem);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Method which loads the News Feed and adds the items to the "News" Collection.
        /// </summary>
        public async void LoadNews()
        {
            RSSReader rssReader = new RSSReader();

            // Clear the Collection. Otherwise the Collection dupicates on every loading.
            News.Clear();

            var news = await rssReader.LoadNewsAsync(new Uri("http://blog.pdapda.de/feed/"));

            foreach (var syndicationItem in news)
            {
                News.Add(syndicationItem);
            }
        }
コード例 #11
0
        public void UpdateNews(List <RockNews> sourceNews)
        {
            // clear the existing news
            News.Clear( );

            // copy the source into our news objects
            foreach (RockNews rockEntry in sourceNews)
            {
                NewsEntry newsEntry = new NewsEntry();
                News.Add(newsEntry);

                newsEntry.News = rockEntry;
            }
        }
コード例 #12
0
        //private bool HasNews()
        //{
        //    //await Task.Delay(5000);
        //    SetProperty(ref _hasNews, News.Count > 0);
        //    return News.Count > 0;
        //}

        public override async Task LoadAsync()
        {
            var news = await _tchospiraService.GetNewsAsync();

            System.Diagnostics.Debug.WriteLine("FOUND {0} TAGS", news.Count);
            News.Clear();
            foreach (var n in news)
            {
                News.Add(n);
            }
            HasNews = News.Count > 0;

            OnPropertyChanged(nameof(News));
            OnPropertyChanged(nameof(HasNews));
        }
コード例 #13
0
ファイル: NewsViewModel.cs プロジェクト: yyg1987/HT.FirstApp
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.NewsService.GetNewsAsync(position, pageIndex, pageSize);

            if (result.Success)
            {
                var news = JsonConvert.DeserializeObject <List <News> >(result.Message.ToString());
                if (news.Count > 0)
                {
                    if (pageIndex == 1 && News.Count > 0)
                    {
                        News.Clear();
                    }
                    News.AddRange(news);
                    switch (position)
                    {
                    case 1:
                        news.ForEach(s => s.IsRecommend = true);
                        break;

                    case 2:
                        news.ForEach(s => s.IsHot = true);
                        break;
                    }
                    await SqliteUtil.Current.UpdateNews(news);

                    pageIndex++;
                    LoadStatus  = LoadMoreStatus.StausDefault;
                    CanLoadMore = true;
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Crashes.TrackError(new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
コード例 #14
0
        void ExecuteLoadItemsCommand(int id)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                News.Clear();
                var items = NewsFromParent;
                if (items != null && items.Count() > 0)
                {
                    var firstItem = items.Where(n => n.Id == id).FirstOrDefault();
                    MainTitle   = firstItem.Title;
                    Title       = firstItem.Title;
                    Content     = firstItem.Content;
                    Date        = firstItem.DatePosted.ToLongDateString();
                    Image       = firstItem.Image;
                    RelatedNews = "Other news";

                    foreach (var item in items.Where(n => n.Id != id))
                    {
                        item.Image = item.Image;
                        item.Date  = firstItem.DatePosted.ToLongDateString();
                        News.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #15
0
ファイル: About.cs プロジェクト: wuchangqi/ifixit-microsoft
        public async Task LoadRss()
        {
            if (_settingsService.IsConnectedToInternet())
            {
                var nBroker = new NewsBroker();

                var xml = await nBroker.GetNews();

                var morenodes = (from n in xml.Descendants("rss") select n).Descendants("item").Select(x => new
                                                                                                       Models.UI.RssItem
                {
                    Title = (string)x.Element("title")
                    ,
                    Summary = (string)x.Element("description")

                    ,
                    ImageUrl = Regex.Match(((string)(x.Element("htmlcontent"))), "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value

                    ,
                    Url = (string)x.Element("guid")
                    ,
                    PubDate = (DateTime)x.Element("pubDate")
                    ,
                    Author = string.Format(International.Translation.RssDateAndAuthor, (string)x.Element("creator"))
                }).ToList();


                News.Clear();
                foreach (var item in morenodes)
                {
                    News.Add(item);
                }
            }
            else
            {
                await _uxService.ShowAlert(International.Translation.NoConnection);
            }
        }
コード例 #16
0
        protected override async void OnInitialize()
        {
            base.OnInitialize();

            var startInterval = TimeSpan.FromMilliseconds(100);

            clockTimer = new DispatcherTimer
            {
                Interval = startInterval
            };
            clockTimer.Tick += InitTimeTick;

            countdownTimer           = new DispatcherTimer();
            countdownTimer.Interval += startInterval;
            countdownTimer.Tick     += InitCountdownTick;

            clockTimer.Start();
            countdownTimer.Start();

            if (RegionSelectorService.Region == ServerRegion.XBOXEU ||
                RegionSelectorService.Region == ServerRegion.XBOXNA)
            {
                News?.Clear();
                News = new ObservableCollection <NewsItem>(await BdoNewsDataService.GetXboxNews());
            }
            else if (RegionSelectorService.Region == ServerRegion.PCEU ||
                     RegionSelectorService.Region == ServerRegion.PCNA)
            {
                News?.Clear();
                News = new ObservableCollection <NewsItem>(await BdoNewsDataService.GetPcNews());
            }
            else if (RegionSelectorService.Region == ServerRegion.PCSEA)
            {
                News?.Clear();
                News = new ObservableCollection <NewsItem>(await BdoNewsDataService.GetPcNews(isSea: true));
            }
        }
コード例 #17
0
ファイル: MainViewModel.cs プロジェクト: taseski/inSpace
        public void LoadData()
        {
            try
            {
                string    url     = "http://nasamissions.azurewebsites.net/api/values";
                WebClient client2 = new WebClient();

                client2.Headers["Accept"] = "application/json";
                client2.DownloadStringAsync(new Uri(url));
                client2.DownloadStringCompleted += (s1, e1) =>
                {
                    if (e1.Error != null)
                    {
                        News.Clear();
                        Console.WriteLine("Error.");
                        bar.Visibility = System.Windows.Visibility.Collapsed;
                        NewsItem ni = new NewsItem();
                        ni.Title   = "Connection failed";
                        ni.Content = "Please check your internet";

                        News.Add(ni);
                        return;
                    }

                    List <Space_Apps_ATMTech.TempModels.MissionFull> data = JsonConvert.DeserializeObject <List <Space_Apps_ATMTech.TempModels.MissionFull> >(e1.Result.ToString());
                    foreach (Space_Apps_ATMTech.TempModels.MissionFull item in data)
                    {
                        //Space_Apps_ATMTech.TempModels.MissionFull mf = item as Space_Apps_ATMTech.TempModels.MissionFull;
                        this.TempMissions.Add(item);
                    }
                };
            }
            catch
            {
            }

            try
            {
                string    uri    = "http://data.nasa.gov/api/get_recent_datasets?count=15";
                WebClient client = new WebClient();

                client.Headers["Accept"] = "application/json";


                client.DownloadStringAsync(new Uri(uri));
                client.DownloadStringCompleted += (s1, e1) =>
                {
                    if (e1.Error != null)
                    {
                        News.Clear();
                        Console.WriteLine("Error.");
                        bar.Visibility = System.Windows.Visibility.Collapsed;
                        NewsItem ni = new NewsItem();
                        ni.Title   = "Connection failed";
                        ni.Content = "Please check your internet";

                        News.Add(ni);
                        return;
                    }
                    News.Clear();
                    this.IsDataLoaded = true;
                    bar.Visibility    = System.Windows.Visibility.Collapsed;
                    var data = JsonConvert.DeserializeObject <RootObject>(e1.Result.ToString());

                    foreach (Post post in data.posts)
                    {
                        NewsItem it  = new NewsItem();
                        String   str = post.content;

                        StringBuilder sb      = new StringBuilder();
                        bool          canTake = true;

                        foreach (char c in str)
                        {
                            if (c == '<' || c == '&')
                            {
                                canTake = false;
                            }
                            else if (c == '>' || c == ';')
                            {
                                canTake = true;
                            }
                            else
                            {
                                if (canTake)
                                {
                                    sb.Append(c);
                                }
                            }
                        }
                        str        = sb.ToString();
                        it.Content = str;

                        it.Title      = post.title;
                        it.MissionUrl = post.url;
                        News.Add(it);
                    }
                };
            }
            catch (Exception ee)
            {
                Console.Write(ee.ToString());
            }
        }
コード例 #18
0
        public void LoadMarquee()
        {
            if (News == null)
            {
                News = new List <string>();
            }
            else
            {
                News.Clear();
            }
            string filename = string.Format("{0}/Resource/{1}", App.CONFIGPATH, lamppath);

            if (System.IO.File.Exists(filename))
            {
                using (FileStream fs = new FileStream(filename, FileMode.Open))
                {
                    StreamReader rd = new StreamReader(fs, System.Text.Encoding.Default);
                    rd.BaseStream.Seek(0, SeekOrigin.Begin);
                    string tmpstr = rd.ReadToEnd();
                    int    index  = 0;
                    foreach (string each in tmpstr.Split(new char[] { '\r', '\n' }))
                    {
                        if (string.IsNullOrEmpty(each))
                        {
                            continue;
                        }
                        if (index < 10)
                        {
                            News.Add(each);
                        }
                        //str += each + "          ";
                        index++;
                    }
                }
            }

            try
            {
                if (News.Count >= 10)
                {
                    return;
                }
                List <string> list = new List <string>();
                XmlSerializer xsi  = new XmlSerializer(typeof(List <string>));
                using (FileStream fs = new FileStream(System.IO.Path.Combine(App.CONFIGPATH, "Resource/News.xml"), FileMode.Open))
                {
                    list = xsi.Deserialize(fs) as List <string>;
                }

                if (list.Count == 0)
                {
                    return;
                }

                int length   = 10 - News.Count;
                int tmpcount = list.Count - 1;

                if (length > 0)
                {
                    List <int> tmp = new List <int>();
                    int        j;
                    for (int i = 0; i < length; i++)
                    {
                        do
                        {
                            Random r = new Random();
                            j = r.Next(tmpcount);
                        } while (tmp.Contains(j));
                        tmp.Add(j);
                        News.Add(list[j]);
                    }
                }

                string content = string.Empty;

                foreach (var each in News)
                {
                    content += each + "          ";
                }

                Lamp = content;
            }
            catch (Exception ex)
            {
            }
        }
コード例 #19
0
        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (e.AddedItems == null || e.AddedItems.Count <= 0)
                {
                    return;
                }

                var viewModel = (TabViewModel)e.AddedItems[0];

                NewsBox.Visibility       = viewModel.Name == "Новости"
                    ? NewsBox.Visibility = Visibility.Visible
                    : Visibility.Collapsed;
                if (NewsBox.Visibility != Visibility.Visible)
                {
                    return;
                }

                News.Clear();

                Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        var newsLogs = await ConfigurationManager.AppSettings["NewsApi"].GetJsonAsync <NewsModel[]>();

                        foreach (var newsModel in newsLogs.OrderByDescending(x => x.PostTime))
                        {
                            var id = newsModel.Id;

                            if (News.Select(x => x.Id).Contains(id))
                            {
                                continue;
                            }

                            var title    = newsModel.Title;
                            var message  = newsModel.Message;
                            var postTime = newsModel.PostTime;

                            Dispatcher.BeginInvoke(new Action(() =>
                            {
                                try
                                {
                                    News.Add(new NewsModel
                                    {
                                        Id       = id,
                                        Title    = title,
                                        Message  = message,
                                        PostTime = postTime
                                    });
                                }
                                catch (Exception ex)
                                {
                                    //todo: Add Log To Sql
                                    MessageBox.Show(ex.Message + " || " + ex.StackTrace);
                                }
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        //todo: Add Log To Sql
                        MessageBox.Show(ex.Message + " || " + ex.StackTrace);
                    }
                });
            }
            catch (Exception ex)
            {
                //todo: Add Log To Sql
                MessageBox.Show(ex.Message + " || " + ex.StackTrace);
            }
        }