Exemplo n.º 1
0
        private async void DataServiceOnDataRefreshed(object sender, DataRefreshedEventArgs dataRefreshedEventArgs)
        {
            await DispatcherHelper.UIDispatcher.InvokeAsync(() =>
            {
                try
                {
                    switch (dataRefreshedEventArgs.DataType)
                    {
                    case DataType.TopStoriesArticles:
                        UpdateHeadLine();
                        UpdateTopStoriesArticles();
                        HasInternet = dataRefreshedEventArgs.IsSuccess;

                        if (!dataRefreshedEventArgs.IsSuccess && !IsCachedModeMessageDisplayed)
                        {
                            IsCachedModeMessageDisplayed = true;
                        }
                        IsRefreshingTopStoriesArticles = false;
                        break;

                    case DataType.BreakingNewsArticles:
                        UpdateBreakingStoriesArticles();
                        HasInternet = dataRefreshedEventArgs.IsSuccess;

                        if (!dataRefreshedEventArgs.IsSuccess && !IsCachedModeMessageDisplayed)
                        {
                            IsCachedModeMessageDisplayed = true;
                        }
                        IsRefreshingBreakingNewsArticles = false;
                        break;

                    case DataType.Categories:
                        IsRefreshingCategories = true;
                        if (ListOfCategories != null && ListOfCategories.Count != 0)
                        {
                            IsRefreshingCategories = false;
                            return;
                        }
                        else if (ListOfCategories == null)
                        {
                            ListOfCategories = new ObservableCollection <CategoryDetailsModel>();
                        }
                        ListOfCategories.Clear();
                        foreach (var category in _dataService.ListOfCategories)
                        {
                            ListOfCategories.Add(category);
                        }
                        IsRefreshingCategories = false;
                        break;
                    }
                }
                catch (Exception exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debug.WriteLine("MainViewModel:" + exception);
                    }
                }
            });
        }
Exemplo n.º 2
0
        private QuoteFmCategories()
        {
            Collections   = new Dictionary <decimal, ThreadSaveObservableCollection <QuoteFmItem> >();
            CategoryNames = new Dictionary <decimal, string>();
            catagories    = QuoteSharp.API.getCategories();
            if (catagories != null)
            {
                if (catagories.entities != null)
                {
                    foreach (Category category in catagories.entities)
                    {
                        if (category != null)
                        {
                            Collections.Add(category.id, new ThreadSaveObservableCollection <QuoteFmItem>());
                            CategoryNames.Add(category.id, category.name);
                            AppController.Current.registerNotificationClass("QUOTE.fm Category " + category.name);
                        }
                    }
                }
            }

            backgroundWorkerCategories = new BackgroundWorker();
            backgroundWorkerCategories.WorkerReportsProgress      = true;
            backgroundWorkerCategories.WorkerSupportsCancellation = true;
            backgroundWorkerCategories.DoWork             += new DoWorkEventHandler(backgroundWorkerCategories_DoWork);
            backgroundWorkerCategories.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorkerCategories_RunWorkerCompleted);
            backgroundWorkerCategories.ProgressChanged    += new ProgressChangedEventHandler(backgroundWorkerCategories_ProgressChanged);
        }
Exemplo n.º 3
0
        private async void RefreshCategories()
        {
            DispatcherHelper.UIDispatcher.BeginInvoke(() =>
            {
                IsRefreshingCategories = true;

                if (ListOfCategories == null)
                {
                    ListOfCategories = new ObservableCollection <CategoryDetailsModel>();
                }
            });
            try
            {
                var categories = new List <CategoryDetailsModel>();
                foreach (var category in await _dataService.GetCategoryDetailsAsync(true))
                {
                    categories.Add(category);
                }
                if (categories != null && categories.Count >= 1)
                {
                    DispatcherHelper.UIDispatcher.BeginInvoke(() =>
                    {
                        ListOfCategories.Clear();
                        foreach (var category in categories.OrderBy(o => o.Order))
                        {
                            ListOfCategories.Add(category);
                        }
                    });
                }
            }
            catch (Exception exception)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine("MainViewModel:" + exception);
                }
            }
            DispatcherHelper.UIDispatcher.BeginInvoke(() =>
            {
                IsRefreshingCategories = false;
                if (ListOfCategories != null && ListOfCategories.Count > 0)
                {
                    if (FavCategories == null)
                    {
                        FavCategories = new ObservableCollection <CategoryDetailsModel>();
                    }
                    FavCategories.Clear();
                    foreach (var category in ListOfCategories)
                    {
                        if (category.IsPinned == true)
                        {
                            FavCategories.Add(category);
                        }
                    }
                }
            });
        }
Exemplo n.º 4
0
        public async void ReadCategoriesXml()
        {
            try
            {
                string configFileUri = "ms-appx:///Config/AllCategories.xml";

                var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(configFileUri));

                Stream fs = await file.OpenStreamForReadAsync();

                var serializer = new XmlSerializer(typeof(ListOfCategories));
                _listOfcategories = (ListOfCategories)serializer.Deserialize(fs);
            }
            catch (Exception)
            { }
        }
Exemplo n.º 5
0
        private async void LoadOrRefreshCategories()
        {
            DispatcherHelper.UIDispatcher.BeginInvoke(() => { IsRefreshingCategories = true; });
            try
            {
                if (ListOfCategories == null || ListOfCategories.Count != 0)
                {
                    DispatcherHelper.UIDispatcher.BeginInvoke(() => { IsRefreshingCategories = false; });
                    return;
                }
                var categories       = new List <CategoryDetailsModel>();
                var categoriesFromDS = await _dataService.GetCategoryDetailsAsync();

                if (categoriesFromDS != null && categoriesFromDS.Count > 0)
                {
                    foreach (var category in categoriesFromDS)
                    {
                        categories.Add(category);
                    }
                    DispatcherHelper.UIDispatcher.BeginInvoke(() =>
                    {
                        ListOfCategories.Clear();
                        foreach (var category in categories.OrderBy(o => o.Order))
                        {
                            ListOfCategories.Add(category);
                        }
                    });
                }
            }
            catch (Exception exception)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine("MainViewModel:" + exception);
                }
            }
            DispatcherHelper.UIDispatcher.BeginInvoke(() => { IsRefreshingCategories = false; });
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            /* This is quite simple testing
             *
             * Methodes do return NULL is no result is available - I do not check here but you should in your application...
             * I decided to create own objects for every result so you can easily see all attributes in debug
             * And I decided to keep this test code very, very simple (no extra methods / functions)
             *
             */
            Console.WriteLine("Test tool for API calls in Quote#");
            Console.WriteLine("###################\n");
            // Categories
            ListOfCategories listCategories = API.getCategories();

            Console.WriteLine("-> List of categories");
            foreach (Category category in listCategories.entities)
            {
                Console.WriteLine(" " + category.ToString());
            }

            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Recommendations\n");
            // Recommendations
            int id = 900;

            Console.Write("Id of recommendation to fetch (default is 900): ");
            string idString = Console.ReadLine();

            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 900");
                id = 900;
            }
            Recommendation reco = API.getRecommendation(id);

            Console.WriteLine(reco.ToString() + "\n");

            Console.Write("Id of article to fetch recommendations of (default is 123): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 123");
                id = 123;
            }
            ListOfRecommendations listRecosArticle = API.getRecommendationsListByArticle(id);

            Console.WriteLine("Fetched for article " + listRecosArticle.article.ToString());
            foreach (Recommendation recoInArticle in listRecosArticle.entities)
            {
                Console.WriteLine(" " + recoInArticle.ToString());
            }

            Console.Write("\nUsername to fetch recommendations of (default is quotefm): ");
            string username = Console.ReadLine();

            if (string.IsNullOrEmpty(username))
            {
                Console.WriteLine("Using default username quotefm");
                username = "******";
            }
            ListOfRecommendations listRecosUser = API.getRecommendationsListByUser(username);

            Console.WriteLine("Fetched for username " + username);
            foreach (Recommendation recoOfUser in listRecosUser.entities)
            {
                Console.WriteLine(" " + recoOfUser.ToString());
            }


            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Articles\n");
            // Articles
            Console.Write("Id of article to fetch (default is 2111): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 2111");
                id = 2111;
            }
            Article article = API.getArticle(id);

            Console.WriteLine(article.ToString());

            Console.Write("\nList of category ids to fetch articles for (commasepareted - default is 1,3): ");
            string         catIds = Console.ReadLine();
            List <decimal> ids    = new List <decimal>();

            if (!string.IsNullOrEmpty(catIds))
            {
                string[] catIdsArray = catIds.Split(',');
                foreach (string catIdString in catIdsArray)
                {
                    try {
                        int catId = Convert.ToInt32(catIdString);
                        ids.Add(catId);
                    }
                    catch {}
                }
            }
            if (ids.Count == 0)
            {
                Console.WriteLine("Using default 1,3");
                ids.Add(1);
                ids.Add(3);
            }
            ListOfArticles listArticlesCategory = API.getArticlesListByCategories(ids);

            foreach (Article articleOfCat in listArticlesCategory.entities)
            {
                Console.WriteLine(" " + articleOfCat.ToString());
            }

            Console.Write("\nId of article page fetch articles of (default is 123): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 123");
                id = 123;
            }
            ListOfArticles listArticlesByPage = API.getArticlesListByPage(123);

            Console.WriteLine("Page is " + listArticlesByPage.page.ToString());
            foreach (Article articleOfPage in listArticlesByPage.entities)
            {
                Console.WriteLine(" " + article.ToString());
            }

            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Pages\n");
            //Pages

            Console.Write("Id of page to fetch (default is 4223): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 4223");
                id = 4223;
            }
            Page pageById = API.getPage(id);

            Console.WriteLine(pageById.ToString());

            Console.Write("\nDomain to fetch page of (default is spiegel.de): ");
            string domain = Console.ReadLine();

            if (string.IsNullOrEmpty(domain))
            {
                Console.WriteLine("Using default domain spiegel.de");
                domain = "spiegel.de";
            }
            Page pageByDomain = API.getPage(domain);

            Console.WriteLine(pageByDomain.ToString());


            Console.WriteLine("\n###################\n");
            Console.WriteLine("-> Users\n");
            // Users
            Console.Write("Id of user to fetch (default is 1): ");
            idString = Console.ReadLine();
            try
            {
                id = Convert.ToInt32(idString);
            }
            catch
            {
                Console.WriteLine("Using default 1");
                id = 1;
            }
            User userById = API.getUser(id);

            Console.WriteLine(userById.ToString());

            Console.Write("\nUsername to fetch (default is quotefm): ");
            username = Console.ReadLine();
            if (string.IsNullOrEmpty(username))
            {
                Console.WriteLine("Using default username quotefm");
                username = "******";
            }
            User userByUsername = API.getUser(username);

            Console.WriteLine(userByUsername.ToString());

            Console.WriteLine("\nFollowers of " + username);
            ListOfUsers listUserFollowers = API.getUsersListOfFollowers(username);

            foreach (User follower in listUserFollowers.entities)
            {
                Console.WriteLine(" " + follower.ToString());
            }

            Console.WriteLine("\nFollowings of " + username);
            ListOfUsers listUserFollowings = API.getUsersListOfFollowings(username);

            foreach (User following in listUserFollowings.entities)
            {
                Console.WriteLine(" " + following.ToString());
            }

            Console.WriteLine("Completed... Press enter to close");
            Console.ReadLine();
        }
Exemplo n.º 7
0
 public CategoriesHelper()
 {
     _listOfcategories = new ListOfCategories();
     ReadCategoriesXml();
 }
 public CategoriesChangedEventArgs(ListOfCategories categories)
 {
     ListOfcategories = categories;
 }