Пример #1
0
 static void Main(String[] args)
 {
     ChickenFarm chicken = new ChickenFarm();
     Thread farmer = new Thread(new ThreadStart(chicken.farmerFunc));
     farmer.Start();
     Retailer chickenstore = new Retailer();
     ChickenFarm.priceCut += new priceCutEvent(chickenstore.chickenOnSale);
     Thread[] retailers = new Thread[5];
     for (int i = 0; i < 3; i++)
     {
         retailers[i] = new Thread(new ThreadStart(chickenstore.retailerFunc));
         retailers[i].Name = (i + 1).ToString();
         retailers[i].Start();
     }
 }
Пример #2
0
 /// <summary>
 /// Attach retailer.
 /// </summary>
 /// <param name="retailer">
 /// The retailer.
 /// </param>
 public void AttachRetailer(Retailer retailer)
 {
 }
Пример #3
0
 /// <summary>
 /// Remove retailer by id.
 /// </summary>
 /// <param name="retailerId">
 /// The retailer id.
 /// </param>
 public void Remove(int retailerId)
 {
     var retailer = new Retailer { Id = retailerId };
     this.context.Entry(retailer).State = EntityState.Deleted;
 }
Пример #4
0
 /// <summary>
 /// Find or add retailer.
 /// </summary>
 /// <param name="retailer">
 /// The retailer.
 /// </param>
 /// <returns>
 /// Retailer that was found or added.
 /// </returns>
 public Retailer FindOrAdd(Retailer retailer)
 {
     return this.context.Retailers.SingleOrDefault(r => r.Url == retailer.Url) 
         ?? this.context.Retailers.SingleOrDefault(r => r.Name == retailer.Name)
         ?? this.context.Retailers.Add(retailer);
 }
 /// <summary>
 /// Find or add retailer.
 /// </summary>
 /// <param name="retailer">
 /// The retailer.
 /// </param>
 /// <returns>
 /// Retailer that was found or added.
 /// </returns>
 public Retailer FindOrAdd(Retailer retailer)
 {
     retailer.Id = 1;
     return retailer;
 }
Пример #6
0
        /// <summary>
        /// Add new order.
        /// </summary>
        /// <param name="request">
        /// The add new order request.
        /// </param>
        /// <returns>
        /// The add order response.
        /// </returns>
        public AddOrderResponse AddOrder(AddOrderRequest request)
        {
            var retailer = new Retailer(request.RetailerUrl);
            var newOrder = new Order(OrderStatus.New) { CreatedDate = DateTime.UtcNow, Retailer = retailer };
            var response = new AddOrderResponse { BrokenRules = retailer.GetBrokenRules().ToList() };
            response.BrokenRules.AddRange(newOrder.GetBrokenRules().ToList());
            if (response.BrokenRules.Any())
            {
                response.MessageType = MessageType.Warning;
                return response;
            }

            try
            {
                var orderResult = this.orderRepository.AddOrder(request.IdentityToken, newOrder);
               
                response = orderResult.ConvertToAddOrderResponse();
                response.Message = CommonResources.OrderAddSuccessMessage;
            }
            catch (Exception ex)
            {
                response.MessageType = MessageType.Error;
                response.ErrorCode = ex.Message;
                this.Logger.Error(CommonResources.OrderAddErrorMessage, ex);
            }

            return response;
        }
Пример #7
0
        public static void GetProductHistogram()
        {
            ShopStyle api = new ShopStyle("uid8409-24047347-36", ShopStyle.UK_API_HOSTNAME);

            CatalogDataContext dc = new CatalogDataContext();
            SS_Category ssCat = dc.SS_Categories.FirstOrDefault<SS_Category>(c => c.cat_id == "jackets");
            SS_Brand ssBrand = dc.SS_Brands.FirstOrDefault<SS_Brand>(b => b.brand_id == 870);
            SS_Retailer ssRetailer = dc.SS_Retailers.FirstOrDefault<SS_Retailer>(r => r.retailer_id == 274);

            ProductQuery query = new ProductQuery().withCategory("jackets");
            Category cat = new Category(ssCat.cat_id, ssCat.name, ssCat.parentid);
            Brand brand = new Brand(ssBrand.brand_id,ssBrand.brand_name,ssBrand.url);
            Retailer retailer = new Retailer(ssRetailer.retailer_id,ssRetailer.name,ssRetailer.url,true);

            query.withCategory(cat); // Category jackets
            //query.withFilter(brand); // Brand filter id
            //query.withFilter(retailer);// Retailer filter id

            //SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            //java.util.Date parsed = format.parse("20130810");
            //java.sql.Date pdd = new java.sql.Date(parsed.getTime());

            //query.withPriceDropDate(pdd);

            ProductHistogramResponse response = api.getProductsHistogram(query,typeof(Price),typeof(Discount));

            PriceHistogramEntry[] arrPriHisEntry = response.getPriceHistogram();
        }
Пример #8
0
            static void Main(string[] args)
            {
                ChickenFarm chicken = new ChickenFarm(); //caller is in the chickenFarmer, but function resides in the Retailer
                Thread farmer = new Thread(new ThreadStart(chicken.farmerFunc)); 
                farmer.Start();	// Start one farmer thread 

                Retailer chickenstore = new Retailer(); 
                ChickenFarm.priceCut += new priceCutEvent(chickenstore.chickenOnSale); 
                //registers the chickOnSale() method (event handler in all the Retailers 
                //  to the priceCut event in the ChickenFarm thread
                //Since priceCut event is defined as a delegate, that can call all the 
                //  subscribed event handlers when the event occurs
                //The changePrice() method searches if there is a subscriber by priceCut!=NULL
                
                //eventhandler is only used when an event happens (or there is a price change)
 
                Thread[] retailers = new Thread[3];
                for (int i = 0; i < 3; i++) //N= 3here  //creates stores 1,2,3
                {	// Start N retailer threads

                    retailers[i] = new Thread(new ThreadStart(chickenstore.retailerFunc));
                    retailers[i].Name = (i + 1).ToString(); //makes names for retailers(Threads)
                    retailers[i].Start(); //start thread
            }
        }