Beispiel #1
0
        /// <summary>
        /// Loads schedule data from the web and parses it into objects.
        /// </summary>
        private static void LoadAndParseData()
        {
            // Get the artist list.
            HtmlDocument artistsPage = LoadPage(_artistPageUri, "artists");

            // Get links to artists.
            // <a class="artist-cover" href="http://dbfestival.com/artists/?.."></a>
            foreach (HtmlNode artistLink in artistsPage.DocumentNode.SelectNodes("//a[@class='artist-cover']"))
            {
                Uri artistPageUri = new Uri(artistLink.Attributes["href"].Value);
                string artistId = artistPageUri.Query.Substring(1);
                HtmlDocument artistPage = LoadPage(artistPageUri, string.Format("artist-{0}", artistId));

                Artist artist = null;
                try
                {
                    artist = new Artist(artistPageUri, artistPage);
                }
                catch
                {
                    continue;
                }

                _artists.Add(artist);
                LoadImage(artist.ImageUri, artist.ImageFileName);
            }

            // Get the showcases list.
            HtmlDocument showcasesPage = LoadPage(_showcasesPageUri, "showcases");

            // Get links to showcases.
            // <a href="http://dbfestival.com/showcase/?..." class="span4 performance-list-event content-margin">
            foreach (HtmlNode showcaseLink in showcasesPage.DocumentNode.SelectNodes("//a[@class='span4 performance-list-event content-margin']"))
            {
                Uri showcasePageUri = new Uri(showcaseLink.Attributes["href"].Value);
                if (_showcases.Any(s => s.ShowcaseLink == showcasePageUri.OriginalString))
                {
                    // One showcase is listed twice by mistake.
                    continue;
                }

                string showcaseId = showcasePageUri.Query.Substring(1);
                HtmlDocument showcasePage = LoadPage(showcasePageUri, string.Format("showcase-{0}", showcaseId));
                Showcase showcase = new Showcase(showcasePageUri, showcasePage);
                _showcases.Add(showcase);

                // Get links to artists in the showcase.
                // <a href="http://dbfestival.com/artists/?..." class="span4 performance-artist">
                HtmlNodeCollection artistLinkNodes = showcasePage.DocumentNode.SelectNodes("//a[@class='span4 performance-artist']");
                if (artistLinkNodes == null)
                {
                    continue;
                }

                List<HtmlNode> artistLinks = artistLinkNodes.Reverse().ToList();
                foreach (HtmlNode artistLink in artistLinks)
                {
                    string id = new Uri(artistLink.Attributes["href"].Value).Query.Substring(1);
                    Artist artist = _artists.FirstOrDefault(a => a.Id == id);
                    if (artist == null)
                    {
                        continue;
                    }

                    Performance performance = new Performance(showcase, artist, artistLink, artistLinks.Count, artistLinks.IndexOf(artistLink));
                    showcase.Performances.Add(performance);
                    _performances.Add(performance);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Performance"/> class.
        /// </summary>
        /// <param name="showcase">The showcase.</param>
        /// <param name="artist">The artist.</param>
        /// <param name="artistLink">The artist link.</param>
        /// <param name="artistsInShowcase">The number of artists in the showcase.</param>
        /// <param name="showcasePosition">The position of this artist in the showcase.</param>
        public Performance(Showcase showcase, Artist artist, HtmlNode artistLink, int artistsInShowcase, int showcasePosition)
        {
            Showcase = showcase;
            Artist = artist;

            // <span class="performance-artist-content-description">...</span>
            PerformanceType = artistLink.SelectSingleNode("div/span[@class='performance-artist-content-description']").InnerText;

            // <span class="performance-artist-content-time">7:40 PM - 8:30 PM</span>
            HtmlNode node = artistLink.SelectSingleNode("div/span[@class='performance-artist-content-time']");
            if (node != null)
            {
                string time = node.InnerText;

                DateTime startTime = DateTime.ParseExact(time.Split(new char[] { '-' }).First().Trim(), "h:mm tt", CultureInfo.InvariantCulture);
                StartTime = new DateTime(Showcase.Doors.Year, Showcase.Doors.Month, Showcase.Doors.Day, startTime.Hour, startTime.Minute, 0);
                if (StartTime.Hour < 12)
                {
                    StartTime = StartTime.AddDays(1);
                }

                DateTime endTime = DateTime.ParseExact(time.Split(new char[] { '-' }).Last().Trim(), "h:mm tt", CultureInfo.InvariantCulture);
                EndTime = new DateTime(Showcase.Doors.Year, Showcase.Doors.Month, Showcase.Doors.Day, endTime.Hour, endTime.Minute, 0);
                if (EndTime.Hour < 12)
                {
                    EndTime = EndTime.AddDays(1);
                }
            }

            // Sometimes set times aren't posted, so let's estimate them.
            if (StartTime == DateTime.MinValue && EndTime == DateTime.MinValue)
            {
                DateTime showcaseStartTime = showcase.Doors;
                DateTime showcaseEndTime = showcaseStartTime.AddHours(6);
                TimeSpan showcaseLength = TimeSpan.FromHours(artistsInShowcase);

                if (showcase.Venue.ToLower().Contains("islander"))
                {
                    // For boat parties, shows start an hour after doors, the show ends at 6pm, and there are always two acts at once.
                    showcaseStartTime = showcaseStartTime.AddHours(1);
                    showcaseEndTime = showcaseStartTime.AddHours(4.5);
                    showcaseLength = showcaseEndTime - showcaseStartTime;
                    TimeSpan setLength = TimeSpan.FromMinutes((int)((double)showcaseLength.TotalMinutes / (double)artistsInShowcase / 2));
                    StartTime = showcaseStartTime.AddMinutes(setLength.TotalMinutes * showcasePosition);
                    if (artistsInShowcase > 3)
                    {
                        setLength = TimeSpan.FromMinutes((int)((double)showcaseLength.TotalMinutes / ((double)artistsInShowcase / 2)));
                        StartTime = showcaseStartTime.AddMinutes(setLength.TotalMinutes * (int)Math.Floor((double)showcasePosition / 2.0));
                    }

                    EndTime = StartTime + setLength;
                }
                else if (showcaseStartTime.Hour < 12)
                {
                    // If it's an afterhours, let's assume everyone's playing sets of equal length and we go til 6am.
                    showcaseEndTime = new DateTime(showcaseStartTime.Year, showcaseStartTime.Month, showcaseStartTime.Day, 6, 0, 0);
                    showcaseLength = showcaseEndTime - showcaseStartTime;
                    TimeSpan setLength = TimeSpan.FromMinutes((int)((double)showcaseLength.TotalMinutes / (double)artistsInShowcase));
                    StartTime = showcaseStartTime.AddMinutes(setLength.TotalMinutes * showcasePosition);
                    EndTime = StartTime + setLength;
                }
                else if (showcaseStartTime.Hour <= 12 + 3)
                {
                    // If it's an afternoon event, assume everyone's playing for an hour.
                    showcaseEndTime = showcaseStartTime.AddHours(artistsInShowcase);
                    showcaseLength = TimeSpan.FromHours(artistsInShowcase);
                    TimeSpan setLength = TimeSpan.FromMinutes((int)((double)showcaseLength.TotalMinutes / (double)artistsInShowcase));
                    StartTime = showcaseStartTime.AddMinutes(setLength.TotalMinutes * showcasePosition);
                    EndTime = StartTime + setLength;
                }
                else if (showcaseStartTime.Hour >= 20)
                {
                    // If it's an evening event, assume it ends at 2a and everyone has equal sets.
                    showcaseEndTime = showcaseStartTime.AddDays(1);
                    showcaseEndTime = new DateTime(showcaseEndTime.Year, showcaseEndTime.Month, showcaseEndTime.Day, 2, 0, 0);
                    showcaseLength = showcaseEndTime - showcaseStartTime;
                    TimeSpan setLength = TimeSpan.FromMinutes((int)((double)showcaseLength.TotalMinutes / (double)artistsInShowcase));
                    StartTime = showcaseStartTime.AddMinutes(setLength.TotalMinutes * showcasePosition);
                    EndTime = StartTime + setLength;
                }
                else
                {
                    // Other cases?
                    Debugger.Break();
                }
            }
        }