コード例 #1
0
        /// <summary>
        /// Check the job store results and if maximum number of results exist
        /// remove the oldest results folder to make room for these new results.
        /// </summary>
        /// <param name="outputPath">Output path</param>
        /// <param name="executionHistoryLength">Maximum size of stored job results</param>
        private static void CheckJobStoreResults(string outputPath, int executionHistoryLength)
        {
            // Get current results for this job definition.
            Collection <DateTime> jobRuns = ScheduledJobStore.GetJobRunsForDefinitionPath(outputPath);

            if (jobRuns.Count <= executionHistoryLength)
            {
                // There is room for another job run in the store.
                return;
            }

            // Remove the oldest job run from the store.
            DateTime jobRunToRemove = DateTime.MaxValue;

            foreach (DateTime jobRun in jobRuns)
            {
                jobRunToRemove = (jobRun < jobRunToRemove) ? jobRun : jobRunToRemove;
            }

            try
            {
                ScheduledJobStore.RemoveJobRunFromOutputPath(outputPath, jobRunToRemove);
            }
            catch (UnauthorizedAccessException)
            { }
        }
コード例 #2
0
        private static void CheckJobStoreResults(string outputPath, int executionHistoryLength)
        {
            DateTime dateTime;
            Collection <DateTime> jobRunsForDefinitionPath = ScheduledJobStore.GetJobRunsForDefinitionPath(outputPath);

            if (jobRunsForDefinitionPath.Count > executionHistoryLength)
            {
                DateTime maxValue = DateTime.MaxValue;
                foreach (DateTime dateTime1 in jobRunsForDefinitionPath)
                {
                    if (dateTime1 < maxValue)
                    {
                        dateTime = dateTime1;
                    }
                    else
                    {
                        dateTime = maxValue;
                    }
                    maxValue = dateTime;
                }
                try
                {
                    ScheduledJobStore.RemoveJobRunFromOutputPath(outputPath, maxValue);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException)
                {
                }
                return;
            }
            else
            {
                return;
            }
        }
コード例 #3
0
 public static Collection <DateTime> GetJobRunsForDefinition(string definitionName)
 {
     if (!string.IsNullOrEmpty(definitionName))
     {
         string jobRunOutputDirectory = ScheduledJobStore.GetJobRunOutputDirectory(definitionName);
         return(ScheduledJobStore.GetJobRunsForDefinitionPath(jobRunOutputDirectory));
     }
     else
     {
         throw new PSArgumentException("definitionName");
     }
 }