Candor.Tasks.ServiceProcess.ServiceMonitorWorkerRoleTask.ValidateServiceFile C# (CSharp) Method

ValidateServiceFile() protected method

Validates that a service file exists, and if not it is logged. A custom logger should be provided to notify the appropriate party.
protected ValidateServiceFile ( ) : bool
return bool
        protected bool ValidateServiceFile()
        {
            if (string.IsNullOrEmpty(OutputFileNameToWatch)) { return true; }

            FileInfo fileInfo;
            try
            {
                fileInfo = new FileInfo(OutputFileNameToWatch);
            }
            catch (Exception acquireEx)
            {
                LogProvider.WarnFormat("Could not find file '{0}'.", acquireEx, OutputFileNameToWatch);
                return false;
            }
            DateTime lastWrite;
            try
            {
                lastWrite = fileInfo.LastWriteTime;
            }
            catch (IOException accessEx)
            {
                LogProvider.WarnFormat("Could not determine last access time for '{0}'.", accessEx, OutputFileNameToWatch);
                return false;
            }
            if (lastWrite.AddMinutes(OutputFileMaxAgeMinutes) < DateTime.Now)
            {
                if (lastWrite.AddMinutes(OutputFileMaxAgeMinutes * 10) < DateTime.Now)
                {   //this file access time is likely old because it is inaccessible,
                    //  or this service has been ignored WAY to long.
                    LogProvider.WarnFormat("'{0}' service cannot accurately check for updated file '{1}'.  The file is inaccessible or severely out of date!",
                        Name, OutputFileNameToWatch);
                }
                else
                {
                    LogProvider.WarnFormat("'{0}' service has not updated file '{1}' in {2} minutes.  The normal maximum age is {3} minutes old.",
                        Name, OutputFileNameToWatch,
                        DateTime.Now.Subtract(lastWrite).TotalMinutes,
                        GetExpectedAgeMinutes());
                }
                return false;
            }
            LogProvider.DebugFormat("'{0}' service has updated file '{1}' {2} minutes ago.",
                                    Name, OutputFileNameToWatch,
                                    DateTime.Now.Subtract(lastWrite).TotalMinutes);
            return true;
        }