Tracks files processed in a list of directories, and notifies when new files become available to be processed.
상속: IDisposable
예제 #1
0
 public TrackedDirectory(FileProcessor fileProcessor, string path)
 {
     m_fileProcessor = fileProcessor;
     Path            = path;
     CreateFileWatcher();
 }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            if (m_disposed)
                return;

            try
            {
                Stop();

                // Stop file monitor timer
                if ((object)m_fileProcessor != null)
                {
                    m_fileProcessor.Processing -= FileProcessor_Processing;
                    m_fileProcessor.Error -= FileProcessor_Error;
                    m_fileProcessor.Dispose();
                    m_fileProcessor = null;
                }
            }
            finally
            {
                m_disposed = true;
            }
        }
        /// <summary>
        /// Starts the fault location engine.
        /// </summary>
        public void Start()
        {
            IEnumerable<string> filterPatterns;

            // Get system settings from the database
            ReloadSystemSettings();

            // Get the list of file extensions to be processed by openXDA
            using (SystemInfoDataContext systemInfo = new SystemInfoDataContext(m_dbConnectionString))
            {
                filterPatterns = systemInfo.DataReaders
                    .Select(reader => reader.FilePattern)
                    .Select(extension => string.Format("*.{0}", extension))
                    .ToList();
            }

            // Reload configuration at startup
            ReloadConfiguration();

            // Make sure watch directories exist
            foreach (string path in m_systemSettings.WatchDirectoryList)
                TryCreateDirectory(path);

            // Make sure results directory exists
            TryCreateDirectory(m_systemSettings.ResultsPath);

            if ((object)m_fileWrapperLookup == null)
                m_fileWrapperLookup = new Dictionary<string, FileWrapper>();

            // Create the lookup table used to track which files are being processed
            if ((object)m_activeFiles == null)
                m_activeFiles = new ConcurrentDictionary<string, string>();

            // Create the scheduler used to schedule when to process meter data
            if ((object)m_meterDataScheduler == null)
            {
                m_meterDataScheduler = new LogicalThreadScheduler();
                m_meterDataThreadLookup = new Dictionary<string, LogicalThread>();

                m_meterDataScheduler.UnhandledException += (sender, args) =>
                {
                    string message = $"Unhandled exception occurred while processing meter data: {args.Argument.Message}";
                    Exception ex = new Exception(message, args.Argument);
                    OnProcessException(ex);
                };
            }

            m_meterDataScheduler.MaxThreadCount = m_systemSettings.ProcessingThreadCount;

            // Setup new file processor to monitor the watch directories
            if ((object)m_fileProcessor == null)
            {
                m_fileProcessor = new FileProcessor(FileProcessorID);
                m_fileProcessor.InternalBufferSize = m_systemSettings.FileWatcherBufferSize;
                m_fileProcessor.EnumerationStrategy = m_systemSettings.FileWatcherEnumerationStrategy;
                m_fileProcessor.MaxThreadCount = m_systemSettings.FileWatcherInternalThreadCount;
                m_fileProcessor.MaxFragmentation = m_systemSettings.FileWatcherMaxFragmentation;
                m_fileProcessor.FilterMethod = PrevalidateFile;
                m_fileProcessor.Processing += FileProcessor_Processing;
                m_fileProcessor.Error += FileProcessor_Error;

                UpdateFileProcessorFilter(m_systemSettings);
            }

            foreach (string path in m_systemSettings.WatchDirectoryList)
                m_fileProcessor.AddTrackedDirectory(path);
        }
예제 #4
0
파일: FileProcessor.cs 프로젝트: rmc00/gsf
            /// <summary>
            /// Creates a new instance of the <see cref="FileEnumerator"/> class.
            /// </summary>
            /// <param name="fileProcessor">The file processor that created the file enumerator.</param>
            public FileEnumerator(FileProcessor fileProcessor)
            {
                m_fileProcessor = fileProcessor;
                m_cancellationTokens = new Dictionary<string, CancellationToken>();

                m_sequentialEnumerationThread = m_fileProcessor.m_threadScheduler.CreateThread();
                m_isActive = new LogicalThreadLocal<bool>();
                m_wrapperStack = new LogicalThreadLocal<Stack<Action>>(() => new Stack<Action>());
                m_directoryQueue = new LogicalThreadLocal<Queue<Action>>(() => new Queue<Action>());

                m_cleanProcessedFilesThread = m_fileProcessor.m_threadScheduler.CreateThread();
                m_cleanProcessedFilesOperation = new LogicalThreadOperation(m_cleanProcessedFilesThread, GetProcessedFiles, false);
            }