Ejemplo n.º 1
0
        public void RunOnce()
        {
            int sleep;

            // Get one Shipment from the queue
            XmlElement xeShipment = null;
            Random     r          = new Random((int)DateTime.Now.Ticks / int.Parse(Thread.CurrentThread.Name));

            while (true)
            {
                sleep = r.Next(Global.ShipmentAppMinSleepTime, Global.ShipmentAppMaxSleepTime);
                Thread.Sleep(sleep);

                lock (ShipPackages)
                {
                    if (0 == ShipPackages.Count)
                    {
                        continue;
                    }
                    xeShipment = (XmlElement)ShipPackages.Dequeue();
                }
                if (null != xeShipment)
                {
                    break;
                }
            }
            string shipID  = xeShipment.GetAttribute("ShipmentID");
            string carrier = Global.ShipmentCarriers[r.Next(Global.ShipmentCarriers.Length)];

            xeShipment.SetAttribute("Carrier", carrier);

            Console.WriteLine("Shipping package " + shipID + " via " + carrier);
#if Interceptor
            BAMInterceptor interceptor = Global.LoadInterceptor("Shipment_interceptor.bin");
            interceptor.OnStep(Global.dataExtractor, "locShipped", xeShipment, Global.es);
#else
            Global.es.UpdateActivity("BAMApiPo", shipID, "Shipped", DateTime.UtcNow);
#endif

            // Simulate delay for Shipment
            sleep = r.Next(Global.ShipmentMinTime, Global.ShipmentMaxTime);
            Thread.Sleep(sleep);

            Console.WriteLine("Package " + xeShipment.GetAttribute("ShipmentID") + " was delivered");
#if Interceptor
            interceptor.OnStep(Global.dataExtractor, "locDelivered", xeShipment, Global.es);
#else
            Global.es.UpdateActivity("BAMApiPo", shipID, "Delivered", DateTime.UtcNow);
            Global.es.EndActivity("BAMApiPo", shipID);
#endif
        }
Ejemplo n.º 2
0
        public void RunOnce()
        {
            int         sleep;
            int         invoiceNum;
            int         total     = 0;
            string      polist    = "";
            XmlDocument xdInvoice = new XmlDocument();

            xdInvoice.LoadXml("<Invoice/>");
            XmlElement xeInvoice = xdInvoice.DocumentElement;

            invoiceNum = ms_InvoiceCounter++;
            xeInvoice.SetAttribute("InvoiceID", invoiceNum.ToString());

            Random r = new Random((int)DateTime.Now.Ticks / int.Parse(Thread.CurrentThread.Name));

            sleep = r.Next(Global.InvoiceAppMinSleepTime, Global.InvoiceAppMaxSleepTime);
            Thread.Sleep(sleep);
#if Interceptor
            BAMInterceptor interceptor = Global.LoadInterceptor("BAMApiInvoice_interceptor.bin");
            interceptor.OnStep(Global.dataExtractor, "locNewInvoice", xeInvoice, Global.es);
#else
            Global.es.BeginActivity("BAMApiInvoice", invoiceNum.ToString());
#endif

            lock (PosToInvoice)
            {
                if (PosToInvoice.Count < Global.InvoicePoMinCount)
                {
                    return;
                }

                while (PosToInvoice.Count > 0)
                {
                    XmlElement xePo    = (XmlElement)PosToInvoice.Dequeue();
                    string     poid    = xePo.GetAttribute("PoID");
                    XmlElement xePoRef = xdInvoice.CreateElement("PoRef");
                    xePoRef.SetAttribute("PoID", poid);
                    xeInvoice.AppendChild(xePoRef);

                    int amount = int.Parse(xePo.SelectSingleNode("Price").InnerText);
                    total  += amount;
                    polist += poid + " ";

#if Interceptor
                    interceptor.OnStep(Global.dataExtractor, "locAddPoToInvoice", xeInvoice, Global.es);
#else
                    Global.es.AddRelatedActivity(
                        "BAMApiInvoice", invoiceNum.ToString(),
                        "BAMApiPo", poid.ToString());
#endif
                }
            }
            xeInvoice.SetAttribute("Total", total.ToString());
            Console.WriteLine("Invoice #" + invoiceNum + " send for { " + polist + "}");

#if Interceptor
            interceptor.OnStep(Global.dataExtractor, "locSendInvoice", xeInvoice, Global.es);
#else
            Global.es.UpdateActivity("BAMApiInvoice", invoiceNum.ToString(),
                                     "Send", DateTime.UtcNow,
                                     "Total", xeInvoice.GetAttribute("Total"));
#endif
            // Simulate delay for Invoice
            sleep = r.Next(Global.InvoiceWaitMinTime, Global.InvoiceWaitMaxTime);
            Thread.Sleep(sleep);
            Console.WriteLine("Invoice " + invoiceNum + " was paid");
#if Interceptor
            interceptor.OnStep(Global.dataExtractor, "locInvoicePaid", xeInvoice, Global.es);
#else
            Global.es.UpdateActivity("BAMApiInvoice", invoiceNum.ToString(), "Paid", DateTime.UtcNow);
            Global.es.EndActivity("BAMApiInvoice", invoiceNum.ToString());
#endif
        }
Ejemplo n.º 3
0
        void RunOnce()
        {
            Random r     = new Random((int)DateTime.Now.Ticks / int.Parse(Thread.CurrentThread.Name));
            int    sleep = r.Next(Global.PoAppMinSleepTime, Global.PoAppMaxSleepTime);

            Thread.Sleep(sleep);

            // Generate Random PurchaseOrder as XML message
            int    poid    = ms_poCounter++;
            string sPOxml  = "<PurchaseOrder PoID=\"" + poid.ToString() + "\">\n";
            int    product = r.Next(Global.Products.Length);

            sPOxml += "    <Product>" + Global.Products[product] + "</Product>\n";
            int discount = r.Next(Global.Discounts.Length);

            sPOxml += "    <Discount>" + Global.Discounts[discount] + "</Discount>\n";
            sPOxml += "    <Price>" + Global.Prices[product, discount] + "</Price>\n";
            sPOxml += "    <Address>" + r.Next(10000).ToString() + " " + r.Next(1000).ToString() + " Str</Address>\n";
            sPOxml += "</PurchaseOrder>\n";

            XmlDocument xdPO = new XmlDocument();

            xdPO.LoadXml(sPOxml);
            XmlElement xePO = xdPO.DocumentElement;

            Console.WriteLine("New Purchase Order #" + xePO.GetAttribute("PoID") + " Received.");

#if Interceptor
            BAMInterceptor interceptor = Global.LoadInterceptor("BAMApiPo_interceptor.bin");
            interceptor.OnStep(Global.dataExtractor, "locNewPo", xePO, Global.es);
#else
            Global.es.BeginActivity("BAMApiPo", poid.ToString());
            Global.es.UpdateActivity("BAMApiPo", poid.ToString(),
                                     "Received", DateTime.UtcNow,
                                     "Product", xePO.SelectSingleNode("Product").InnerText,
                                     "Amount", xePO.SelectSingleNode("Price").InnerText);
#endif

            // Random Approval Decision
            sleep = r.Next(Global.ApprovalMinTime, Global.ApprovalMaxTime);
            Thread.Sleep(sleep);

            int approve = r.Next(100);
            if (approve > Global.ApprovalPercent)
            {
                Console.WriteLine(xePO.GetAttribute("PoID") + " was Rejected.");

#if Interceptor
                interceptor.OnStep(Global.dataExtractor, "locRejected", xePO, Global.es);
#else
                Global.es.UpdateActivity("BAMApiPo", poid.ToString(),
                                         "Denied", DateTime.UtcNow);
#endif
                return;
            }
            Console.WriteLine(xePO.GetAttribute("PoID") + " was Approved.");

#if Interceptor
            interceptor.OnStep(Global.dataExtractor, "locApproved", xePO, Global.es);
#else
            Global.es.UpdateActivity("BAMApiPo", poid.ToString(),
                                     "Approved", DateTime.UtcNow);
#endif

            // Put the Package in the queue to be shipped
            sleep = r.Next(Global.PackagingMinTime, Global.PackagingMaxTime);
            Thread.Sleep(sleep);
            int packageNumber = r.Next(poid * 10, (poid + 1) * 10);

            if (Global.ShipmentThreads > 0)
            {
                XmlDocument xdShipment = new XmlDocument();
                string      sShipXml   = "<Shipment ShipmentID=\"pkg#" + packageNumber.ToString() + "\"/>";
                xdShipment.LoadXml(sShipXml);
                XmlElement xeShipment    = xdShipment.DocumentElement;
                XmlElement xeShipAddress = xdShipment.CreateElement("Address");
                XmlElement xePoAddress   = (XmlElement)xePO.SelectSingleNode("Address");
                xeShipAddress.InnerText = xePoAddress.InnerText;
                xeShipment.AppendChild(xeShipAddress);

                lock (ShipmentApplication.ShipPackages)
                {
                    ShipmentApplication.ShipPackages.Enqueue(xeShipment);
                }
            }

            // and register this PO to be included in some invoice
            if (Global.InvoiceThreads > 0)
            {
                InvoiceApplication.PosToInvoice.Enqueue(xePO);
            }

            Console.WriteLine(xePO.GetAttribute("PoID") +
                              " was shipped as pkg#" + packageNumber.ToString());

#if Interceptor
            interceptor.OnStep(Global.dataExtractor, "locPackaged", xePO, Global.es);
#else
            Global.es.UpdateActivity("BAMApiPo", poid.ToString(),
                                     "Packaged", DateTime.UtcNow);
            Global.es.EnableContinuation("BAMApiPo", poid.ToString(), "pkg#" + packageNumber.ToString());
            Global.es.EndActivity("BAMApiPo", poid.ToString());
#endif
        }