コード例 #1
0
        /// <exception cref="ResourcesNotFoundException">
        ///     Thrown, if both <see cref="GlobalSettings.ResourcesAssembly" /> is not set and the entry assembly
        ///     cannot be accesed.
        /// </exception>
        private void ReadDicts()
        {
            var rm = ResourcesManagerProvider.GetResourcesManager();

            Dictionary <string, string> invariantFallback = null;

            //collect all Resource entries.
            var langs = CultureInfo.GetCultures(CultureTypes.AllCultures);

            foreach (var lang in langs)
            {
                try
                {
                    //tryParents is false and will be handled in CultureInfoUtils insted, to avoid registering
                    //same dict multiple times.
                    var resourceSet = rm.GetResourceSet(lang, true, false);
                    if (resourceSet == null)
                    {
                        continue;
                    }

                    if (lang.Equals(CultureInfo.InvariantCulture))
                    {
                        invariantFallback = resourceSet.Cast <DictionaryEntry>().ToDictionary(
                            r => r.Key.ToString(), r => r.Value.ToString());
                    }
                    else
                    {
                        _dictOfDicts.Add(lang, resourceSet.Cast <DictionaryEntry>().ToDictionary(
                                             r => r.Key.ToString(), r => r.Value.ToString()));
                    }
                }
                catch (CultureNotFoundException)
                {
                    //all non-existent languages will be ignored.
                }
            }

            TryAddChangesIntoDictOfDicts();

            if (_dictOfDicts.ContainsKey(InputLanguage))
            {
                _dictOfDicts.Add(CultureInfo.InvariantCulture, invariantFallback);
            }
            //if Inputlanguage is not present, use invariant as replacement instead, because
            //InputLanguage is expected to always exist.
            else
            {
                ExceptionLoggingUtils.ThrowIf <InputLanguageNotFoundException>(invariantFallback == null,
                                                                               _logger, $"The given input language ({InputLanguage.EnglishName}) was not found in the " +
                                                                               "Resources files.");

                _dictOfDicts.Add(InputLanguage, invariantFallback);
            }

            _status = ProviderStatus.Initialized;
        }
コード例 #2
0
        /// <summary>
        ///     Handles Exception logging for the given <paramref name="path" />.
        ///     Returns the given <paramref name="path" /> with the appropriate ending, if it was not present.
        /// </summary>
        /// <param name="path">The path that should be verified.</param>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="path" /> is null.</exception>
        /// <exception cref="ArgumentException">
        ///     Thrown, if <paramref name="path" /> contains only white space, includes
        ///     unsupported characters or if the system fails to get the fully qualified
        ///     location for the given path.
        /// </exception>
        /// <exception cref="System.Security.SecurityException">
        ///     Thrown, if the permissions for accessing the full path are missing.
        /// </exception>
        /// <exception cref="NotSupportedException">
        ///     Thrown, if <paramref name="path" /> contains a colon anywhere other than as part of a
        ///     volume identifier ("C:\").
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     Thrown, if <paramref name="path" /> is too long.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     Thrown, if permissions to create the directory are missing.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     Thrown, if the directory was not found.
        ///     For example because it is on an unmapped device.
        /// </exception>
        /// <exception cref="IOException">
        ///     Thrown, if a file with the name of the dictionary that should be created already exists.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        ///     Thrown, if <paramref name="path" /> is a dictionary.
        /// </exception>
        public void VerifyPath(string path)
        {
            ExceptionLoggingUtils.ThrowIfNull(_logger, nameof(VerifyPath), (object)path, nameof(path),
                                              "Unable to open path, because it is null.");

            var fullPath = GetFullPathWrapper(path);

            if (File.Exists(fullPath))
            {
                return;
            }

            ExceptionLoggingUtils.ThrowIf(Directory.Exists(fullPath), _logger, new FileNotFoundException(
                                              "Unable to find file, because directory with same name exists.", path),
                                          "Given path is directory instead of file.");

            CreateDirectoryWrapper(fullPath);
        }
コード例 #3
0
        /// <summary>
        ///     Work for BackgroundWorker.
        ///     Loads the excel sheet at <see cref="Path" /> and saves it as its result.
        ///     <see cref="Path" /> has to be set to a value, before this handler is used.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown, if <paramref name="sender" /> or <paramref name="e" /> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     Thrown, if <paramref name="sender" /> is not of type BackgroundWorker.
        /// </exception>
        /// <exception cref="NotSupportedException">
        ///     Thrown, if <see cref="Path" /> is not set before this function is called
        ///     - or - if <see cref="Path" /> contains a colon anywhere other than as part of a
        ///     volume identifier ("C:\").
        /// </exception>
        /// <exception cref="System.Security.SecurityException">
        ///     Thrown, if the permissions for accessing the full path are missing.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     Thrown, if <see cref="Path" /> is too long.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     Thrown, if permissions to create the directory are missing.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     Thrown, if the directory was not found.
        ///     For example because it is on an unmapped device.
        /// </exception>
        /// <exception cref="IOException">
        ///     Thrown, if a file with the name of the dictionary that should be created already exists.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        ///     Thrown, if <see cref="Path" /> is a dictionary.
        /// </exception>
        public void LoadExcelLanguageFileAsync(object sender, DoWorkEventArgs e)
        {
            var bw = sender as BackgroundWorker;

            //null and argument checks.
            ExceptionLoggingUtils.VerifyMultiple(e, nameof(e))
                .AlsoVerify(sender, nameof(sender))
                .ThrowIfNull(_logger, nameof(LoadExcelLanguageFileAsync),
                    "Parameter for DoWork event handler cannot be null.");
            ExceptionLoggingUtils.ThrowIf(bw == null, _logger, new ArgumentException(
                    "Sender for DoWork event handler is not of type BackgroundWorker.", nameof(sender)),
                "LoadExcelLanguageFileAsync functions was called without BackgroundWorker.");
            ExceptionLoggingUtils.ThrowIf(Path == null, _logger,
                new NotSupportedException("Path property for DoWork event handler was not set."),
                "LoadExcelLanguageFileAsync functions was called without Path property being set beforehand.");

            _logger.Log(LogLevel.Trace, "LoadExcelLanguageFileAsync functions was called by BackgroundWorker.");

            VerifyPath(Path);
            LoadExcelLanguageFileAsyncInternal(bw, e, Path);
        }