Ejemplo n.º 1
0
 public void HandleResult(object sender, object result)
 {
     AvailableTennisSlotsCollection results = (AvailableTennisSlotsCollection)result;
     TennisRepository repository = new TennisRepository();
     foreach (AvailableTennisSlot slot in results)
     {
         repository.SaveAvailableSlot(slot);
     }
 }
Ejemplo n.º 2
0
        public override void Monitor()
        {
            IAuthentifier authentifier = new TennisAuthentifier(Profile);
            WebClient client = authentifier.GetAuthenticatedClient();
            byte[] result = client.UploadValues(SearchUrl, "POST", DefaultPreferences);
            string resultString = Encoding.Default.GetString(result);


            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(resultString);

            if (resultString.Contains(NoResult))
            {
                LogManager.Log("No results");
                return;
            }

            HtmlNodeCollection elements = doc.DocumentNode.SelectNodes("//table[@class='normal']/tbody/tr");

            if (elements == null || elements.Count() == 0)
            {
                throw new HtmlStructureChangedException(Url, "Expected one or more elements matching xpath : //table[@class='normal']/tbody/tr");
            }
            AvailableTennisSlotsCollection tennisSlots = new AvailableTennisSlotsCollection(
                elements
                    .Select(e => ConvertNodeToTennisSlot(e))
                    .Where(
                        s => s.CourtNumber != 8 &&                                  // F**k court 8
                        s.Place == "Jules Ladoumègue" &&                            // F**k this website's encoding
                        s.StartDateTime.DayOfWeek != System.DayOfWeek.Saturday &&   // No tennis on weekends
                        s.StartDateTime.DayOfWeek != System.DayOfWeek.Sunday));     // !

            TennisRepository repository = new TennisRepository();
            tennisSlots.Slots = tennisSlots.Slots.Where(s => !repository.IsAvailableSlotAlreadySent(s.StartDateTime));

            if (tennisSlots.Slots.Count() > 0)
            {
                OnMonitorEnded(tennisSlots);
            }
        }