コード例 #1
0
        public void threadBody(string sku)
        {
            Random rand = new Random();

            while (true)
            {
                //since this is a simulation, we need to make sure
                //the quantity of parts exists to make this sku
                if (BOM.CanMakeSku(sku))
                {
                    var skuData = BOM.Skus.First(x => x.name == sku);
                    Dictionary <string, string> thisIsMyProperty = new Dictionary <string, string>();
                    thisIsMyProperty.Add("source", "sensor");
                    thisIsMyProperty.Add("sku", sku);
                    int qty = 0;
                    if (skuData.avgYieldPerHour > 0)
                    {
                        qty = (rand.Next(99) < ((float)(skuData.avgYieldPerHour * 100)) / (float)(skuData.productionRatePerHour)) ? 1 : 0;
                    }
                    Message messageToPublish = new Message(qty.ToString(), thisIsMyProperty);

                    this.broker.Publish(messageToPublish);

                    Thread.Sleep(Convert.ToInt32(3600000f / (float)(skuData.productionRatePerHour)));
                }
            }
        }