示例#1
0
        public async Task Publish(List <CalenderViewModel> x, IEnumerable <EventViewModel> thisweek)
        {
            var rootUri = ConfigurationManager.AppSettings.Get("FirebaseUri");
            var secret  = ConfigurationManager.AppSettings.Get("FirebaseUserToken");
            var fb      = new FirebaseSharp.Portable.Firebase(rootUri, secret);

            await fb.DeleteAsync("/events");

            await fb.DeleteAsync("/thisweek");

            var taskOfEvents   = x.OrderBy(s => s.Name).Select(item => fb.PostAsync("/events", JsonConvert.SerializeObject(item)));
            var taskOfThisWeek = thisweek.EmptyIfNull().Where(s => s != null).OrderBy(s => s.Start).Select(item => fb.PostAsync("/thisweek", JsonConvert.SerializeObject(item)));
            await Task.WhenAll(taskOfEvents);

            await Task.WhenAll(taskOfThisWeek);
        }
示例#2
0
        public async Task <bool> Publish()
        {
            var sites    = (await GetCalendarList()).Items;
            var thisweek = new List <EventViewModel>();
            var tasks    = sites.Select(async s =>
            {
                var events             = await GetEvents(s.Id, false);
                MetaDataViewModel meta = null;
                try
                {
                    meta = JsonConvert.DeserializeObject <MetaDataViewModel>(s.Description);
                }
                catch (Exception exp)
                {
                }

                var list = new List <EventViewModel>();
                var cal  = new CalenderViewModel
                {
                    Id          = s.Id,
                    Name        = s.Summary,
                    Description = s.Description,
                    MetaData    = meta,
                    Location    = s.Location,
                    Items       = events.Items.Select(ev =>
                    {
                        var evModel = new EventViewModel
                        {
                            CalendarId   = s.Id,
                            CalendarName = s.Summary,
                            Start        = ev.Start.DateTime ?? Convert.ToDateTime(ev.Start.Date),
                            Title        = ev.Summary,
                            Description  = ev.Description,
                            Location     = s.Location,
                            Time         = meta != null ? meta.Time : string.Empty,
                            Region       = meta.Region
                        };
                        try
                        {
                            var json         = JsonConvert.DeserializeObject <Dictionary <string, string> >(ev.Description);
                            evModel.Preblast = json.ContainsKey("preblast") ? json["preblast"] : null;
                            evModel.Tag      = json.ContainsKey("tag") ? json["tag"] : null;
                        }
                        catch (Exception exp)
                        {
                        }

                        return(evModel);
                    }).AsEnumerable()
                };
                thisweek.AddRange(isThisWeek(cal));

                return(cal);
            });

            var x = await Task.WhenAll(tasks);

            var rootUri = ConfigurationManager.AppSettings.Get("FirebaseUri");
            var secret  = ConfigurationManager.AppSettings.Get("FirebaseUserToken");
            var fb      = new FirebaseSharp.Portable.Firebase(rootUri, secret);

            await fb.DeleteAsync("/events");

            await fb.DeleteAsync("/thisweek");

            var taskOfEvents   = x.OrderBy(s => s.Name).Select(item => fb.PostAsync("/events", JsonConvert.SerializeObject(item)));
            var taskOfThisWeek = thisweek.EmptyIfNull().Where(s => s != null).OrderBy(s => s.Start).Select(item => fb.PostAsync("/thisweek", JsonConvert.SerializeObject(item)));
            await Task.WhenAll(taskOfEvents);

            await Task.WhenAll(taskOfThisWeek);

            return(true);
        }