コード例 #1
0
ファイル: ScheduledAgent.cs プロジェクト: garapani/outlook
        private async Task UpdateAsync()
        {
            try
            {
                //BackgroundWorker bwLatestNews = new BackgroundWorker();
                //bwLatestNews.DoWork += bwLatestNews_DoWork;
                //bwLatestNews.RunWorkerAsync();
                try
                {
                    OutlookClient client   = new OutlookClient();
                    var           articles = await client.GetArticlesAsync(_latestNews);

                    if (articles != null && articles.Count > 0)
                    {
                        articles = articles.OrderByDescending(o => o.ArticleDate).ToList();
                        SaveLatestNews(articles);
                        UpdateNotifications(articles.Count, articles[0]);
                    }
                }
                catch (Exception)
                {
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
ファイル: RegtimeConsole.cs プロジェクト: kalabakas1/MPE
        private List <ValidationResult <RegtimeRegistration> > ExecuteValidateDate(DateTime date = default(DateTime))
        {
            if (date == default(DateTime))
            {
                date = GetDateFromInput();
            }

            var outlookClient = new OutlookClient(_configurationService.Configuration.Username, _configurationService.Configuration.Password);
            var converter     = new CalendarEventConverter(_configurationService.Configuration);

            var events      = outlookClient.GetEvents(_configurationService.Configuration.Calendar, date, date.AddDays(1));
            var validations = converter.ConvertMultipleToRegtimeRegistrations(events);

            if (validations.Any(x => !x.IsValid))
            {
                Console.WriteLine($"Some entries are not valid {date.ToShortDateString()}:");
                foreach (var validationResult in validations.Where(x => !x.IsValid).ToList())
                {
                    Console.WriteLine(validationResult.Message);
                }
            }
            else
            {
                Console.WriteLine("CONGRATS - You are now ready for the registration of time... " + date.ToShortDateString());
                PrintRegistrations(validations.Select(x => x.Object).ToList());
            }
            return(validations);
        }
コード例 #3
0
ファイル: ScheduledAgent.cs プロジェクト: garapani/outlook
        private async void bwLatestNews_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                OutlookClient client   = new OutlookClient();
                var           articles = await client.GetArticlesAsync(_latestNews);

                if (articles != null && articles.Count > 0)
                {
                    articles = articles.OrderByDescending(o => o.ArticleDate).ToList();
                    SaveLatestNews(articles);
                    UpdateNotifications(articles.Count, articles[0]);
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #4
0
 public MockedOutlookEmailClientFactory(IRegistry registry, OutlookClient outlookClient)
     : base(registry)
 {
     _outlookClient = outlookClient;
 }
コード例 #5
0
ファイル: DataService.cs プロジェクト: garapani/outlook
        public async Task <List <Article> > GetArticlesAsync(string categoryName, bool isForce = false)
        {
            List <Article> articles = new List <Article>();

            try
            {
                DateTime presentTime = DateTime.Now;
                bool     refresh     = false;
                Category category    = await DatabaseOperations.GetInstance().GetCategoryDetailAsync(categoryName);

                if (category != null)
                {
                    var diff = DateTime.Now - category.LastUpdated;
                    if (diff.TotalMinutes > 15)
                    {
                        refresh = true;
                    }
                }
                else
                {
                    category = new Category();
                    category.CategoryName = categoryName;
                    category.CategoryUrl  = categoryUrlTemplate + categoryName;
                    await DatabaseOperations.GetInstance().AddCategoryAsync(category);
                }

                var tempCategory = _listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower());
                if (tempCategory != null)
                {
                    if (refresh || isForce)
                    {
                        if (NetworkInterface.GetIsNetworkAvailable())
                        {
                            var oldArticles = await DatabaseOperations.GetInstance().GetCategoryArticlesAsync(categoryName);

                            if (oldArticles != null && oldArticles.Count > 0)
                            {
                                articles.AddRange(oldArticles);
                            }
                            _listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower()).isRrefreshing = true;
                            category.isRrefreshing = true;
                            OutlookClient client         = new OutlookClient();
                            var           latestArticles = await client.GetArticlesAsync(categoryName);

                            if (latestArticles != null && latestArticles.Count > 0)
                            {
                                //articles.AddRange(latestArticles.ToList());
                                foreach (var article in latestArticles)
                                {
                                    if (articles.Find(o => o.HeadLine == article.HeadLine) == null)
                                    {
                                        articles.Add(article);
                                    }
                                    await DatabaseOperations.GetInstance().AddOrUpdateArticleAsync(article);
                                }
                                _listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower()).LastUpdated = DateTime.Now;
                                category.LastUpdated = DateTime.Now;
                            }
                            category.isRrefreshing = false;
                            await DatabaseOperations.GetInstance().UpdateCategoryAsync(category);
                        }
                    }
                    else
                    {
                        var tempArticles = await DatabaseOperations.GetInstance().GetCategoryArticlesAsync(categoryName);

                        if (tempArticles != null && tempArticles.Count > 0)
                        {
                            articles.AddRange(tempArticles);
                        }
                    }
                    if (_listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower()).Articles == null)
                    {
                        _listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower()).Articles = new ObservableCollection <Article>();
                    }
                    else
                    {
                        _listofCategories.Find(o => o.CategoryName.ToLower() == categoryName.ToLower()).Articles.Clear();
                    }
                    articles.OrderByDescending(o => o.ArticleDate).ToList().ForEach(o => _listofCategories.Find(l => l.CategoryName.ToLower() == categoryName.ToLower()).Articles.Add(o));
                }
            }
            catch (Exception)
            {
            }
            return(articles.OrderByDescending(o => o.ArticleDate).ToList());
        }