Ejemplo n.º 1
0
        public static async Task Run(
            [QueueTrigger(QueueName.ListenInitialize)] string command,

            [Table(TableName.Meetup)] CloudTable meetupTable,

            [Queue(QueueName.CollectMeetupPage)] CloudQueue meetupQueue,
            [Queue(QueueName.CollectCalendarPage)] CloudQueue calendarQueue,
            [Queue(QueueName.CollectHomePage)] CloudQueue homepageQueue)
        {
            var meetupService = new MeetupService(meetupTable);

            var collectMeetupService   = new CommandQueueService(meetupQueue);
            var collectCalendarService = new CommandQueueService(calendarQueue);
            var collectHomepageService = new CommandQueueService(homepageQueue);

            var meetups = await meetupService.GetMeetupsAsync();

            foreach (var meetup in meetups)
            {
                await collectMeetupService.SubmitCommandAsync(new CollectMeetupPageData
                {
                    Id = meetup.Id
                });
            }

            await collectCalendarService.SubmitCommandAsync(new CollectCalendarPageData());

            await collectHomepageService.SubmitCommandAsync(new CollectHomePageData());
        }
Ejemplo n.º 2
0
        public static async Task Run(
            [TimerTrigger("0 1 0 * * *")] TimerInfo myTimer,

            [Table(TableName.Meetup)] CloudTable meetupTable,

            [Queue(QueueName.CollectMeetupPage)] CloudQueue meetupQueue,

            ILogger log)
        {
            var meetupService  = new MeetupService(meetupTable);
            var meetupCommands = new CommandQueueService(meetupQueue);

            var meetups = await meetupService.GetMeetupsForDateAsync(myTimer.ScheduleStatus.Last);

            foreach (var meetup in meetups)
            {
                var delay = TimeSpan
                            .FromHours(meetup.TimeStartHours)
                            .Add(TimeSpan.FromMinutes(meetup.TimeStartMinutes))
                            .Subtract(TimeSpan.FromMinutes(10));

                var payload = new CollectMeetupPageData
                {
                    Id = meetup.Id
                };

                await meetupCommands.SubmitCommandAsync(payload, delay);
            }
        }
Ejemplo n.º 3
0
        public static async Task Run(
            [QueueTrigger(QueueName.RenderPage)] RenderPage command,

            [Blob(ContainerName.PageTemplate + "/{" + nameof(RenderPage.TemplateId) + "}", FileAccess.Read)] CloudBlockBlob pageTemplateBlob,
            [Blob(ContainerName.PageData + "/{" + nameof(RenderPage.DataInstanceId) + "}", FileAccess.ReadWrite)] CloudBlockBlob pageDataBlob,

            [Blob(ContainerName.WebHost + "/{" + nameof(RenderPage.PublicUrl) + "}", FileAccess.Write)] CloudBlockBlob pageHtmlBlob,
            [Queue(QueueName.CopyBlob)] CloudQueue copyQueue,

            ILogger log)
        {
            log.LogInformation(JsonConvert.SerializeObject(command));

            var copyQueueService = new CommandQueueService(copyQueue);

            var pageData     = JsonConvert.DeserializeObject(await pageDataBlob.DownloadTextAsync());
            var pageTemplate = await pageTemplateBlob.DownloadTextAsync();

            var html = Render.StringToString(pageTemplate, pageData, new RenderContextBehaviour
            {
                HtmlEncoder = text => text
            });

            var compressor = new HtmlCompressor();

            compressor.setEnabled(true);
            compressor.setRemoveComments(true);
            compressor.setRemoveMultiSpaces(true);
            compressor.setRemoveIntertagSpaces(true);

            html = compressor.compress(html);

            await pageHtmlBlob.UploadTextAsync(html);

            pageHtmlBlob.Properties.ContentType = "text/html";
            await pageHtmlBlob.SetPropertiesAsync();

            var copyCommand = new CopyBlob
            {
                Path = command.PublicUrl
            };

            await Task.WhenAll(
                pageDataBlob.DeleteAsync(),
                copyQueueService.SubmitCommandAsync(copyCommand)
                );
        }
Ejemplo n.º 4
0
        public static async Task Run(
            [QueueTrigger(QueueName.CollectCalendarPage)] CollectCalendarPageData command,

            [Table(TableName.Meetup)] CloudTable meetupTable,
            [Table(TableName.MeetupSession)] CloudTable meetupSessionTable,
            [Table(TableName.Session)] CloudTable sessionTable,
            [Table(TableName.Speaker)] CloudTable speakerTable,
            [Table(TableName.Venue)] CloudTable venueTable,

            [Blob(ContainerName.PageData + PageDataBlobUrl, FileAccess.Write)] CloudBlockBlob calendarPageDataBlob,
            [Queue(QueueName.RenderPage)] CloudQueue renderQueue,

            ILogger log)
        {
            var meetupService        = new MeetupService(meetupTable);
            var venueService         = new VenueService(venueTable);
            var meetupSessionService = new MeetupSessionService(meetupSessionTable);
            var sessionService       = new SessionService(sessionTable);
            var speakerService       = new SpeakerService(speakerTable);

            var renderService = new CommandQueueService(renderQueue);


            var calendarPageModel = new CalendarPage();

            var meetups = (await meetupService.GetMeetupsAsync())
                          .GroupBy(x => x.Year, (key, elements) => new
            {
                year    = key,
                meetups = elements
                          .OrderBy(x => x.Year)
                          .ThenBy(x => x.Month)
                          .ThenBy(x => x.Day)
            })
                          .OrderBy(x => x.year)
                          .ToDictionary(x => x.year, element => element.meetups);

            var meetupSessions = await meetupSessionService.GetMeetupSessionsAsync();

            var sessions = await sessionService.GetSessionsAsync();

            var speakers = await speakerService.GetSpeakersAsync();

            var venues = await venueService.GetVenuesAsync();

            calendarPageModel.Years         = meetups.Keys.ToArray();
            calendarPageModel.CalendarYears = meetups.Values.Select(x =>
            {
                var calendarYear = new CalendarYear();

                calendarYear.Year    = x.First().Year;
                calendarYear.Meetups = x.Select(y =>
                {
                    var meetupPage = new MeetupPage();

                    meetupPage.Meetup = y;

                    meetupPage.Venue = venues
                                       .Single(z => z.Id == meetupPage.Meetup.VenueId);

                    meetupPage.Sessions = meetupSessions
                                          .Where(z => z.MeetupId == meetupPage.Meetup.Id)
                                          .OrderBy(z => z.OrderN)
                                          .Select(z =>
                    {
                        var agenda = new MeetupAgenda();

                        agenda.MeetupSession = z;

                        agenda.Session = sessions
                                         .Single(q => q.Id == agenda.MeetupSession.SessionId);

                        agenda.Speaker = speakers
                                         .Single(q => q.Id == agenda.Session.SpeakerId);

                        return(agenda);
                    })
                                          .ToArray();

                    return(meetupPage);
                })
                                       .ToArray();

                return(calendarYear);
            })
                                              .ToArray();


            await calendarPageDataBlob.UploadTextAsync(JsonConvert.SerializeObject(calendarPageModel));

            var renderCommand = new RenderPage
            {
                DataInstanceId = command.DataInstanceId,
                PublicUrl      = calendarPageModel.PublicUrl,
                TemplateId     = CalendarPage.TemplateId
            };
            await renderService.SubmitCommandAsync(renderCommand);
        }
Ejemplo n.º 5
0
        public static async Task Run(
            [QueueTrigger(QueueName.CollectHomePage)] CollectHomePageData command,

            [Table(TableName.Meetup)] CloudTable meetupTable,
            [Table(TableName.MeetupSession)] CloudTable meetupSessionTable,
            [Table(TableName.Session)] CloudTable sessionTable,
            [Table(TableName.Speaker)] CloudTable speakerTable,
            [Table(TableName.Venue)] CloudTable venueTable,
            [Table(TableName.Partner)] CloudTable partnerTable,

            [Blob(ContainerName.PageData + "/index.json", FileAccess.Write)] CloudBlockBlob homePageDataBlob,
            [Queue(QueueName.RenderPage)] CloudQueue renderQueue,

            ILogger log)
        {
            var meetupService        = new MeetupService(meetupTable);
            var venueService         = new VenueService(venueTable);
            var meetupSessionService = new MeetupSessionService(meetupSessionTable);
            var sessionService       = new SessionService(sessionTable);
            var speakerService       = new SpeakerService(speakerTable);
            var partnerService       = new PartnerService(partnerTable);

            var renderService = new CommandQueueService(renderQueue);


            var homePageModel = new HomePage();

            var date    = DateTime.UtcNow.AddHours(TimeZoneOffset);
            var meetups = (await meetupService.GetMeetupsUpcomingAsync(TopMeetups, date))
                          .OrderBy(x => x.Year)
                          .ThenBy(x => x.Month)
                          .ThenBy(x => x.Day);

            var venues = await venueService.GetVenuesByIdsAsync(meetups.Select(x => x.VenueId));

            var agendaItems = await meetupSessionService.GetMeetupSessionsByMeetupIdsAsync(meetups.Select(x => x.Id));

            var sessions = await sessionService.GetSessionsByIdsAsync(agendaItems.Select(x => x.SessionId));

            var speakers = await speakerService.GetSpeakersByIdsAsync(sessions.Select(x => x.SpeakerId));

            var meetupPages = new List <MeetupPage>();

            foreach (var meetup in meetups)
            {
                var meetupPage = new MeetupPage();
                meetupPages.Add(meetupPage);

                meetupPage.Meetup = meetup;

                meetupPage.Registration = new MeetupRegistration
                {
                    IsOpened = true,
                    Url      = null
                };

                meetupPage.Venue = venues.Single(x => x.Id == meetup.VenueId);

                var agenda = agendaItems
                             .Where(x => x.MeetupId == meetup.Id)
                             .Select(a =>
                {
                    var y = new MeetupAgenda
                    {
                        MeetupSession = a,
                        Session       = sessions.Single(x => x.Id == a.SessionId)
                    };

                    y.Speaker = speakers.Single(x => x.Id == y.Session.SpeakerId);

                    return(y);
                });

                meetupPage.Sessions = agenda.ToArray();

                meetupPage.Partners = new IPartner[0];
            }

            homePageModel.Meetups = meetupPages.ToArray();

            homePageModel.Speakers = (await speakerService.GetSpeakersHighlightedAsync())
                                     .ToArray();

            homePageModel.Partners = (await partnerService.GetPartnersHighlightedAsync())
                                     .ToArray();

            await homePageDataBlob.UploadTextAsync(JsonConvert.SerializeObject(homePageModel));

            var renderCommand = new RenderPage
            {
                DataInstanceId = command.DataInstanceId,
                PublicUrl      = homePageModel.PublicUrl,
                TemplateId     = HomePage.TemplateId
            };
            await renderService.SubmitCommandAsync(renderCommand);
        }
Ejemplo n.º 6
0
        public static async Task Run(
            [QueueTrigger(QueueName.CollectMeetupPage)] CollectMeetupPageData command,

            [Table(TableName.Meetup)] CloudTable meetupTable,
            [Table(TableName.MeetupSession)] CloudTable meetupSessionTable,
            [Table(TableName.Session)] CloudTable sessionTable,
            [Table(TableName.MeetupSessionMaterial)] CloudTable sessionMaterialTable,
            [Table(TableName.Speaker)] CloudTable speakerTable,
            [Table(TableName.Venue)] CloudTable venueTable,

            [Blob(ContainerName.PageData + PageDataBlobUrl, FileAccess.Write)] CloudBlockBlob meetupPageDataBlob,
            [Queue(QueueName.RenderPage)] CloudQueue renderQueue,

            ILogger log)
        {
            var meetupService                = new MeetupService(meetupTable);
            var venueService                 = new VenueService(venueTable);
            var meetupSessionService         = new MeetupSessionService(meetupSessionTable);
            var meetupSessionMaterialService = new MeetupSessionMaterialService(sessionMaterialTable);
            var sessionService               = new SessionService(sessionTable);
            var speakerService               = new SpeakerService(speakerTable);

            var renderService = new CommandQueueService(renderQueue);

            var meetupPageViewModel = new MeetupPage();

            meetupPageViewModel.Meetup = await meetupService.GetMeetupByIdAsync(command.MeetupId);

            meetupPageViewModel.Venue = await venueService.GetVenueByIdAsync(meetupPageViewModel.Meetup.VenueId);

            var openedMeetups = new List <string>
            {
                //Guid.Parse("059b6187352c4b718e5626e56f6d84a1").ToString("N")
            };

            meetupPageViewModel.Registration = new MeetupRegistration
            {
                IsOpened = openedMeetups.Contains(command.MeetupId),
                Url      = null
            };

            var meetupAgendaItems = await meetupSessionService.GetMeetupSessionsByMeetupIdAsync(meetupPageViewModel.Meetup.Id);

            var sessions = await sessionService.GetSessionsByIdsAsync(meetupAgendaItems.Select(x => x.SessionId));

            var speakers = await speakerService.GetSpeakersByIdsAsync(sessions.Select(x => x.SpeakerId));

            var materials = await meetupSessionMaterialService.GetMeetupSessionsMaterialsByMeetupIdAsync(command.MeetupId);

            meetupPageViewModel.Sessions = meetupAgendaItems.Select(x =>
            {
                var agenda = new MeetupAgenda
                {
                    MeetupSession = x,
                    Session       = sessions.Single(s => s.Id == x.SessionId),
                    Materials     = materials.Where(m => m.SessionId == x.SessionId).ToArray()
                };

                agenda.Speaker = speakers.Single(s => s.Id == agenda.Session.SpeakerId);

                return(agenda);
            }).ToArray();

            meetupPageViewModel.Partners = new IPartner[0];

            await meetupPageDataBlob.UploadTextAsync(JsonConvert.SerializeObject(meetupPageViewModel));

            var renderCommand = new RenderPage
            {
                DataInstanceId = command.DataInstanceId,
                PublicUrl      = meetupPageViewModel.PublicUrl,
                TemplateId     = MeetupPage.TemplateId
            };
            await renderService.SubmitCommandAsync(renderCommand);
        }