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;
            }
        }
示例#2
0
        public MySqlContext(DbContextOptions options) : base(options)
        {
            //Database.EnsureDeleted();
            Database.EnsureCreated();

            if (Articles.Count() == 0)
            {
                PutData data = new PutData();

                Articles.AddRange(data.articles);
                Comments.AddRange(data.comments);

                SuperUsers.Add(data.super);
                TeacherUsers.AddRange(data.teacher);
                StudentUsers.AddRange(data.studentUser);
                TestStudents.AddRange(data.testStudents);
                QuestionAnswers.AddRange(data.questionAnswers);
                Tests.AddRange(data.tests);

                Themes.AddRange(data.themes);
                TestThemes.AddRange(data.TestThemas);
                Questions.AddRange(data.questions1);
                Questions.AddRange(data.questions2);
                Questions.AddRange(data.questions3);
                Marks.AddRange(data.Marks1);
                Marks.AddRange(data.Marks2);

                EventProfileUsers.AddRange(data.EventProfileUsers);
                Meetups.AddRange(data.Meetups);
                Speakers.AddRange(data.Speakers);

                SaveChanges();
            }
        }
        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;
            }
        }
 public void AddArticlesThreadsafe(IEnumerable <Article> articles)
 {
     lock (_articleLock){
         if (Articles == null)
         {
             Articles = new List <Article>();
         }
         Articles.AddRange(articles);
     }
 }
 public async void GetClientArticlesAsync()
 {
     if (position == 0)
     {
         Articles.AddRange(await SqliteUtil.Current.QueryArticles(pageSize));
     }
     else if (position == 1)
     {
         Articles.AddRange(await SqliteUtil.Current.QueryArticlesByRecommend(pageSize));
     }
 }
        /// <summary>
        /// Function to fetch saved articles from database
        /// </summary>
        /// <param name="isRefreshing"></param>
        async Task LoadSavedItems(bool isRefreshing = false)
        {
            if (isRefreshing && Articles.Any())
            {
                IsBusy       = false;
                IsRefreshing = true;
            }

            try
            {
                string userId = await Helpers.DatabaseHelper.UserId();

                if (userId != null)
                {
                    CrossCloudFirestore.Current
                    .Instance
                    .GetCollection($"articles/{userId}/saved-articles")
                    .AddSnapshotListener((snapshot, error) =>
                    {
                        if (!snapshot.IsEmpty)
                        {
                            IsEmpty = false;

                            var articles = snapshot.ToObjects <Article>().OrderBy(s => s.SavedOn).Reverse();

                            if (Articles.Any())
                            {
                                Articles.ReplaceRange(articles);
                            }
                            else
                            {
                                Articles.AddRange(articles);
                            }
                        }
                        else
                        {
                            IsEmpty = true;
                        }

                        IsRefreshing = false;
                        IsBusy       = false;
                    });
                }
                else
                {
                    IsBusy = false;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        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;
            }
        }
示例#8
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);
        }
示例#9
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;
            }
        }
示例#10
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;
            }
        }
示例#11
0
        private void GetArticles()
        {
            var listArticles = RestApi.Request <ListArticles>(ApiRequest.Articles).Result;

            this.Articles.AddRange(listArticles.Articles);
            List <String> requestList = new List <string>();

            for (var i = 2; i <= listArticles.PageCount; i++)
            {
                var url = $"?page={i}&per_page=30";
                requestList.Add(url);
            }

            var list = RestApi.MultiplyRequest <ListArticles>(ApiRequest.Articles, requestList).Result;

            foreach (var item in list)
            {
                Articles.AddRange(item.Articles);
            }
        }
示例#12
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;
            }
        }
示例#13
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;
            }
        }
示例#15
0
 public void AddArticles(params Article[] articles) => Articles.AddRange(articles);
示例#16
0
文件: Magazine.cs 项目: dorodon/Cs
 internal void AddArticles(params Article[] articles)
 {
     Articles.AddRange(articles);
 }