public static DataFeedsFetcher3 GetInstance() { if (_instance == null) { _instance = new DataFeedsFetcher3(); } return _instance; }
private void ToCategoryPage(string mainCat) { Analytics.GetInstance().TrackCategoryPressed(mainCat); var cfb = CategoryConfigB.Config; var subCatsStg = cfb[mainCat]["subcat"]; var subCats = subCatsStg.Split('|'); List<Dictionary<string, string>> categoryInfoList = subCats.Select(subCat => cfb[subCat]).ToList(); string fileNames = ""; var noDownloadCount = 0; var k = 0; foreach (var item in categoryInfoList) { bool isStorageFileExisted = false; string subscribeFileName = "fbd-ctgy-" + item["cachename"]; using (IsolatedStorageFile f = IsolatedStorageFile.GetUserStoreForApplication()) { isStorageFileExisted = f.FileExists(subscribeFileName + ".xml"); } if (isStorageFileExisted) { noDownloadCount++; fileNames += subscribeFileName + "|"; //addGiantHelper(subscribeFileName); } else { string keyword = item["keyword"]; string cacheName = "fbd-localcache-" + item["cachename"]; //cacheName = "fbd-ctgy-" + item["cachename"]; fileNames += cacheName + "|"; int k1 = k; var dataFetcher = new DataFeedsFetcher3(); dataFetcher.FetchFeeds(keyword, new DataModel.UserToken { DataFetchType = cacheName, Callback = delegate { Debug.WriteLine("D:" + keyword); CategoryPage.NumOfDownloadCompleted++; CategoryPage.IsDownloadCompleted[k1]++; //addGiantHelper(cacheName); } }); } k++; } fileNames = fileNames.TrimEnd('|'); string isNoDownload = (noDownloadCount == categoryInfoList.Count) ? "&isnodownload=1" : ""; NavigationService.Navigate(new Uri("/CategoryPage.xaml?cachenames=" + fileNames + "&maincat=" + mainCat + isNoDownload, UriKind.Relative)); }
/* private void TileTap14(object sender, System.Windows.Input.GestureEventArgs e) { } private void TileTap15(object sender, System.Windows.Input.GestureEventArgs e) { } */ private void SearchBoxKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { BusyIndicator.IsRunning = true; BusyIndicator.Visibility = Visibility.Visible; SearchResultListBox.Visibility = Visibility.Collapsed; this.Focus(); var adsTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(10) }; adsTimer.Tick += (sender2, args2) => { //Busy indicator timeouteout BusyIndicator.IsRunning = false; BusyIndicator.Visibility = Visibility.Collapsed; SearchResultListBox.Visibility = Visibility.Visible; adsTimer.Stop(); }; adsTimer.Start(); var box = sender as RadTextBox; /* ToCategoryPage(new List<Dictionary<string, string>>() { new Dictionary<string, string>() { {"cachename", "search"}, {"keyword", box.Text} } }); */ string keyword = box.Text; const string cacheName = "fbd-localcache-search"; Dispatcher.BeginInvoke(() => { var dataFetcher = new DataFeedsFetcher3(); dataFetcher.FetchFeeds(keyword, new DataModel.UserToken { DataFetchType = cacheName, Callback = delegate { AppendSearchContent(cacheName); } }); }); } }
public void AddSubCategoryTile(string storageName, DataModel.ContextItem firstItem) { var homePagePinTileList = MiscHelpers.GetItemFromIsolatedStorage<List<PinTile>>("fbd-pintiles.xml") ?? new List<PinTile>(); string categoryName = storageName.Replace("fbd-localcache-", ""); categoryName = categoryName.Replace("fbd-ctgy-", ""); Dictionary<string, string> categoryinfo = CategoryConfigA.Config[categoryName]; string title = categoryinfo["title"]; string photo = categoryinfo["photo_default"]; string keywords = categoryinfo["keyword"]; string newStorageName = "fbd-ctgy-" + categoryName; homePagePinTileList.Add(new PinTile() { PinTypeLabel = PinType.SubCategory, Title = title, StorageName = newStorageName, TileImage = photo, TileCategory = categoryName, TileGuid = "fbd-hometile-" + Guid.NewGuid() }); var fetcher = new DataFeedsFetcher3(); fetcher.FetchFeeds(keywords, new DataModel.UserToken { DataFetchType = newStorageName, Callback = delegate { MiscHelpers.SaveDataToIsolatedStorage("fbd-pintiles.xml", homePagePinTileList, typeof(List<PinTile>)); //RadMessageBox.Show("Tile has been added to home screen.", vibrate: false, verticalAlignment: VerticalAlignment.Center); } }); }
private void ToCategoryPage(string mainCat) { var cfb = CategoryConfigB.Config; var subCatsStg = cfb[mainCat]["subcat"]; var subCats = subCatsStg.Split('|'); List<Dictionary<string, string>> categoryInfoList = subCats.Select(subCat => cfb[subCat]).ToList(); //string fileNames = ""; int countAddGiantDone = 0; var giantCategoryitem = new DataModel.CategoryItem { ChannelItems = new List<DataModel.ChannelItem>() }; Func<string, bool> addGiantHelper = delegate(string fileName) { countAddGiantDone++; var categoryItem = MiscHelpers.GetItemFromIsolatedStorage<DataModel.CategoryItem>(fileName + ".xml"); if (categoryItem != null && categoryItem.ChannelItems != null && categoryItem.ChannelItems.Count > 0) { foreach ( var channelItem in categoryItem.ChannelItems.Where( channelItem => channelItem != null && channelItem.NewsItems != null && channelItem.NewsItems.Count > 0)) { var channelItem2 = MiscHelpers.CreateChannelItem2(channelItem); channelItem2.NewsItems = new List<DataModel.NewsItem> { channelItem.NewsItems[0] }; giantCategoryitem.ChannelItems.Add(channelItem2); } if (countAddGiantDone == categoryInfoList.Count()) { MiscHelpers.SaveDataToIsolatedStorage("fbd-giant.xml", giantCategoryitem, typeof(DataModel.CategoryItem)); NewsListPage.GiantDownloadCompleted++; } } return true; }; int k = 0; foreach (var item in categoryInfoList) { bool isStorageFileExisted = false; string subscribeFileName = "fbd-ctgy-" + item["cachename"]; using (IsolatedStorageFile f = IsolatedStorageFile.GetUserStoreForApplication()) { isStorageFileExisted = f.FileExists(subscribeFileName + ".xml"); } if (isStorageFileExisted) { //fileNames += subscribeFileName + "|"; addGiantHelper(subscribeFileName); } else { string keyword = item["keyword"]; string cacheName = "fbd-localcache-" + item["cachename"]; //cacheName = "fbd-ctgy-" + item["cachename"]; //fileNames += cacheName + "|"; var dataFetcher = new DataFeedsFetcher3(); int k1 = k; Dispatcher.BeginInvoke(() => dataFetcher.FetchFeeds(keyword, new DataModel.UserToken { DataFetchType = cacheName, Callback = () => { //NewsListPage.NumOfDownloadCompleted++; //NewsListPage.IsDownloadCompleted[k1]++; addGiantHelper(cacheName); } })); } k++; } //fileNames = fileNames.TrimEnd('|'); //NavigationService.Navigate(new Uri("/NewsListPage.xaml?homegiant=" + fileNames + "&category=" + mainCat, UriKind.Relative)); NavigationService.Navigate(new Uri("/NewsListPage.xaml?storage=fbd-giant&category=" + mainCat + "&viewtype=" + PinType.Category, UriKind.Relative)); }
public void FetchCategories(Action callback) { //var pinTileList = h.GetHomePagePinTileList(); var pinTileList = MiscHelpers.GetItemFromIsolatedStorage<List<PinTile>>("fbd-pintiles.xml") ?? new List<PinTile>(); if (pinTileList == null) return; int completedCount = 0; foreach (var p in pinTileList) { if ("fbfeeds".Equals(p.TileCategory) || "search".Equals(p.TileCategory) || "favourite".Equals(p.TileCategory) || "historicalview".Equals(p.TileCategory)) { continue; } if (PinType.Category.Equals(p.PinTypeLabel)) { var mainCat = p.TileCategory; var cfb = CategoryConfigB.Config; var subCatsStg = cfb[mainCat]["subcat"]; var subCats = subCatsStg.Split('|'); List<Dictionary<string, string>> categoryInfoList = subCats.Select(subCat => cfb[subCat]).ToList(); foreach (var item in categoryInfoList) { string keyword = item["keyword"]; string storageName = "fbd-ctgy-" + item["cachename"]; var dataFetcher = new DataFeedsFetcher3(); dataFetcher.FetchFeeds(keyword, new DataModel.UserToken { DataFetchType = storageName, Callback = delegate { completedCount++; Debug.WriteLine("Downloaded C: " + storageName); if (completedCount == pinTileList.Count) { completedCount = 0; if (callback != null) { callback.Invoke(); } } } }); } } else if (PinType.SubCategory.Equals(p.PinTypeLabel)) { var cfb = CategoryConfigB.Config; var subCat = p.TileCategory; if ("fbfeeds".Equals(subCat)) continue; string keyword = cfb[subCat]["keyword"]; string storageName = p.StorageName; var dataFetcher = new DataFeedsFetcher3(); dataFetcher.FetchFeeds(keyword, new DataModel.UserToken { DataFetchType = storageName, Callback = delegate { completedCount++; if (_adsTimer != null) { //_adsTimer.Stop(); _adsTimer.Dispose(); _adsTimer = null; } if (completedCount == pinTileList.Count) { completedCount = 0; Debug.WriteLine("Downloaded S: " + storageName); if (callback != null) { callback.Invoke(); } } else { _adsTimer = new Timer(delegate { completedCount = 0; Debug.WriteLine("Downloaded SSS: " + storageName); if (callback != null) { callback.Invoke(); } if (_adsTimer != null) { _adsTimer.Dispose(); _adsTimer = null; } }, null, 20000, Timeout.Infinite); } } }); } else if (PinType.Channel.Equals(p.PinTypeLabel)) { string feedUrl = p.StorageName; feedUrl = feedUrl.Replace("fbd-channel-", ""); string feedLink = ""; if ("fbfeeds".Equals(feedUrl)) continue; string fileName = "fbd-channel-" + feedUrl; string encodedFileName = HttpUtility.UrlEncode(fileName); DataNewsFetcher2 fetcher = DataNewsFetcher2.GetInstance(); fetcher.FetchNewsAccumulated(feedUrl, new DataModel.UserToken() { FeedUrl = feedUrl, ChannelId = feedLink, DataFetchType = fileName, Callback = delegate { completedCount++; if (_adsTimer != null) { //_adsTimer.Stop(); _adsTimer.Dispose(); _adsTimer = null; } if (completedCount == pinTileList.Count) { completedCount = 0; Debug.WriteLine("Downloaded S22: " + fileName); if (callback != null) { callback.Invoke(); } } else { _adsTimer = new Timer(delegate { completedCount = 0; Debug.WriteLine("Downloaded SSS22: " + fileName); if (callback != null) { callback.Invoke(); } if (_adsTimer != null) { _adsTimer.Dispose(); _adsTimer = null; } }, null, 20000, Timeout.Infinite); } } }); } } }