示例#1
0
        /// <summary>
        /// Creates a new OlsonDirectoryInfo with the provided directory, to provide information on such directory.
        /// </summary>
        /// <param name="path"></param>
        public OlsonDirectoryInfo(string path)
            : base(path)
        {
            _isValid = false;
            if (Exists)
            {
                ValidOlsonFiles = new BlockingCollection <OlsonFileInfo>();

                bool validTabFiles = true;
                try
                {
                    IsoFile  = new OlsonFileInfo(path + ISO_TAB_NAME);
                    ZoneFile = new OlsonFileInfo(path + ZONE_TAB_NAME);
                }
                catch (System.Exception)
                {
                    validTabFiles = false;
                }

                bool validFiles = false;
                var  files      = GetFiles();
                foreach (var file in files)
                {
                    if (_validFiles.Contains(file.Name))
                    {
                        validFiles = true;
                        break;
                    }
                }

                _isValid = validTabFiles || validFiles;
            }
        }
示例#2
0
        /// <summary>
        /// Enumerates and returns all of the valid olson files for this directory.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">fileName is null.</exception>
        /// <exception cref="System.Security.SecurityException">The caller does not have the required permission.</exception>
        /// <exception cref="System.ArgumentException">The file name is empty, contains only white spaces, or contains invalid characters.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Access to fileName is denied.</exception>
        /// <exception cref="System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.
        /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
        /// <exception cref="System.NotSupportedException">fileName contains a colon (:) in the middle of the string.</exception>
        /// <exception cref="System.IO.FileNotFoundException">The filePath provided does not exist.</exception>
        /// <exception cref="NUIClockUpdater.Models.InvaliOlsonFileException">The file provided is not a valid Olson Database file.</exception>
        public BlockingCollection <OlsonFileInfo> GetValidOlsonFiles()
        {
            try
            {
                string[] paths = null;

                paths = Directory.GetFiles(ToString());
                foreach (string path in paths)
                {
                    try
                    {
                        OlsonFileInfo file = new OlsonFileInfo(path);
                        if (_validFiles.Contains(file.Name.ToLower()))
                        {
                            ValidOlsonFiles.Add(file);
                        }
                    }
                    catch (InvalidOlsonFileException)
                    {
                        continue;
                    }
                }
                return(ValidOlsonFiles);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                ValidOlsonFiles.CompleteAdding();
            }
        }