Esempio n. 1
0
        /**
         * Command actions
         */
        public async Task PopulateReferenceArticles()
        {
            try
            {
                _workStatus(true);

                Articles.Clear();

                List <Article> articles = new List <Article>();

                await Task.Run(() =>
                {
                    foreach (Article article in (new ReferenceRepo()).LoadArticlesForReference(Reference))
                    {
                        articles.Add(article);
                    }
                });

                foreach (Article article in articles)
                {
                    Articles.Add(article);
                }

                _workStatus(false);
            }
            catch (Exception e)
            {
                new BugTracker().Track("Reference View", "Populate references", e.Message, e.StackTrace);
                _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
            }
            finally
            {
                _workStatus(false);
            }
        }
        // Private helpers
        private async Task PopulateArticles()
        {
            // 1. Clear existing data grid source
            Articles.Clear();

            List <Article> articles = new List <Article>();

            await Task.Run(() =>
            {
                // 2. Fetch artilces from database
                foreach (Article article in new ArticleRepo().LoadArticles(
                             Users[UserIndex],
                             FilterTitle,
                             FilterAuthors.ToList(),
                             FilterKeywords.ToList(),
                             FilterYear,
                             FilterPersonalComment,
                             _offset,
                             ItemsPerPage,
                             SelectedSection,
                             _currentSort))
                {
                    articles.Add(article);
                }
            });

            // 3. Populate article collection
            foreach (Article article in articles)
            {
                this.Articles.Add(article);
            }
        }
Esempio n. 3
0
        protected async Task LoadArticles()
        {
            Articles.Clear();

            try
            {
                IsDefaultVisible = false;
                var articleResults = await App.Database.GetArticlesAsync();

                foreach (var counter in articleResults)
                {
                    Articles.Add(counter);
                }

                if (articleResults.Count == 0)
                {
                    IsDefaultVisible = true;
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Warning", "Could not retrieve articles.", "OK");

                IsDefaultVisible = true;
            }
        }
Esempio n. 4
0
        public async void LoadArticles(object input = null)
        {
            // 1. Clear existing data grid source
            Articles.Clear();

            // 2. Fetch artilces from database
            List <Article> articles = new List <Article>();

            _workStatus(true);

            await Task.Run(() =>
            {
                new ArticleRepo().GetAllArticles(User, FilterTitle).ForEach((article) =>
                {
                    articles.Add(article);
                });
            });

            _workStatus(false);

            // 3. Populate collection
            foreach (Article article in articles)
            {
                Articles.Add(article);
            }
        }
        async Task ExecuteLoadArticlesCommand()
        {
            try
            {
                Articles.Clear();
                CurrentState = ListState.Loading;
                Title        = $"Edition {EditionId}";
                var edition = await dataStore.GetEditionAsync(EditionId);

                CurrentState = ListState.Success;
                Articles.AddRange(edition.Articles);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                analytics.TrackError(ex, new Dictionary <string, string> {
                    { Constants.Analytics.Properties.EditionId, EditionId }
                });
            }
            finally
            {
                IsBusy             = false;
                shouldForceRefresh = true;
            }
        }
        async Task ExecuteLoadArticlesCommand(bool forceRefresh = false)
        {
            IsBusy = true;

            try
            {
                Articles.Clear();

                if (ShowSaved)
                {
                    // get the saved
                    var articles = dataStore.GetSavedArticles(forceRefresh);
                    Articles.AddRange(articles.Articles);
                    Title = "Bookmarks";
                }
                else
                {
                    Title = $"Edition {EditionId}";
                    var edition = await dataStore.GetEditionAsync(EditionId, forceRefresh);

                    Articles.AddRange(edition.Articles);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 7
0
        protected async Task LoadArticles()
        {
            Articles.Clear();

            try
            {
                this.IsBusy = true;
                var articleResults = await this.TBService.GetAllArticles();

                foreach (var counter in articleResults.Articles)
                {
                    Articles.Add(counter);
                }

                this.IsBusy = false;

                if (articleResults.Articles.Count == 0)
                {
                }
                //await App.Current.MainPage.DisplayAlert("Warning", "No articles found.", "OK");
            }
            catch (Exception ex)
            {
                //await App.Current.MainPage.DisplayAlert("Warning", "Could not retrieve articles.", "OK");
            }
        }
        private void ChangeArticlesSelection(bool isInit = false)
        {
            var xnl1 = doc.SelectNodes(@"Document/Article");

            Dictionary <string, string> DicTemp = new Dictionary <string, string>();

            foreach (var item in xnl1)
            {
                DicTemp.Add(((XmlElement)item).GetAttribute("Id").ToString(), ((XmlElement)item).GetAttribute("Name").ToString());
            }
            Articles.Clear();
            Articles = DicTemp;
            if (isInit)
            {
                ArticleSelected = Articles.Keys.First();
            }
            string str = string.Empty;

            for (int i = 0; i < xnl1.Count; i++)
            {
                if (((XmlElement)xnl1[i]).GetAttribute("Id") == ArticleSelected)
                {
                    str = xnl1[i].InnerText;
                }
            }
            OriDoc.Blocks.Clear();
            OriDoc.Blocks.Add(new Paragraph(new Run(str)));

            RightFontCount = 0;
            ErrorFontCount = 0;
        }
 public void Clear(object input = null)
 {
     FilterTitle = null;
     FilterAuthors.Clear();
     FilterKeywords.Clear();
     FilterYear            = null;
     FilterPersonalComment = null;
     Articles.Clear();
 }
Esempio n. 10
0
        public void UpdateView()
        {
            var articles = _articleRepository.GetEntities();

            Articles.Clear();
            foreach (var article in articles)
            {
                Articles.Add(article);
            }
        }
Esempio n. 11
0
        private async Task GetArticlesAsync()
        {
            string url = $"api/article/articles/relatedcategory";

            Loading = true;
            Articles.Clear();
            StateHasChanged();
            var pagingResponse = await ArticleService.GetVMPageAsync(PagingParameters, url);

            Articles = pagingResponse.Items;
            MetaData = pagingResponse.MetaData;
            Loading  = false;
            StateHasChanged();
        }
Esempio n. 12
0
        private void HandleClearTable()
        {
            BusyOverlayService.SetBusyState(BusyEnum.Busy);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Articles.Clear();

            ItemCount = 0;

            stopwatch.Stop();
            ProcessingTimeMs = stopwatch.ElapsedMilliseconds;
            BusyOverlayService.SetBusyState(BusyEnum.NotBusy);
        }
 private void DeleteAllArticles()
 {
     try
     {
         _dataService.DeleteAllSavedArticles();
         Articles.Clear();
         _rootFrame.GoBack();
     }
     catch (Exception exception)
     {
         if (Debugger.IsAttached)
         {
             Debug.WriteLine("SavedArticlesViewModel:" + exception);
         }
     }
 }
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.ArticlesService.GetArticlesAsync(position, pageIndex, pageSize);

            if (result.Success)
            {
                var articles = JsonConvert.DeserializeObject <List <Articles> >(result.Message.ToString());
                if (articles.Count > 0)
                {
                    if (pageIndex == 1 && Articles.Count > 0)
                    {
                        Articles.Clear();
                    }
                    Articles.AddRange(articles);
                    if (position == 1)
                    {
                        articles.ForEach(s => s.IsRecommend = true);
                    }
                    await SqliteUtil.Current.UpdateArticles(articles);

                    pageIndex++;
                    if (Articles.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                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;
            }
        }
Esempio n. 15
0
        public async Task <List <Article> > LoadCategryArticlesAsync(string category)
        {
            if (Articles == null)
            {
                Articles = new List <Article>();
            }
            Articles.Clear();
            var listOfArticles = new List <Article>();
            var oldArticles    = await DatabaseOperations.GetInstance().GetCategoryArticlesAsync(category);

            if (oldArticles != null && oldArticles.Count > 0)
            {
                Articles.AddRange(oldArticles);
                listOfArticles.AddRange(oldArticles);
            }
            return(listOfArticles);
        }
Esempio n. 16
0
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.ArticlesService.GetArticlesAsync(position, pageIndex, pageSize);

            if (result.Success)
            {
                var articles = JsonConvert.DeserializeObject <List <Articles> >(result.Message.ToString());
                if (articles.Count > 0)
                {
                    try
                    {
                        if (pageIndex == 1 && Articles.Count > 0)
                        {
                            Articles.Clear();
                        }
                        Articles.AddRange(articles);
                        pageIndex++;
                    }
                    catch (Exception ex)
                    {
                        Log.SendLog("ArticlesViewModel.ExecuteRefreshCommandAsync:" + ex.Message);
                    }
                    if (Articles.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SendLog("ArticlesViewModel.GetArticlesAsync:" + result.Message);
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
        private async Task InitNewsAsync(bool forceRefresh = false)
        {
            if (!Articles.IsNullOrEmpty() && !forceRefresh)
            {
                return;
            }

            var articles = await FetchArticlesAsync();

            if (articles != null)
            {
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    Articles.Clear();
                    LoadArticlesPage(articles);
                });
            }
        }
Esempio n. 18
0
        private async Task GetArticlesAsync()
        {
            string url = $"api/article/articles/newest";

            Loading = true;
            Articles.Clear();
            StateHasChanged();
            var pagingResponse = await ArticleService.GetVMPageAsync(PagingParameters, url);

            Articles = pagingResponse.Items;
            if (Articles.Count == 0)
            {
                Message = $"{Translate.Keys["SorryNo"]} {Translate.Keys["Articles"]} {Translate.Keys["Found"]} ! ";
            }
            MetaData = pagingResponse.MetaData;
            Loading  = false;
            StateHasChanged();
        }
Esempio n. 19
0
        /// <summary>
        /// Loop and replace currently displayed articles
        /// </summary>
        /// <param name="arg">Name of article type</param>
        public void FilterArticleAction(object arg)
        {
            // From the buttons' commandArgument
            string selectedType = (string)arg;

            // Set hightlight display for navmenubutton
            foreach (var item in FilterButtons)
            {
                if (item.Type == selectedType)
                {
                    item.IsActive = true;
                }
                else
                {
                    item.IsActive = false;
                }
            }

            // When 'home' is hit. Reset displayed articles to show all
            if (selectedType == "All" || selectedType == "Hem")
            {
                Articles.Clear();

                foreach (var item in storedArticles)
                {
                    Articles.Add(item);
                }

                // Return point here
                return;
            }

            // If not, filter by selected type
            var _ = storedArticles.Where(a => a.Article.Type == selectedType);

            Articles.Clear();

            foreach (var item in _)
            {
                Articles.Add(item);
            }
        }
Esempio n. 20
0
        async Task ExecuteLoadArticlesCommand(bool forceRefresh = false)
        {
            IsBusy = true;

            try
            {
                Articles.Clear();
                var edition = await dataStore.GetEditionAsync(EditionId, forceRefresh);

                Articles.AddRange(edition.Articles);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 21
0
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.BlogsService.GetArticlesAsync(blogApp);

            if (result.Success)
            {
                var articles = JsonConvert.DeserializeObject <List <Articles> >(result.Message.ToString());
                if (articles.Count > 0)
                {
                    if (pageIndex == 1 && Articles.Count > 0)
                    {
                        Articles.Clear();
                    }
                    Articles.AddRange(articles);
                    pageIndex++;
                    if (Articles.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Crashes.TrackError(new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
            }
        }
Esempio n. 22
0
        async Task ExecuteLoadArticlesCommand()
        {
            IsBusy = true;

            try
            {
                Articles.Clear();
                var articles = await DataStore.GetArticlesForEditionAsync(EditionId, true);

                foreach (var item in articles)
                {
                    Articles.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 23
0
        async Task ExecuteLoadArticlesCommand(bool forceRefresh = false)
        {
            IsBusy = true;

            try
            {
                Articles.Clear();

                if (ShowSaved)
                {
                    // get the saved
                    var articles = dataStore.GetSavedArticles(forceRefresh);
                    Articles.AddRange(articles.Articles);
                    Title = "Bookmarks";
                }
                else
                {
                    Title = $"Edition {EditionId}";
                    var edition = await dataStore.GetEditionAsync(EditionId, forceRefresh);

                    Articles.AddRange(edition.Articles);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                analytics.TrackError(ex, new Dictionary <string, string> {
                    { Constants.Analytics.Properties.EditionId, EditionId },
                    { Constants.Analytics.Properties.ShowSaved, ShowSaved.ToString() }
                });
            }
            finally
            {
                IsBusy = false;
            }
        }
        void ExecuteLoadArticlesCommand()
        {
            try
            {
                Articles.Clear();

                // get the saved
                CurrentState = ListState.Loading;
                var articles = dataStore.GetSavedArticles(true);
                Articles.AddRange(articles.Articles);
                Title = "Bookmarks";

                CurrentState = Articles.Count == 0 ? ListState.Empty: ListState.None;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                analytics.TrackError(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 25
0
 private async Task RefreshData()
 {
     _pageIndex = 0;
     Articles.Clear();
     await RequestArticles();
 }
Esempio n. 26
0
        public async override Task <bool> ReadFromWeb()
        {
            if (this.Busy)
            {
                return(false);
            }
            this.Busy = true;

            try
            {
                Articles.Clear();

                var _Client = new HttpClient()
                {
                    Timeout = TimeSpan.FromSeconds(30)
                };
                var _Response = await _Client.GetAsync(this.SourceUrl);

                var _String = await _Response.Content.ReadAsStringAsync();

                var _Parse = (Parser)null;
                int _Index = -1;
                var _Lines = Regex.Split(_String, @"\n");
                foreach (var item in _Lines)
                {
                    if (item.StartsWith("BEGIN:VEVENT"))
                    {
                        _Parse = new Parser();
                    }
                    if (_Parse == null)
                    {
                        continue;
                    }
                    if (item.StartsWith("DTSTART;"))
                    {
                        _Parse.Date = item.Split(':')[1];
                    }
                    if (item.StartsWith("DESCRIPTION:"))
                    {
                        _Parse.Body = item.Substring("DESCRIPTION:".Length).Replace(@"\n", "<p/>");
                    }
                    if (item.StartsWith("LOCATION:"))
                    {
                        _Parse.Location = item.Substring("LOCATION:".Length);
                    }
                    if (item.StartsWith("SUMMARY:"))
                    {
                        _Parse.Subject = item.Substring("SUMMARY:".Length);
                    }
                    if (item.StartsWith("URL:"))
                    {
                        _Parse.Url = item.Substring("URL:".Length);
                    }
                    if (item.StartsWith("END:VEVENT"))
                    {
                        var _Event = _Parse.ToArticle();
                        _Event.Index = _Index++;
                        if (_Event.Url == null)
                        {
                            _Event.Url = new Uri(this.MoreUrl + "#" + _Event.Date.ToString("yyMMddhhmmss")).ToString();
                        }
                        this.Articles.Add(_Event);
                    }
                }
                if (_Parse == null)
                {
                    throw new Exception("Failed to parse calendar; check URL");
                }
                this.Updated = DateTime.Now;
                await base.WriteToCache();

                this.InError = false;
                return(true);
            }
            catch
            {
                // calendar
                Debug.WriteLine("Error reading/parsing: " + this.SourceUrl);
                System.Diagnostics.Debugger.Break();
                // setting inerror to true will remove it from the UI
                this.InError = true;
                return(false);
            }
            finally
            {
                this.Busy = false;
            }
        }
Esempio n. 27
0
 public void RechercherParRef(string reference)
 {
     Articles.Clear();
     BusinessManager.RechercheParRefApproximative(reference).ForEach(c => Articles.Add(c));
 }
Esempio n. 28
0
 public void ChargerStock()
 {
     Articles.Clear();
     BusinessManager.Load().ForEach(c => Articles.Add(c));
 }
        public override void Loaded()
        {
            TxtInput = string.Empty;

            Articles.Clear();
            isInputEnabled = false;

            Index = 1;
            List <string> ls = new List <string>();

            if (App.Model == TestModel.Exam)
            {
                IsBaseInfoVis   = Visibility.Visible;
                IsExerciseModel = Visibility.Hidden;
                time            = Exam.CR_F_TESTTIME * 60;
                string article = Exam.CR_F_ARTICLE;
                while (article.Length != 0)
                {
                    var strTemp = string.Empty;
                    if (article.Length < 30)
                    {
                        ls.Add(article);
                        article = string.Empty;
                    }
                    else
                    {
                        ls.Add(article.Substring(0, 30));
                        strTemp = article.Remove(0, 30);
                        article = strTemp;
                    }
                }
                //ls = Exam.CR_F_ARTICLE.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
            }
            else
            {
                try
                {
                    ExerciseTestTime = Convert.ToInt32(ConfigManager.GetInstance().GetConfigValue("SlitTextCnCharactersTypingDuration", ConfigType.Client));
                }
                catch (Exception)
                {
                }
                Article.Clear();

                IsBaseInfoVis   = Visibility.Hidden;
                IsExerciseModel = Visibility.Visible;
                time            = ExerciseTestTime * 60;


                doc.Load(@".\Source\TypeSlit.xml");
                var xnl1 = doc.SelectNodes(@"Document/Article");

                Dictionary <string, string> DicTemp = new Dictionary <string, string>();
                foreach (var item in xnl1)
                {
                    DicTemp.Add(((XmlElement)item).GetAttribute("Id").ToString(), ((XmlElement)item).GetAttribute("Name").ToString());
                }
                Articles.Clear();
                Articles        = DicTemp;
                ArticleSelected = Articles.Keys.ToArray()[0];
                for (int i = 0; i < xnl1.Count; i++)
                {
                    if (((XmlElement)xnl1[i]).GetAttribute("Id") == Articles.Keys.First())
                    {
                        foreach (XmlNode item in xnl1[i].ChildNodes)
                        {
                            ls.Add(item.InnerText);
                        }
                    }
                }
            }
            TimeSpan ts = new TimeSpan(0, 0, time);

            CountDown = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
            foreach (var item in ls)
            {
                Article.Add(new OneTypeInfo()
                {
                    Index  = ls.IndexOf(item) + 1,
                    StrOri = item,
                });
            }
            TxtOri = Article[Index - 1].StrOri;
            if (timer.Interval != new TimeSpan(0, 0, 1))
            {
                timer.Interval = TimeSpan.FromMilliseconds(1000);
                timer.Tick    += timer_Tick; //你的事件
            }
        }
        public async Task GetCategoryArticlesAsync(string category, bool bForce = false)
        {
            try
            {
                if (_dataService.NetWorkAvailable())
                {
                    if (Articles == null || Articles.Count == 0)
                    {
                        bForce = true;
                    }
                    if (_selectedCategory != category || bForce == true)
                    {
                        if (Articles != null)
                        {
                            Articles.Clear();
                        }
                        else
                        {
                            Articles = new ObservableCollection <Article>();
                        }
                        IsRefreshingArticles = true;
                        _selectedCategory    = category;
                        var articles = await _dataService.LoadCategryArticlesAsync(category);

                        bool canRefresh = await _dataService.CanRefreshCategoryAsync(category);

                        if (articles == null || articles.Count == 0 || canRefresh || bForce)
                        {
                            string categoryUrl = _dataService.GetCategoryUrl(category);
                            var    newArticles = await _dataService.GetCategoryArticlesAsync(category, categoryUrl);

                            if (newArticles != null)
                            {
                                if (articles == null)
                                {
                                    articles = newArticles.ToList();
                                }
                                else
                                {
                                    foreach (var article in newArticles.Where(article => articles.Find(o => o.ArticleId == article.ArticleId) == null))
                                    {
                                        articles.Add(article);
                                    }
                                }
                            }
                        }
                        if (articles != null)
                        {
                            if (Articles != null)
                            {
                                Articles.Clear();
                            }
                            else
                            {
                                Articles = new ObservableCollection <Article>();
                            }
                            foreach (var article in articles.OrderByDescending(o => o.PublishDate).ToList())
                            {
                                Articles.Add(article);
                            }
                        }

                        IsRefreshingArticles = false;
                    }
                }
                else
                {
                    var rootFrame = (App.Current as App).RootFrame;
                    rootFrame.Navigate(new Uri("/Views/NetworkError.xaml", UriKind.Relative));
                }
            }
            catch (Exception exception)
            {
                if (Debugger.IsAttached)
                {
                    Debug.WriteLine("CategoryPageViewModel:" + exception);
                }
            }
        }