Esempio n. 1
0
        public YmlCatalog GetYmlCatalog(string path)
        {
            var tokenSource = new CancellationTokenSource();
            var token = tokenSource.Token;

            YmlCatalog catalog =new YmlCatalog();

            var catalogTask = GetXmlYmlCatalog(path, token);
            catalog = catalogTask.Result;
            
            return catalog;
        }
Esempio n. 2
0
        /// <summary>
        /// Send the offer.
        /// </summary>
        /// <param name="ymlCatalog">The yml catalog.</param>
        /// <param name="offerId">The offer id.</param>
        /// <param name="urlToSend">The URL to send.</param>
        /// <returns>true</returns>
        /// <exception cref="YmlCatalogException">
        /// Yml Catalog is null
        /// or
        /// Other exception.
        /// </exception>
        public bool SendOffer(YmlCatalog ymlCatalog, int offerId, string urlToSend)
        {
            if(ymlCatalog == null)
                throw new YmlCatalogException("Yml Catalog is null.");

            Offer offer = GetOfferById(ymlCatalog, offerId);

            if (offer == null)
                throw new YmlCatalogException(String.Format("No offer with id = {0}.", offerId));

            string offerInJson = new JavaScriptSerializer().Serialize(offer);
            bool sendResult = true;

            var sendResultTask = SendJson(offerInJson, urlToSend);
            sendResult = sendResultTask.Result;

            return sendResult;
        }
Esempio n. 3
0
 public void DisplayYmlCatalog()
 {
     try
     {
         _ymlCatalog = _catalog.GetYmlCatalog(_urlToYml);
         Console.WriteLine("Yml Catalog:");
         Console.WriteLine("Date: {0}", _ymlCatalog.Date);
         Console.WriteLine("Name: {0}", _ymlCatalog.Shop.Name);
         Console.WriteLine("Company: {0}", _ymlCatalog.Shop.Company);
         Console.WriteLine("URL: {0}", _ymlCatalog.Shop.Url);
         Console.WriteLine("Offers count: {0}", _ymlCatalog.Shop.Offers.OfferList.Count);
     }
     catch (AggregateException e)
     {
         e.Handle((x) =>
         {
             if (x is YmlCatalogException)
             {
                 Console.WriteLine("Yml Catalog Exception");
                 Console.WriteLine(e.Message);
                 Console.WriteLine("Please press any key to end the program");
                 Console.ReadKey();
                 Environment.Exit(1);
             }
             else
             {
                 Console.WriteLine("Other Exception");
                 Console.WriteLine(e.Message);
                 Console.WriteLine("Please press any key to end the program");
                 Console.ReadKey();
                 Environment.Exit(1);
             }
             return true;
         });
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Gets the offer by id.
 /// </summary>
 /// <param name="ymlCatalog">The yml catalog.</param>
 /// <param name="offerId">The offer id.</param>
 /// <returns>Offer by id.</returns>
 private Offer GetOfferById(YmlCatalog ymlCatalog,int offerId)
 {
     return ymlCatalog.Shop.Offers.OfferList.FirstOrDefault(item => item.Id == offerId);
 }