Ejemplo n.º 1
0
        /*
         * Format of request queue message:
         * <job job_id="{GUID}">
         *   <pauseForSeconds>{numberOfSecondsToDoWork}</pauseForSeconds>
         * </job>
         *
         * Format of response queue message:
         * <job job_id="{GUID}">
         *   <status>{bool: 0: false, 1: true}</status>
         * </job>
         */

        internal static JobA FromQueueMessage(IModel channel, byte[] messageBody)
        {
            XPathNavigator nav = null;

            using (MemoryStream ms = new MemoryStream(messageBody))
            {
                nav = new XPathDocument(ms).CreateNavigator();
            }

            JobA job = new JobA();

            job.Channel          = channel;
            job.State            = JobAState.Begin;
            job.JobXml           = nav.InnerXml;
            job.JobId            = Guid.NewGuid();
            job.StartTime        = DateTime.UtcNow;
            job.NumSecondsToWork = int.Parse(nav.SelectSingleNode("/job/pauseForSeconds").Value);
            job.FullPathAndFilenameToSerializedJob = Path.Combine(
                Environment.CurrentDirectory, "serialized-jobs", job.JobId.ToString() + ".xml");
            return(job);
        }
Ejemplo n.º 2
0
        internal static JobA FromSavedState(IModel channel, string pathFilename)
        {
            JobA job = new JobA();

            string[] serializedStateText = File.ReadAllText(pathFilename).Split(new char[] { ',' });

            XPathNavigator nav = null;

            using (StringReader reader = new StringReader(serializedStateText[1]))
            {
                XPathDocument xPathDoc = new XPathDocument(reader);
                nav = xPathDoc.CreateNavigator();
            }

            job.Channel          = channel;
            job.State            = (JobAState)Enum.Parse(typeof(JobAState), serializedStateText[0]);
            job.JobXml           = nav.InnerXml;
            job.JobId            = Guid.Parse(Path.GetFileNameWithoutExtension(pathFilename));
            job.StartTime        = DateTime.UtcNow;
            job.NumSecondsToWork = int.Parse(nav.SelectSingleNode("/job/pauseForSeconds").Value);
            job.FullPathAndFilenameToSerializedJob = Path.Combine(
                Environment.CurrentDirectory, "serialized-jobs", job.JobId.ToString() + ".xml");
            return(job);
        }