internal static void SaveJobToStore(ScheduledJob job)
        {
            DateTime valueOrDefault;
            DateTime minValue;
            string   outputPath = job.Definition.OutputPath;

            if (!string.IsNullOrEmpty(outputPath))
            {
                FileStream fileStream  = null;
                FileStream fileStream1 = null;
                try
                {
                    ScheduledJobSourceAdapter.CheckJobStoreResults(outputPath, job.Definition.ExecutionHistoryLength);
                    string   str         = outputPath;
                    DateTime?pSBeginTime = job.PSBeginTime;
                    if (pSBeginTime.HasValue)
                    {
                        valueOrDefault = pSBeginTime.GetValueOrDefault();
                    }
                    else
                    {
                        valueOrDefault = DateTime.MinValue;
                    }
                    fileStream = ScheduledJobStore.CreateFileForJobRunItem(str, valueOrDefault, ScheduledJobStore.JobRunItem.Status);
                    ScheduledJobSourceAdapter.SaveStatusToFile(job, fileStream);
                    string   str1     = outputPath;
                    DateTime?nullable = job.PSBeginTime;
                    if (nullable.HasValue)
                    {
                        minValue = nullable.GetValueOrDefault();
                    }
                    else
                    {
                        minValue = DateTime.MinValue;
                    }
                    fileStream1 = ScheduledJobStore.CreateFileForJobRunItem(str1, minValue, ScheduledJobStore.JobRunItem.Results);
                    ScheduledJobSourceAdapter.SaveResultsToFile(job, fileStream1);
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                    if (fileStream1 != null)
                    {
                        fileStream1.Close();
                    }
                }
                return;
            }
            else
            {
                string str2 = StringUtil.Format(ScheduledJobErrorStrings.CantSaveJobNoFilePathSpecified, job.Name);
                throw new ScheduledJobException(str2);
            }
        }
Exemple #2
0
        /// <summary>
        /// Serializes a ScheduledJob and saves it to store.
        /// </summary>
        /// <param name="job">ScheduledJob</param>
        internal static void SaveJobToStore(ScheduledJob job)
        {
            string outputPath = job.Definition.OutputPath;

            if (string.IsNullOrEmpty(outputPath))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.CantSaveJobNoFilePathSpecified,
                                               job.Name);
                throw new ScheduledJobException(msg);
            }

            FileStream fsStatus  = null;
            FileStream fsResults = null;

            try
            {
                // Check the job store results and if maximum number of results exist
                // remove the oldest results folder to make room for these new results.
                CheckJobStoreResults(outputPath, job.Definition.ExecutionHistoryLength);

                fsStatus = ScheduledJobStore.CreateFileForJobRunItem(
                    outputPath,
                    job.PSBeginTime ?? DateTime.MinValue,
                    ScheduledJobStore.JobRunItem.Status);

                // Save status only in status file stream.
                SaveStatusToFile(job, fsStatus);

                fsResults = ScheduledJobStore.CreateFileForJobRunItem(
                    outputPath,
                    job.PSBeginTime ?? DateTime.MinValue,
                    ScheduledJobStore.JobRunItem.Results);

                // Save entire job in results file stream.
                SaveResultsToFile(job, fsResults);
            }
            finally
            {
                if (fsStatus != null)
                {
                    fsStatus.Close();
                }

                if (fsResults != null)
                {
                    fsResults.Close();
                }
            }
        }