示例#1
0
        /// <summary>
        /// The subscribe to market data.
        /// </summary>
        public void SubscribeToMarketData(IEnumerable <IRawMaterialMarketData> sourceMarketDatas)
        {
            this.marketDatas = sourceMarketDatas;

            // ingredient prices are set at 0
            this.eggPrice       = 0;
            this.flourPrice     = 0;
            this.flavorPrice    = 0;
            this.sizePrice      = null;
            this.packagingPrice = null;
            foreach (var rawMaterialMarketData in this.marketDatas)
            {
                // indentify the argument family, subscribe to it
                // and invalidate the current value.
                var role = RecipeHelper.ParseRawMaterialRole(rawMaterialMarketData.RawMaterialName);
                switch (role)
                {
                case RawMaterialRole.Flour:
                    this.flourPrice = null;
                    rawMaterialMarketData.PriceChanged += this.MarketDataFlourPriceChanged;
                    break;

                case RawMaterialRole.Egg:
                    this.eggPrice = null;
                    rawMaterialMarketData.PriceChanged += this.MarketDataEggPriceChanged;
                    break;

                case RawMaterialRole.Flavor:
                    this.flavorPrice = null;
                    rawMaterialMarketData.PriceChanged += this.MarketDataFlavorPriceChanged;
                    break;

                case RawMaterialRole.Size:
                    this.sizePrice = null;
                    rawMaterialMarketData.PriceChanged += this.MarketDataSizePriceChanged;
                    break;

                case RawMaterialRole.Packaging:
                    this.packagingPrice = null;
                    rawMaterialMarketData.PriceChanged += this.MarketDataPackagingPriceChanged;
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main()
        {
            ThreadPool.SetMinThreads(Environment.ProcessorCount * 2, 0);
            Console.WriteLine("Welcome to the pasta pricer (powered by the Michonne library).");
            Console.WriteLine("Conflation Y/N?");
            var  option            = Console.ReadLine();
            bool conflationEnabled = false;

            if (option.ToUpper().StartsWith("Y"))
            {
                conflationEnabled = true;
                Console.WriteLine("Conflation enabled!\n");
            }
            else
            {
                Console.WriteLine("NO Conflation\n");
            }

            Console.WriteLine("         Type 'Enter' to start market data inputs.");
            Console.WriteLine("         Then type 'Enter' again, to stop market data inputs.");

            Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.DarkGray;

            var publisher = new ConsolePastaPricerPublisher();

            var marketDataProvider = new AggresiveMarketDataProvider(aggressionFactor: 10, timerPeriodInMsec: 1);

            var unitOfExecutionsFactory = new UnitOfExecutionsFactory();

            ThreadPool.SetMaxThreads(Environment.ProcessorCount * 2, 0);
            ThreadPool.SetMinThreads(Environment.ProcessorCount * 2, 0);

            var pastaPricer = new PastaPricerEngine(unitOfExecutionsFactory.GetPool(), RecipeHelper.GenerateConfigurations(), marketDataProvider, publisher, conflationEnabled);

            pastaPricer.Start();

            // Turns on market data
            marketDataProvider.Start();

            Console.ReadLine();

            Console.WriteLine("----------------\nMarket data is stopping.\n----------------\n");

            marketDataProvider.Stop();
            publisher.CountPublish();

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("----------------\nMarket data stopped. Wait a while, and type 'Enter' to exit.\n----------------\n");

            Console.ReadLine();

            Console.WriteLine("{0} late prices have been published since we stopped the market data.", publisher.PublicationCounter);

            Console.WriteLine("Type Enter to exit the program.");

            Console.ReadLine();
        }