示例#1
0
        // creates a workflow application, binds parameters, links extensions and run it
        public WorkflowApplication CreateAndRun(RequestForProposal rfp)
        {
            // input parameters for the WF program
            IDictionary <string, object> inputs = new Dictionary <string, object>();

            inputs.Add("Rfp", rfp);

            // create and run the WF instance
            Activity            wf       = new PurchaseProcessWorkflow();
            WorkflowApplication instance = new WorkflowApplication(wf, inputs)
            {
                PersistableIdle = OnIdleAndPersistable,
                Completed       = OnWorkflowCompleted,
                Idle            = OnIdle
            };
            XmlWorkflowInstanceStore store = new XmlWorkflowInstanceStore(instance.Id);

            instance.InstanceStore = store;

            //Create the persistence Participant and add it to the workflow instance
            XmlPersistenceParticipant xmlPersistenceParticipant = new XmlPersistenceParticipant(instance.Id);

            instance.Extensions.Add(xmlPersistenceParticipant);

            // add a tracking participant
            instance.Extensions.Add(new SaveAllEventsToTestFileTrackingParticipant());

            // add instance to the host list of running instances
            this.instances.Add(instance.Id, instance);

            // continue executing this instance
            instance.Run();

            return(instance);
        }
        // creates a workflow application, binds parameters, links extensions and run it
        public WorkflowApplication CreateAndRun(RequestForProposal rfp)
        {
            // input parameters for the WF program
            IDictionary<string, object> inputs = new Dictionary<string, object>();
            inputs.Add("Rfp", rfp);

            // create and run the WF instance
            Activity wf = new PurchaseProcessWorkflow();
            WorkflowApplication instance = new WorkflowApplication(wf, inputs);
            XmlWorkflowInstanceStore store = new XmlWorkflowInstanceStore(instance.Id);
            instance.InstanceStore = store;
            instance.PersistableIdle += OnIdleAndPersistable;
            instance.Completed += OnWorkflowCompleted;
            instance.Idle += OnIdle;

            //Create the persistence Participant and add it to the workflow instance
            XmlPersistenceParticipant xmlPersistenceParticipant = new XmlPersistenceParticipant(instance.Id);
            instance.Extensions.Add(xmlPersistenceParticipant);

            // add a tracking participant
            instance.Extensions.Add(new SaveAllEventsToTestFileTrackingParticipant());

            // add instance to the host list of running instances
            this.instances.Add(instance.Id, instance);

            // continue executing this instance
            instance.Run();

            return instance;
        }
        // serialize a Rfp to Xml using Linq to Xml
        XElement SerializeRfp(RequestForProposal rfp, Guid instanceId)
        {
            // main body of the rfp
            XElement ret =
                new XElement("requestForProposal",
                             new XAttribute("id", instanceId.ToString()),
                             new XAttribute("status", rfp.Status),
                             new XElement("creationDate", rfp.CreationDate),
                             new XElement("completionDate", rfp.CompletionDate),
                             new XElement("title", rfp.Title),
                             new XElement("description", rfp.Description));

            // add invited vendors
            XElement invitedVendors = new XElement("invitedVendors");

            foreach (Vendor vendor in rfp.InvitedVendors)
            {
                invitedVendors.Add(
                    new XElement("vendor",
                                 new XAttribute("id", vendor.Id)));
            }
            ret.Add(invitedVendors);

            // add vendor proposals
            XElement vendorProposals = new XElement("vendorProposals");

            foreach (VendorProposal proposal in rfp.VendorProposals.Values)
            {
                vendorProposals.Add(
                    new XElement("vendorProposal",
                                 new XAttribute("vendorId", proposal.Vendor.Id),
                                 new XAttribute("date", proposal.Date),
                                 new XAttribute("value", proposal.Value)));
            }
            ret.Add(vendorProposals);

            // add best proposal
            if (rfp.BestProposal != null && rfp.BestProposal.Vendor != null)
            {
                ret.Add(
                    new XElement("bestProposal",
                                 new XAttribute("vendorId", rfp.BestProposal.Vendor.Id),
                                 new XAttribute("date", rfp.BestProposal.Date),
                                 new XAttribute("value", rfp.BestProposal.Value)));
            }

            return(ret);
        }
示例#4
0
        // create a new Rfp and launch the WF instance
        private void btnCreate_Click(object sender, EventArgs e)
        {
            // create the RFP
            RequestForProposal rfp = new RequestForProposal();
            rfp.Title = this.txtTitle.Text;
            rfp.Description = this.txtDescription.Text;
            foreach (Vendor vendor in chkVendors.CheckedItems)
            {
                rfp.InvitedVendors.Add(vendor);
            }

            // create the proposal within the host
            this.PurchaseProcessHost.CreateAndRun(rfp);

            // show final message
            this.Hide();
        }
示例#5
0
        // map a Request for Proposal from a Linq to Xml XElement
        static RequestForProposal MapFrom(XElement elem)
        {
            RequestForProposal rfp = new RequestForProposal();

            rfp.ID           = new Guid(elem.Attribute("id").Value);
            rfp.Status       = elem.Attribute("status").Value;
            rfp.Title        = elem.Element("title").Value;
            rfp.Description  = elem.Element("description").Value;
            rfp.CreationDate = DateTime.Parse(elem.Element("creationDate").Value, new CultureInfo("EN-us"));

            if (elem.Element("completionDate") != null)
            {
                rfp.CompletionDate = DateTime.Parse(elem.Element("completionDate").Value, new CultureInfo("EN-us"));
            }

            // invited vendors
            foreach (XElement vendorElem in elem.Element("invitedVendors").Elements("vendor"))
            {
                Vendor vendor = VendorRepository.Retrieve(Convert.ToInt32(vendorElem.Attribute("id").Value, new CultureInfo("EN-us")));
                rfp.InvitedVendors.Add(vendor);
            }

            // map received proposals in the list
            foreach (var proposal in elem.Element("vendorProposals").Elements("vendorProposal"))
            {
                Vendor         vendor         = VendorRepository.Retrieve(int.Parse(proposal.Attribute("vendorId").Value, new CultureInfo("EN-us")));
                VendorProposal vendorProposal = new VendorProposal(vendor);
                vendorProposal.Value = double.Parse(proposal.Attribute("value").Value, new CultureInfo("EN-us"));
                vendorProposal.Date  = DateTime.Parse(proposal.Attribute("date").Value, new CultureInfo("EN-us"));
                rfp.VendorProposals.Add(vendor.Id, vendorProposal);
            }

            // map best proposal
            if (elem.Element("bestProposal") != null)
            {
                Vendor bestVendor = VendorRepository.Retrieve(Convert.ToInt32(elem.Element("bestProposal").Attribute("vendorId").Value, new CultureInfo("EN-us")));
                rfp.BestProposal       = new VendorProposal(bestVendor);
                rfp.BestProposal.Value = double.Parse(elem.Element("bestProposal").Attribute("value").Value, new CultureInfo("EN-us"));
                rfp.BestProposal.Date  = DateTime.Parse(elem.Element("bestProposal").Attribute("date").Value, new CultureInfo("EN-us"));
            }

            return(rfp);
        }
示例#6
0
        // map a Request for Proposal from a Linq to Xml XElement
        static RequestForProposal MapFrom(XElement elem)
        {
            RequestForProposal rfp = new RequestForProposal();

            rfp.ID = new Guid(elem.Attribute("id").Value);
            rfp.Status = elem.Attribute("status").Value;
            rfp.Title = elem.Element("title").Value;
            rfp.Description = elem.Element("description").Value;
            rfp.CreationDate = DateTime.Parse(elem.Element("creationDate").Value, new CultureInfo("EN-us"));

            if (elem.Element("completionDate") != null)
                rfp.CompletionDate = DateTime.Parse(elem.Element("completionDate").Value, new CultureInfo("EN-us"));

            // invited vendors
            foreach (XElement vendorElem in elem.Element("invitedVendors").Elements("vendor"))
            {
                Vendor vendor = VendorRepository.Retrieve(Convert.ToInt32(vendorElem.Attribute("id").Value, new CultureInfo("EN-us")));
                rfp.InvitedVendors.Add(vendor);
            }

            // map received proposals in the list
            foreach (var proposal in elem.Element("vendorProposals").Elements("vendorProposal"))
            {
                Vendor vendor = VendorRepository.Retrieve(int.Parse(proposal.Attribute("vendorId").Value, new CultureInfo("EN-us")));
                VendorProposal vendorProposal = new VendorProposal(vendor);
                vendorProposal.Value = double.Parse(proposal.Attribute("value").Value, new CultureInfo("EN-us"));
                vendorProposal.Date = DateTime.Parse(proposal.Attribute("date").Value, new CultureInfo("EN-us"));
                rfp.VendorProposals.Add(vendor.Id, vendorProposal);
            }

            // map best proposal
            if (elem.Element("bestProposal") != null)
            {
                Vendor bestVendor = VendorRepository.Retrieve(Convert.ToInt32(elem.Element("bestProposal").Attribute("vendorId").Value, new CultureInfo("EN-us")));
                rfp.BestProposal = new VendorProposal(bestVendor);
                rfp.BestProposal.Value = double.Parse(elem.Element("bestProposal").Attribute("value").Value, new CultureInfo("EN-us"));
                rfp.BestProposal.Date = DateTime.Parse(elem.Element("bestProposal").Attribute("date").Value, new CultureInfo("EN-us"));
            }

            return rfp;
        }
        // serialize a Rfp to Xml using Linq to Xml
        XElement SerializeRfp(RequestForProposal rfp, Guid instanceId)
        {
            // main body of the rfp
            XElement ret =
               new XElement("requestForProposal",
                   new XAttribute("id", instanceId.ToString()),
                   new XAttribute("status", rfp.Status),
                       new XElement("creationDate", rfp.CreationDate),
                       new XElement("completionDate", rfp.CompletionDate),
                       new XElement("title", rfp.Title),
                       new XElement("description", rfp.Description));

            // add invited vendors
            XElement invitedVendors = new XElement("invitedVendors");
            foreach (Vendor vendor in rfp.InvitedVendors)
            {
                invitedVendors.Add(
                    new XElement("vendor",
                        new XAttribute("id", vendor.Id)));
            }
            ret.Add(invitedVendors);

            // add vendor proposals
            XElement vendorProposals = new XElement("vendorProposals");
            foreach (VendorProposal proposal in rfp.VendorProposals.Values)
            {
                vendorProposals.Add(
                    new XElement("vendorProposal",
                        new XAttribute("vendorId", proposal.Vendor.Id),
                        new XAttribute("date", proposal.Date),
                        new XAttribute("value", proposal.Value)));
            }
            ret.Add(vendorProposals);

            // add best proposal
            if (rfp.BestProposal != null && rfp.BestProposal.Vendor != null)
            {
                ret.Add(
                    new XElement("bestProposal",
                        new XAttribute("vendorId", rfp.BestProposal.Vendor.Id),
                        new XAttribute("date", rfp.BestProposal.Date),
                        new XAttribute("value", rfp.BestProposal.Value)));
            }

            return ret;
        }
        //Implementations of MapValues are given all the values collected from all participants’ implementations of CollectValues
        protected override IDictionary <XName, object> MapValues(IDictionary <XName, object> readWriteValues, IDictionary <XName, object> writeOnlyValues)
        {
            XName statusXname = XName.Get("Status", propertiesNamespace);

            IDictionary <XName, object> mappedValues = base.MapValues(readWriteValues, writeOnlyValues);

            RequestForProposal requestForProposal = null;
            string             status             = string.Empty;
            object             value = null;

            //retrieve the status of the workflow
            if (writeOnlyValues.TryGetValue(statusXname, out value))
            {
                status = (string)value;
            }

            //retrieve the RequestForProposal object
            foreach (KeyValuePair <System.Xml.Linq.XName, object> item in writeOnlyValues)
            {
                if (item.Value is LocationInfo)
                {
                    LocationInfo li = (LocationInfo)item.Value;
                    if (li.Value is RequestForProposal)
                    {
                        requestForProposal = (RequestForProposal)li.Value;
                    }
                }
            }

            IOHelper.EnsureAllRfpFileExists();

            // load the document
            XElement doc = XElement.Load(IOHelper.GetAllRfpsFileName());

            IEnumerable <XElement> current =
                from r in doc.Elements("requestForProposal")
                where r.Attribute("id").Value.Equals(Id.ToString())
                select r;

            if (status == "Closed")
            {
                // erase nodes for the current rfp
                foreach (XElement xe in current)
                {
                    xe.Attribute("status").Value = "finished";
                }
            }
            else
            {
                // erase nodes for the current rfp
                foreach (XElement xe in current)
                {
                    xe.Remove();
                }

                // get the Xml version of the Rfp, add it to the document and save it
                if (requestForProposal != null)
                {
                    XElement e = SerializeRfp(requestForProposal, Id);
                    doc.Add(e);
                }
            }

            doc.Save(IOHelper.GetAllRfpsFileName());

            return(mappedValues);
        }