private void DownloadCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            var root = JsonConvert.DeserializeObject<DataModel.GoogleFeed>(e.Result);

            DataModel.ChannelItem channelItem = null;

            if (root.ResponseData != null)
            {
                var feedObj = root.ResponseData.Feed;

                var userToken = e.UserState as DataModel.UserToken;

                channelItem = MiscHelpers.CreateFeedItem(feedObj, userToken.ChannelId);

            }
            else
            {
                //ToDO: Feed obj not available, provide url instead

                channelItem = new DataModel.ChannelItem()
                {
                    FeedAuthor = "123",
                    FeedDescription = "123",
                    FeedTitle = "123",
                    Tag = Guid.NewGuid()
                };
            }
            /*
            var newsList = root.ResponseData.Feed.Entries;

            if (newsList != null)
            {
                _newsList = new List<DataModel.ContextItem>();

                foreach (var entry in newsList)
                {
                    var newsItem = MiscHelpers.CreateNewsItem(entry);
                    _newsList.Add(newsItem);
                }
            }
            else
            {
                _newsList = new List<DataModel.ContextItem>();
                //ToDO: Feed entries obj not available
            }
            */

            var u = e.UserState as DataModel.UserToken;

            if (u != null)
            {
                // Write to the Isolated Storage
                if (u.DataFetchType != null)
                {
                    MiscHelpers.SaveDataToIsolatedStorage(u.DataFetchType + ".xml", channelItem, typeof(DataModel.ChannelItem));
                }

                //Reset variables
                //_newsList = new List<DataModel.ContextItem>();

                //Call ScheduledAgent's NotifyCompleted() or other callback
                if (u.Callback != null)
                {
                    (u.Callback).Invoke();
                }
            }
            else
            {
                //Web-fetch only: _feedItemlist
            }
        }
        private void DownloadFeedContentCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            var root = JsonConvert.DeserializeObject<DataModel.GoogleFeed>(e.Result);

            if (root.ResponseData != null)
            {
                var feedObj = root.ResponseData.Feed;

                var userToken = e.UserState as DataModel.UserToken;

                DataModel.ChannelItem feedItem = MiscHelpers.CreateFeedItem(feedObj, userToken.ChannelId);

                _tempStorage.Add(userToken.ChannelId, feedItem);

                _feedItemlist.Add(feedItem);

            }
            else
            {
                //ToDO: Feed obj not available, provide url instead

                DataModel.ChannelItem feedItem = new DataModel.ChannelItem()
                {
                    FeedAuthor = "123",
                    FeedDescription = "123",
                    FeedTitle = "123",
                    Tag = Guid.NewGuid()
                };
                var userToken = e.UserState as DataModel.UserToken;

                _tempStorage.Add(userToken.ChannelId, feedItem);

                _feedItemlist.Add(feedItem);

            }

            if (_feedItemlist.Count == _googleFeedsResponseDataEntryListSize)
            {

                var u = e.UserState as DataModel.UserToken;

                if (u != null)
                {
                    // Write to the Isolated Storage
                    if (u.DataFetchType != null)
                    {

                        if ((u.DataFetchType).StartsWith("fbd-"))
                        {
                            foreach (var item in _tempStorage)
                            {
                                AppendFreshNewsItemToChannelStorage(item);
                            }
                        }

                        var categoryItem = new DataModel.CategoryItem
                            {
                                CategoryName = "123",
                                ChannelItems = _feedItemlist
                            };
                        MiscHelpers.SaveDataToIsolatedStorage(u.DataFetchType + ".xml", categoryItem, typeof(DataModel.CategoryItem));
                    }

                    //Reset variable
                    _feedItemlist = new List<DataModel.ChannelItem>();

                    //Callback to goto new page once fetching is completed
                    if (u.Callback != null)
                    {
                        (u.Callback).Invoke();
                    }
                }
                else
                {
                    //Web-fetch only: _feedItemlist
                }
            }

            //Call ScheduledAgent's NotifyCompleted()
            //(e.UserState as Action).Invoke();
        }
        private void DownloadFeedsJsonCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            //if (e.UserState == null) return;
            try
            {
                var root = JsonConvert.DeserializeObject<DataModel.GoogleFeeds>(e.Result);

                List<DataModel.GoogleFeedsResponseDataEntry> googleFeedsResponseDataEntryList = root.ResponseData.ResponseData;
                if (googleFeedsResponseDataEntryList != null)
                {
                    var _feedItemlist = new List<DataModel.ChannelItem>();

                    int n = 0;
                    foreach (var entry in googleFeedsResponseDataEntryList)
                    {
                        if (n++ >= 6) break;

                        if (entry.Url != null && !"".Equals(entry.Url))
                        {
                            string title = Regex.Replace(entry.Title, @"<[^>]+>|&nbsp;", "").Trim();
                            string snippet = Regex.Replace(entry.ContentSnippet, @"<[^>]+>|&nbsp;", "").Trim();

                            var channelItem = new DataModel.ChannelItem()
                            {
                                Tag = "feed|" + entry.Link + "|" + entry.Url,

                                FeedUrl = entry.Url,
                                FeedLink = entry.Link,
                                //FeedAuthor = feed.Authors.ToString(),
                                FeedDescription = snippet,
                                FeedTitle = title,

                                NewsItems = null,

                                NewsContent = snippet,
                                //NewsLink = entry.Link,
                                //NewsAuthor = feed.Authors.ToString(),
                                NewsSnippet = snippet,
                                NewsTitle = title,
                                NewsImages = null,

                                ChannelTag = entry.Link
                            };

                            _feedItemlist.Add(channelItem);
                        }
                    }

                    var categoryItem = new DataModel.CategoryItem
                    {
                        ChannelItems = _feedItemlist
                    };
                    var u = e.UserState as DataModel.UserToken;
                    Debug.WriteLine("Prefetch:" + u.DataFetchType);
                    MiscHelpers.SaveDataToIsolatedStorage(u.DataFetchType + ".xml", categoryItem,
                                                          typeof(DataModel.CategoryItem));
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void DownloadCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            var root = JsonConvert.DeserializeObject<DataModel.FacebookFeeds>(e.Result);

            DataModel.ChannelItem channelItem = null;

            if (root.Data != null)
            {
                var fbfeeds = root.Data;

                var entry = fbfeeds[0];

                var newsItemList = new List<DataModel.NewsItem>();

                foreach (var f in fbfeeds)
                {
                    var title = f.Name;
                    if (f.From != null && f.From.Name != null)
                    {
                        title = f.From.Name;
                    }

                    var message = f.Message;
                    if (f.Message == null)
                    {
                        message = f.Caption;
                    }
                    if (f.Message != null && f.Caption != null && f.Caption.Length > f.Message.Length)
                    {
                        message = f.Caption;
                    }

                    var item = new DataModel.NewsItem()
                    {
                        Tag = "news|" + f.Link + "|fbfeeds",
                        NewsContent = message,
                        NewsLink = f.Link,
                        NewsSnippet = message,
                        NewsTitle = title,
                        NewsImages = new List<string>(){f.Picture},
                        FeedTitle = "Facebook",
                        FeedUrl = "fbfeeds",
                        IsNew = false
                    };
                    newsItemList.Add(item);
                }

                channelItem = new DataModel.ChannelItem()
                {
                    Tag = "feed|fbfeeds|fbfeeds",

                    NewsItems = newsItemList,

                    NewsContent = entry.Message,
                    NewsLink = entry.Link,
                    NewsSnippet = entry.Message,
                    NewsTitle = entry.Name,
                    NewsImages = new List<string>() { entry.Picture }
                };

                //var userToken = e.UserState as DataModel.UserToken;
            }
            else
            {
                //ToDO: Feed obj not available, provide url instead

                channelItem = new DataModel.ChannelItem()
                {
                    Tag = "feed|fbfeeds|fbfeeds"
                };
            }

            var u = e.UserState as DataModel.UserToken;

            if (u != null)
            {
                // Write to the Isolated Storage
                if (u.DataFetchType != null)
                {
                    MiscHelpers.SaveDataToIsolatedStorage(u.DataFetchType + ".xml", channelItem, typeof(DataModel.ChannelItem));
                    /*
                    if ((u.DataFetchType).StartsWith("fbd-"))
                    {
                        AppendFreshNewsItemToChannelStorage(new KeyValuePair<string, DataModel.ChannelItem>("fbfeeds",
                                                                                                            channelItem));
                    }
                    else
                    {
                        MiscHelpers.SaveDataToIsolatedStorage(u.DataFetchType + ".xml", channelItem, typeof(DataModel.ChannelItem));
                    }
                     */
                }

                //Reset variables
                //_newsList = new List<DataModel.ContextItem>();

                //Call ScheduledAgent's NotifyCompleted() or other callback
                if (u.Callback != null)
                {
                    (u.Callback).Invoke();
                }
            }
            else
            {
                //Web-fetch only: _feedItemlist
            }
        }
        private void DownloadCompletedCallback(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            // Load the feed into a SyndicationFeed instance.
            SyndicationFeed feed = null;
            try
            {
                var stringReader = new StringReader(e.Result);
                var xmlReader = XmlReader.Create(stringReader);
                feed = SyndicationFeed.Load(xmlReader);
            }
            catch (Exception ex)
            {
                feed = null;
            }

            DataModel.ChannelItem channelItem = null;

            if (feed != null)
            {
                var userToken = e.UserState as DataModel.UserToken;

                channelItem = MiscHelpers.CreateFeedItem2(feed, userToken.ChannelId, userToken.FeedUrl);
            }
            else
            {
                //ToDO: Feed obj not available, provide url instead

                channelItem = new DataModel.ChannelItem()
                {
                    FeedAuthor = "123",
                    FeedDescription = "123",
                    FeedTitle = "123",
                    Tag = Guid.NewGuid()
                };
            }

            var u = e.UserState as DataModel.UserToken;

            if (u != null)
            {
                // Write to the Isolated Storage
                if (u.DataFetchType != null)
                {
                    string storageName = HttpUtility.UrlEncode(u.DataFetchType);
                    MiscHelpers.SaveDataToIsolatedStorage(storageName + ".xml", channelItem, typeof(DataModel.ChannelItem));
                }

                //Reset variables
                //_newsList = new List<DataModel.ContextItem>();

                //Call ScheduledAgent's NotifyCompleted() or other callback
                if (u.Callback != null)
                {
                    (u.Callback).Invoke();
                }
            }
            else
            {
                //Web-fetch only: _feedItemlist
            }
        }
        private void DownloadCompletedCallbackAccumulated(Object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null) return;
            if (string.IsNullOrEmpty(e.Result)) return;

            // Load the feed into a SyndicationFeed instance.
            SyndicationFeed feed = null;
            try
            {
                var stringReader = new StringReader(e.Result);
                var xmlReader = XmlReader.Create(stringReader);
                feed = SyndicationFeed.Load(xmlReader);
            }
            catch (Exception ex)
            {
                feed = null;
            }

            DataModel.ChannelItem channelItem = null;

            if (feed != null)
            {
                var userToken = e.UserState as DataModel.UserToken;

                channelItem = MiscHelpers.CreateFeedItem2(feed, userToken.ChannelId, userToken.FeedUrl);
            }
            else
            {
                //ToDO: Feed obj not available, provide url instead

                channelItem = new DataModel.ChannelItem()
                {
                    FeedAuthor = "123",
                    FeedDescription = "123",
                    FeedTitle = "123",
                    Tag = Guid.NewGuid()
                };
            }

            var u = e.UserState as DataModel.UserToken;

            if (u != null)
            {
                // Write to the Isolated Storage
                if (u.DataFetchType != null)
                {
                    string channelStorageName = HttpUtility.UrlEncode(u.DataFetchType) + ".xml";

                    var existingChannelItem = MiscHelpers.GetChannelItemFromIsolatedStorage(channelStorageName);

                    if (existingChannelItem != null && existingChannelItem.NewsItems != null)
                    {
                        var existingNewsItems = existingChannelItem.NewsItems;
                        var newsItems = channelItem.NewsItems;

                        var addNewsItems = new List<DataModel.NewsItem>();

                        //ToDo: Integrate duplication checking to map

                        //Check if newsItem already existed in channel-storage-file
                        foreach (var newsItem in newsItems)
                        {
                            bool isMatch = false;
                            foreach (var existingNewsItem in existingNewsItems)
                            {
                                if ((newsItem.NewsLink).Equals(existingNewsItem.NewsLink))
                                {
                                    //Debug.WriteLine("M:" + newsItem.NewsLink);
                                    isMatch = true;
                                    break;
                                }
                            }
                            if (!isMatch)
                            {
                                //Debug.WriteLine("U:" + newsItem.NewsLink);
                                newsItem.IsNew = true;
                                addNewsItems.Add(newsItem);
                            }
                        }

                        //Add news-items to channel-storage-file, if any
                        if (addNewsItems.Count > 0)
                        {
                            existingChannelItem.NewsItems.AddRange(addNewsItems);
                            existingChannelItem.NumOfNewNewsItems += addNewsItems.Count;
                            MiscHelpers.SaveDataToIsolatedStorage(channelStorageName, existingChannelItem, typeof(DataModel.ChannelItem));

                            Debug.WriteLine("Downloaded G2:" + channelStorageName);
                        }
                    }

                    //MiscHelpers.SaveDataToIsolatedStorage(channelStorageName + ".xml", channelItem, typeof(DataModel.ChannelItem));
                }

                //Reset variables
                //_newsList = new List<DataModel.ContextItem>();

                //Call ScheduledAgent's NotifyCompleted() or other callback
                if (u.Callback != null)
                {
                    (u.Callback).Invoke();
                }
            }
            else
            {
                //Web-fetch only: _feedItemlist
            }
        }