コード例 #1
0
        private void ProcessScannerFiles(List <String> listScannerFileNames)
        {
            // For each of these scanners we need to validate them and read the audit data path
            foreach (string scannerFileName in listScannerFileNames)
            {
                // get the scanner object first
                AuditScannerDefinition currentScannerConfiguration = AuditWizardSerialization.DeserializeObject(scannerFileName);

                if (currentScannerConfiguration != null)
                {
                    // Do we already have this scanner in our list?
                    AutoLoaderFolder thisFolder = _listUploadFolders.ContainsScanner(currentScannerConfiguration);

                    // If it doesn't already exist, add it
                    if (thisFolder == null)
                    {
                        AddUploadFolder(currentScannerConfiguration);
                    }
                    else
                    {
                        CheckUploadFolder(thisFolder);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// This function is called to check the supplied scanner to determine if it has been updated
        /// and if so to check and if necessary update the data folder being watched
        /// </summary>
        /// <param name="theFolder"></param>
        protected void CheckUploadFolder(AutoLoaderFolder aFolder)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                // Get the timestamp for the file and if matches that stored exit
                DateTime lastWriteTime = File.GetLastWriteTime(aFolder.FileName);

                if (lastWriteTime == aFolder.LastTimeStamp)
                {
                    return;
                }

                ourLog.Write("File timestamp indicates changes made - validating", true);

                // the timestamp differs meaning that the file has been updated - this means that we
                // will have to re-read the file and check it's data  folder
                aFolder.LastTimeStamp = lastWriteTime;                  // Update the timestamp anyway
                AuditScannerDefinition scannerConfiguration = AuditWizardSerialization.DeserializeObject(aFolder.FileName);

                if (Convert.ToBoolean(config.AppSettings.Settings["disable_all_uploads"].Value))
                {
                    ourLog.Write("disable_all_uploads is turned on - removing from list of watched folders.", true);
                    _listUploadFolders.Remove(aFolder);
                    return;
                }

                if (!scannerConfiguration.AutoUpload)
                {
                    // if the auto-upload has been changed to false then remove from the list
                    ourLog.Write("Auto-upload is set to false - removing from list of watched folders.", true);
                    _listUploadFolders.Remove(aFolder);
                    return;
                }

                // Check to see if the file is in fact a valid file and if not we ignore this file but update our timestamp
                if (!scannerConfiguration.IsValidFile)
                {
                    ourLog.Write("Scanner configuration File does not appear to be valid and will be ignored.", true);
                    return;
                }

                // Get the data Path - has it changed?  If not then return
                if (scannerConfiguration.DeployPathData == aFolder.DataFolder)
                {
                    ourLog.Write("Scanner data path does not appear to have changed - ignoring file update.", true);
                    return;
                }

                // Ok the path has changed so we need to change the path looked at by the watcher.
                aFolder.DataFolder = scannerConfiguration.DeployPathData;
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [CheckUploadFolder], Exception Text is is " + ex.Message, true);
            }
        }
コード例 #3
0
        /// <summary>
        /// Add a new upload folder to those being monitored
        /// </summary>
        /// <param name="scannerFile"></param>
        protected void AddUploadFolder(AuditScannerDefinition aScannerConfiguration)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                // Get the timestamp for the file
                string   fileName      = aScannerConfiguration.Filename;
                DateTime lastWriteTime = File.GetLastWriteTime(fileName);

                if (Convert.ToBoolean(config.AppSettings.Settings["disable_all_uploads"].Value))
                {
                    ourLog.Write("disable_all_uploads is turned on - not adding to list of watched folders.", true);
                    return;
                }

                // Check to see if the file is a valid file and has auto-upload enabled
                if (!aScannerConfiguration.IsValidFile)
                {
                    ourLog.Write("The format of the scanner configuration file is not valid.", true);
                    return;
                }

                if (!aScannerConfiguration.AutoUpload)
                {
                    ourLog.Write("The scanner configuration " + aScannerConfiguration.ScannerName + " has auto-upload disabled - not processing.", true);
                    return;
                }

                try
                {
                    string dataPath = aScannerConfiguration.DeployPathData;
                    if (dataPath == "")
                    {
                        return;
                    }

                    // Create a new AutoLoaderFolder object to hold the details for this scanner
                    AutoLoaderFolder newFolder = new AutoLoaderFolder(fileName, aScannerConfiguration.ScannerName, dataPath, null, lastWriteTime);

                    // ...and add to our list
                    _listUploadFolders.Add(newFolder);
                }
                catch (Exception ex)
                {
                    ourLog.Write("Exception occurred creating the FileSystemWatcher, text is " + ex.Message, true);
                }
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [AddUploadFolder] for xml file: " + aScannerConfiguration.ScannerName +
                             " , the exception was '" + ex.Message + "'", true);
            }
        }