示例#1
0
        /// <summary>
        /// Finds and load the Job associated with this ScheduledJobDefinition object
        /// having the job run date time provided.
        /// </summary>
        /// <param name="jobRun">DateTime of job run to load</param>
        /// <param name="definitionName">ScheduledJobDefinition name</param>
        /// <returns>Job2 job loaded from store</returns>
        internal static Job2 LoadJobFromStore(string definitionName, DateTime jobRun)
        {
            FileStream fsResults     = null;
            Exception  ex            = null;
            bool       corruptedFile = false;
            Job2       job           = null;

            try
            {
                // Results
                fsResults = ScheduledJobStore.GetFileForJobRunItem(
                    definitionName,
                    jobRun,
                    ScheduledJobStore.JobRunItem.Results,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read);

                job = LoadResultsFromFile(fsResults);
            }
            catch (ArgumentException e)
            {
                ex = e;
            }
            catch (DirectoryNotFoundException e)
            {
                ex = e;
            }
            catch (FileNotFoundException e)
            {
                ex            = e;
                corruptedFile = true;
            }
            catch (UnauthorizedAccessException e)
            {
                ex = e;
            }
            catch (IOException e)
            {
                ex = e;
            }
            catch (System.Runtime.Serialization.SerializationException)
            {
                corruptedFile = true;
            }
            catch (System.Runtime.Serialization.InvalidDataContractException)
            {
                corruptedFile = true;
            }
            catch (System.Xml.XmlException)
            {
                corruptedFile = true;
            }
            catch (System.TypeInitializationException)
            {
                corruptedFile = true;
            }
            finally
            {
                if (fsResults != null)
                {
                    fsResults.Close();
                }
            }

            if (corruptedFile)
            {
                // Remove the corrupted job results file.
                ScheduledJobStore.RemoveJobRun(definitionName, jobRun);
            }

            if (ex != null)
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.CantLoadJobRunFromStore, definitionName, jobRun);
                throw new ScheduledJobException(msg, ex);
            }

            return(job);
        }
        internal static Job2 LoadJobFromStore(string definitionName, DateTime jobRun)
        {
            FileStream fileForJobRunItem = null;
            Exception  exception         = null;
            bool       flag = false;
            Job2       job2 = null;

            try
            {
                try
                {
                    fileForJobRunItem = ScheduledJobStore.GetFileForJobRunItem(definitionName, jobRun, ScheduledJobStore.JobRunItem.Results, FileMode.Open, FileAccess.Read, FileShare.Read);
                    job2 = ScheduledJobSourceAdapter.LoadResultsFromFile(fileForJobRunItem);
                }
                catch (ArgumentException argumentException1)
                {
                    ArgumentException argumentException = argumentException1;
                    exception = argumentException;
                }
                catch (DirectoryNotFoundException directoryNotFoundException1)
                {
                    DirectoryNotFoundException directoryNotFoundException = directoryNotFoundException1;
                    exception = directoryNotFoundException;
                }
                catch (FileNotFoundException fileNotFoundException1)
                {
                    FileNotFoundException fileNotFoundException = fileNotFoundException1;
                    exception = fileNotFoundException;
                    flag      = true;
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    exception = unauthorizedAccessException;
                }
                catch (IOException oException1)
                {
                    IOException oException = oException1;
                    exception = oException;
                }
                catch (SerializationException serializationException)
                {
                    flag = true;
                }
                catch (InvalidDataContractException invalidDataContractException)
                {
                    flag = true;
                }
                catch (XmlException xmlException)
                {
                    flag = true;
                }
                catch (TypeInitializationException typeInitializationException)
                {
                    flag = true;
                }
            }
            finally
            {
                if (fileForJobRunItem != null)
                {
                    fileForJobRunItem.Close();
                }
            }
            if (flag)
            {
                ScheduledJobStore.RemoveJobRun(definitionName, jobRun);
            }
            if (exception == null)
            {
                return(job2);
            }
            else
            {
                object[] objArray = new object[2];
                objArray[0] = definitionName;
                objArray[1] = jobRun;
                string str = StringUtil.Format(ScheduledJobErrorStrings.CantLoadJobRunFromStore, objArray);
                throw new ScheduledJobException(str, exception);
            }
        }