Exemplo n.º 1
0
        public static void EnsureAllRfpFileExists()
        {
            string fileName = IOHelper.GetAllRfpsFileName();

            if (!File.Exists(fileName))
            {
                XElement root = new XElement("requestForProposals");
                root.Save(fileName);
            }
        }
Exemplo n.º 2
0
        // retrieve a Request for Proposal from the repository by Id
        public static RequestForProposal Retrieve(Guid id)
        {
            // load the document
            XElement doc = XElement.Load(IOHelper.GetAllRfpsFileName());

            // erase nodes for the current rfp
            IEnumerable <RequestForProposal> current =
                from r in doc.Elements("requestForProposal")
                where r.Attribute("id").Value.Equals(id.ToString())
                select MapFrom(r);

            return(current.First <RequestForProposal>());
        }
Exemplo n.º 3
0
        // retrieve all finished Requests for Proposals
        public static IEnumerable <RequestForProposal> RetrieveFinished()
        {
            //  if no persistence file, exit
            if (!File.Exists(IOHelper.GetAllRfpsFileName()))
            {
                return(new List <RequestForProposal>());
            }

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

            // fetch active rfps
            return
                (from rfp in doc.Descendants("requestForProposal")
                 where (rfp.Attribute("status").Value.Equals("finished"))
                 select MapFrom(rfp));
        }
        //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);
        }