Beispiel #1
0
        private void SendEmailAsync(Context context, DayOverview dayOverview)
        {
            m_workItemQueue.Enqueue(async cancellationToken =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                var email = await m_amazonService.GetEmailAsync(context).ConfigureAwait(false);
                if (email == null)
                {
                    return;
                }

                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    var subject  = $"Übersicht {dayOverview.Cinema.Name}";
                    var htmlBody = m_dayOverviewEmailFormatter.Format(dayOverview);
                    if (string.IsNullOrEmpty(htmlBody))
                    {
                        return;
                    }

                    await m_emailService.SendEmailOverviewAsync(email, subject, htmlBody).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            });
        }
Beispiel #2
0
        /// <summary>
        /// Gets the day overview for a date
        /// </summary>
        /// <param name="date">The date to return the day information for</param>
        /// <returns>Dashbaord/DayInformation</returns>
        public ActionResult DayInformation(DateTime date)
        {
            //Calculates the frequency, occupancy and utilisation rates for the compnay on the date given
            var model = new DayOverview
            {
                Frequency   = (service.CalculateFrequencyRate(date, date) * 100).ToString("0.##\\%"),
                Occupancy   = (service.CalculateOccupancyRate(date, date) * 100).ToString("0.##\\%"),
                Utilisation = (service.CalculateUtilisationRate(date, date) * 100).ToString("0.##\\%"),
                DayChart    = GenerateDayChart(date, date.DayOfWeek + "Chart"),
                Day         = date.DayOfWeek.ToString(),
                Date        = date,
            };

            //Required for dashbaord panel to track whihc tab is active
            model.DateInformation = new DateInformation
            {
                StartDate = FindStartDate(date),
                ActiveDay = date.DayOfWeek.ToString(),
            };

            return(View(model));
        }
        private DayOverview ParseHtml(string datum, string htmlResult)
        {
            var document = new HtmlDocument();

            document.LoadHtml(htmlResult);

            HtmlNode mainTable = document.DocumentNode.SelectSingleNode("//*[@id=\"ctl00_ContentPlaceHolder1_DetailPrikking1_gvwPrikkingen\"]");
            IEnumerable <string[]> tableData = null;

            try
            {
                tableData = mainTable.Descendants("tr").Select(n => n.Elements("td").Select(e => e.InnerText).ToArray());
            }
            catch (Exception)
            {
                //throw;
            }

            var day = new DayOverview
            {
                Prikkingen = new List <Prikking>(),
                Date       = DateTime.Parse(datum)
            };

            if (tableData != null)
            {
                foreach (var tableRow in tableData)
                {
                    if (!tableRow.Any())
                    {
                        continue;
                    }

                    var prikking = new Prikking
                    {
                        Datum    = DateTime.Parse(datum + RemoveHtmlTags(tableRow[3])),
                        Zone     = RemoveHtmlTags(tableRow[1]),
                        Prikklok = RemoveHtmlTags(tableRow[2])
                    };

                    day.Prikkingen.Add(prikking);
                }

                // make sure timestamps are ordered in the correct way
                day.Prikkingen = day.Prikkingen.OrderBy(x => x.Datum).ToList();

                day.CalculateTotal();

                if (day.Total >= TimeSpan.FromHours(8))
                {
                    day.Completed = true;
                }
            }
            else if (day.Date < DateTime.Now)
            {
                day.Absence = true;
                day.CalculateTotal();
            }

            return(day);
        }
Beispiel #4
0
        private DayOverview ParseDayOverview(Cinema cinema, IEnumerable <Show> shows, DateTime vorstellungsdatum, string vorstellungszeit)
        {
            if (shows == null)
            {
                m_logger.LogError("shows is NULL");
                return(null);
            }

            m_logger.LogDebug("Getting all relevant showtimes");
            var timeNow     = DateTime.UtcNow;
            var showsOnDate = shows.Where(p => p.Beginning.GetDateTime().Date == vorstellungsdatum.Date &&
                                          p.Beginning.GetDateTime() >= timeNow);

            var dayOverview = new DayOverview
            {
                Cinema = cinema,
                Date   = vorstellungsdatum.Date.ToLocalTime()
            };

            m_logger.LogDebug("Generating day overview");
            var filmGroup = showsOnDate.GroupBy(p => p.MovieInfo.Id);

            foreach (var movieGroup in filmGroup)
            {
                var movieInfo = movieGroup.First().MovieInfo;
                var movie     = new Movie
                {
                    Name        = FormatMovieName(movieInfo.Title),
                    Description = movieInfo.Description,
                };
                if (movieInfo.ThumbnailImage != null && movieInfo.ThumbnailImage.Length > 0)
                {
                    movie.ThumbnailUrl = movieInfo.ThumbnailImage[0].Url;
                }

                foreach (var movieVorstellung in movieGroup)
                {
                    var showTime = movieVorstellung.Beginning.GetDateTime().ToLocalTime();
                    if (!string.IsNullOrEmpty(vorstellungszeit))
                    {
                        switch (vorstellungszeit)
                        {
                        case "EV" when showTime.Hour < 18:
                        {
                            continue;
                        }

                        case "AF" when showTime.Hour > 18:
                        {
                            continue;
                        }
                        }
                    }

                    movie.Vorstellungen.Add(
                        new Vorstellung(movieVorstellung.Id, movieVorstellung.Name, showTime.TimeOfDay, movieVorstellung.DetailUrl.AbsoluteUrl));
                }

                if (movie.Vorstellungen.Count == 0)
                {
                    continue;
                }

                dayOverview.Movies.Add(movie);
            }

            m_logger.LogDebug("Parsing done");
            return(dayOverview);
        }