Esempio n. 1
0
        /// <summary>
        /// Create a new directory monitor for the provided file reference collection on the provided path.
        /// </summary>
        /// <param name="path">The file path to monitor.</param>
        /// <param name="filter">A matching filter to files to look for in the specified path</param>
        public FileReferenceCollection(string path, string filter)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            m_Path = path.Trim();

            if (Directory.Exists(m_Path) == false)
            {
                throw new DirectoryNotFoundException(string.Format("The path '{0}' does not exist and therefore can't be monitored.", path));
            }

            m_Filter = filter;

            m_Logger = ApplicationLogging.CreateLogger <FileReferenceCollection>();

            //but now go off and find everything that already exists.
            m_MonitoredDirectory = new DirectoryInfo(m_Path);
            FileInfo[] reportDefinitionFiles = string.IsNullOrEmpty(m_Filter) ? m_MonitoredDirectory.GetFiles() : m_MonitoredDirectory.GetFiles(m_Filter);

            foreach (FileInfo definitionFile in reportDefinitionFiles)
            {
                FileReference newReference = new FileReference(definitionFile);
                Add(newReference);
            }

            //and fire up our background thread to monitor stuff....
            CreateDirectoryMonitorThread();
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new file reference object
        /// </summary>
        /// <param name="referencedFile">The file information object for the file being added</param>
        internal FileReference(FileInfo referencedFile)
        {
            if (referencedFile == null)
            {
                throw new ArgumentNullException(nameof(referencedFile));
            }

            m_Logger = ApplicationLogging.CreateLogger <FileReference>();

            Caption       = referencedFile.Name;
            FileNamePath  = referencedFile.FullName;
            LastWriteTime = referencedFile.LastWriteTime;

            //load up the file as a snapshot load
            Refresh();
        }