Ejemplo n.º 1
0
        private string GetTop10FileInfos(List <FileInfo> fileInfos)
        {
            StringBuilder sb       = new StringBuilder();
            int           topCount = 10;

            for (int i = 0; i < topCount && i < fileInfos.Count; i++)
            {
                FileInfo fi = fileInfos[i];
                sb.AppendLine(string.Format("\t{0} - {1}", fi.Name, FormatUtils.FormatFileSize(fi.Length)));
            }
            if (fileInfos.Count > 10)
            {
                sb.AppendLine("...");
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public MonitorStates GetState(DirectoryFileInfo fileInfo)
        {
            MonitorStates returnState = MonitorStates.Good;

            LastErrorMsg = "";
            if (!fileInfo.Exists)
            {
                returnState  = MonitorStates.Error;
                LastErrorMsg = string.Format("Directory '{0}' not found or not accessible!", DirectoryPath);
            }
            else if (DirectoryExistOnly)
            {
                returnState = MonitorStates.Good;
            }
            else if (fileInfo.FileCount == -1)
            {
                returnState  = MonitorStates.Error;
                LastErrorMsg = string.Format("An error occured while accessing '{0}'\r\n\t{1}", FilterFullPath, LastErrorMsg);
            }
            else
            {
                if (
                    (CountErrorIndicator > 0 && CountErrorIndicator <= fileInfo.FileCount) ||
                    (SizeKBErrorIndicator > 0 && SizeKBErrorIndicator * 1024 <= fileInfo.FileSize)
                    )
                {
                    returnState  = MonitorStates.Error;
                    LastErrorMsg = string.Format("Error state reached for '{0}': {1} file(s), {2}", FilterFullPath, fileInfo.FileCount, FormatUtils.FormatFileSize(fileInfo.FileSize));
                }
                else if (
                    (CountWarningIndicator > 0 && CountWarningIndicator <= fileInfo.FileCount) ||
                    (SizeKBWarningIndicator > 0 && SizeKBWarningIndicator * 1024 <= fileInfo.FileSize)
                    )
                {
                    returnState  = MonitorStates.Warning;
                    LastErrorMsg = string.Format("Warning state reached for '{0}': {1} file(s), {2}", FilterFullPath, fileInfo.FileCount, FormatUtils.FormatFileSize(fileInfo.FileSize));
                }
                else
                {
                    returnState = MonitorStates.Good;
                }
            }
            return(returnState);
        }