public override HealthMonitorResult DoHealthCheck(IEnumerable <BoundsLimit> healthCheckParameters)
        {
            try
            {
                BoundsLimit boundsLimit = healthCheckParameters.FirstOrDefault(x => x.Name.ToLower().Equals(ServiceTimeoutMillisecondsParameter.ToLower()));
                if (boundsLimit != null)
                {
                    int serviceTimeoutMilliseconds = int.Parse(boundsLimit.Value);
                    ServiceTimeout = TimeSpan.FromMilliseconds(serviceTimeoutMilliseconds);
                }
                BoundsLimit[] checkParameters         = healthCheckParameters as BoundsLimit[] ?? healthCheckParameters.ToArray();
                string        rollingFileAppenderName = checkParameters.FirstOrDefault(x => x.Type.Equals("appender-ref")).Value;
                var           rollingFileName         = checkParameters.FirstOrDefault(x => x.Type.Equals("file")).Value;


                //Read the configuration
                Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
                CleanupLogs(hierarchy, rollingFileAppenderName, rollingFileName);
            }
            catch (Exception e)
            {
                Result.Status = ResultStatus.Error;
                Result.MessageBuilder.Append(e.ToLogString()).Append(Environment.NewLine);
            }
            return(Result);
        }
 public override HealthMonitorResult DoHealthCheck(IEnumerable <BoundsLimit> healthCheckParameters)
 {
     try
     {
         BoundsLimit boundsLimit = healthCheckParameters.FirstOrDefault(x => x.Name.ToLower().Equals(ServiceTimeoutMillisecondsParameter.ToLower()));
         if (boundsLimit != null)
         {
             int serviceTimeoutMilliseconds = int.Parse(boundsLimit.Value);
             ServiceTimeout = TimeSpan.FromMilliseconds(serviceTimeoutMilliseconds);
         }
         BoundsLimit[]       checkParameters   = healthCheckParameters as BoundsLimit[] ?? healthCheckParameters.ToArray();
         ServiceController[] servicesToRestart = checkParameters.Where(x => x.Type.Equals("service"))
                                                 .Select(y => new ServiceController(y.Value))
                                                 .ToArray();
         return(RestartServices(servicesToRestart));
     }
     catch (Exception e)
     {
         return(new HealthMonitorResult(Name, HealthType, ResultStatus.Error, e.ToLogString()));
     }
 }
        /// <summary>
        /// Iterate through all prescribed directories and look to optimeze by either deleting or
        /// archiveing/zipping files
        /// </summary>
        /// <param name="healthCheckParameters">parameters that include size of file before archiving and directories to work on</param>
        /// <returns> object</returns>
        public override HealthMonitorResult DoHealthCheck(IEnumerable <BoundsLimit> healthCheckParameters)
        {
            const string maxDays = "maxDays";
            const string maxSize = "maxSize";

            HealthMonitorResult result = new HealthMonitorResult(Name, HealthType, ResultStatus.Information);

            string[]      spaceOptimizeCheckParams = new[] { maxDays, maxSize };
            BoundsLimit[] checkParameters          = healthCheckParameters as BoundsLimit[] ?? healthCheckParameters.ToArray();
            EnsureAllParametersArePresent(spaceOptimizeCheckParams, checkParameters);
            int  daysOld  = int.Parse(checkParameters.Single(x => x.Name.Equals(maxDays)).Value);
            long fileSize = long.Parse(checkParameters.Single(x => x.Name.Equals(maxSize)).Value);

            spaceOptimizationService.MaxDays = daysOld;
            spaceOptimizationService.MaxSize = fileSize;
            BoundsLimit boundsLimit = checkParameters.FirstOrDefault(x => x.Name.ToLower().Equals(ServiceTimeoutMillisecondsParameter.ToLower()));

            if (boundsLimit != null)
            {
                int serviceTimeoutMilliseconds = int.Parse(boundsLimit.Value);
                ServiceTimeout = TimeSpan.FromMilliseconds(serviceTimeoutMilliseconds);
            }
            //the list of folder(s) to work on are of type 'folder'
            List <string> directories = checkParameters.Where(x => x.Type.Equals("folder"))
                                        .Select(y => y.Value)
                                        .ToList();

            ServiceController[] services = checkParameters.Where(x => x.Type.Equals("service"))
                                           .Select(y => new ServiceController(y.Value))
                                           .ToArray();
            HealthMonitorResult resultToStop = StopServices(services);

            result.MessageBuilder.AppendNewLine(resultToStop.MessageBuilder.ToString());
            List <SpaceOptimizationSummary> optimizations = new List <SpaceOptimizationSummary>();

            //iterete through directories
            foreach (string path in directories)
            {
                try
                {
                    DirectoryInfo directory = new DirectoryInfo(path);
                    archiveService.ArchiveFileName = Path.Combine(path, ZIP_FILE_NAME);
                    SpaceOptimizationSummary summary = new SpaceOptimizationSummary(DateTime.Now,
                                                                                    new List <FileOptimized>(),
                                                                                    path,
                                                                                    directory.GetCurrentSizeExceptFiles(".zip"));
                    result.MessageBuilder.AppendNewLine(DeleteOldArchivedFiles(summary, daysOld));
                    result.MessageBuilder.AppendNewLine(DeleteOldArchivedFiles(summary, path));
                    summary.CurrentSize = directory.GetCurrentSizeExceptFiles(".zip");
                    result.MessageBuilder.AppendNewLine(summary.ToString());
                    optimizations.Add(summary);
                }
                catch (Exception e)
                {
                    result.MessageBuilder.AppendNewLine(e.ToLogString());
                    result.Status = ResultStatus.Warning;
                }
            }
            HealthMonitorResult resultToStart = StartServices(services);

            result.MessageBuilder.AppendNewLine(resultToStart.MessageBuilder.ToString());
            string spaceSavedMessage = string.Format(SystemConstants.TOTAL_FILE_SIZE_MSG,
                                                     FileSizeUtils.FileSizeDescription(optimizations.Sum(x => x.SpaceSaved)));

            result.MessageBuilder.AppendNewLine(spaceSavedMessage);
            return(result);
        }