Ejemplo n.º 1
0
        public static BAMInterceptor LoadInterceptor(string filename)
        {
            string          exe            = Assembly.GetExecutingAssembly().Location;
            string          InterceptorDir = exe.Substring(0, exe.LastIndexOf("\\") + 1);
            Stream          f           = File.Open(InterceptorDir + filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryFormatter bf          = new BinaryFormatter();
            BAMInterceptor  interceptor = (BAMInterceptor)bf.Deserialize(f);

            f.Close();
            return(interceptor);
        }
Ejemplo n.º 2
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
        }
        static void ConfigureInterceptor(string activity, ActivityInterceptorConfiguration config)
        {
            while (true)
            {
                Console.Write("Activity Milestone or Item Name      : ");
                string item = Console.ReadLine();
                if ("" == item)
                {
                    break;
                }

                Console.Write("Get this at what step (location)?    : ");
                string loc = Console.ReadLine();

                Console.Write("From what Xpath? (empty if Milestone): ");
                string xpath = Console.ReadLine();
                config.RegisterDataExtraction(item, loc, xpath);
                Console.WriteLine();
            }

            // Prepare interceptor instance to be used by the Business Implementation
            BAMInterceptor interceptor = new BAMInterceptor();

            config.UpdateInterceptor(interceptor);

            BinaryFormatter bf = new BinaryFormatter();
            Stream          f  = File.Create(activity + "_interceptor.bin");

            bf.Serialize(f, interceptor);
            f.Close();

            // And output the configuration as xml for verification
            XmlSerializer xs = new XmlSerializer(typeof(ActivityInterceptorConfiguration));

            f = File.Create(activity + "_config.xml");
            xs.Serialize(f, config);
            f.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a BAM interceptor for the step.
        /// </summary>
        /// <param name="activityName">BAM activity name</param>
        /// <param name="stepName">The BAM step name.</param>
        /// <param name="policyName">BAM Policy name</param>
        /// <param name="version">BAM Policy version in the format of x.y where x is the major and y is the minor version number</param>
        /// <returns>Return a BAMInterceptor object</returns>
        private BAMInterceptor DoGetBamInterceptor(string activityName, string stepName, string policyName, Version version)
        {
            // TraceHelper.TraceMessage("Resolver.GetInterceptor - In");
            if (this.bamInterceptor != null)
            {
                return(this.bamInterceptor);
            }

            var bamActivityStep = DoGetStep(activityName, stepName, policyName, version);
            var interceptor     = new BAMInterceptor();

            // Because of a logic error in Microsoft's code, a separate ActivityInterceptorConfiguration must be used
            // for each location.  The following code extracts only those track points for a given step name (location).
            var trackPointGroup = from TrackPoint tp in bamActivityStep.TrackPoints
                                  where (string)tp.Location == stepName
                                  select tp;
            var bamActivityInterceptorConfig = new ActivityInterceptorConfiguration(activityName);

            foreach (var trackPoint in trackPointGroup)
            {
                switch (trackPoint.Type)
                {
                case TrackPointType.Start:
                    bamActivityInterceptorConfig.RegisterStartNew(trackPoint.Location, trackPoint.ExtractionInfo);
                    break;

                case TrackPointType.Reference:
                    bamActivityInterceptorConfig.RegisterReference(trackPoint.ItemName, trackPoint.ReferenceType, trackPoint.Location, trackPoint.ExtractionInfo);
                    break;

                case TrackPointType.Relationship:
                    bamActivityInterceptorConfig.RegisterRelationship(trackPoint.ItemName, trackPoint.Location, trackPoint.ExtractionInfo);
                    break;

                case TrackPointType.EnableContinuation:
                    if (string.IsNullOrWhiteSpace(trackPoint.ItemName))
                    {
                        bamActivityInterceptorConfig.RegisterEnableContinuation(trackPoint.Location, trackPoint.ExtractionInfo);
                    }
                    else
                    {
                        bamActivityInterceptorConfig.RegisterEnableContinuation(
                            trackPoint.Location,
                            trackPoint.ExtractionInfo,
                            trackPoint.ItemName);
                    }

                    break;

                case TrackPointType.Continue:
                    if (string.IsNullOrWhiteSpace(trackPoint.ItemName))
                    {
                        bamActivityInterceptorConfig.RegisterContinue(trackPoint.Location, trackPoint.ExtractionInfo);
                    }
                    else
                    {
                        bamActivityInterceptorConfig.RegisterContinue(trackPoint.Location, trackPoint.ExtractionInfo, trackPoint.ItemName);
                    }

                    break;

                case TrackPointType.Data:
                    bamActivityInterceptorConfig.RegisterDataExtraction(trackPoint.ItemName, trackPoint.Location, trackPoint.ExtractionInfo);
                    break;

                case TrackPointType.End:
                    bamActivityInterceptorConfig.RegisterEnd(trackPoint.Location);
                    break;
                }
            }

            bamActivityInterceptorConfig.UpdateInterceptor(interceptor);

            // #if !DEBUG1
            //            // Add to the local cache
            //            DirectivesCache.Add(key.ToString(), interceptor);
            // #endif
            this.bamInterceptor = interceptor;

            Debug.Write("[Resolver] GetInterceptor - Returned a BAM interceptor for activity " + activityName);

            return(interceptor);
        }
Ejemplo n.º 5
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.º 6
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
        }