/// <summary> /// Clean up after BackgroundWorker finished. /// Throws Exceptions, but cannot interupt main thread. /// </summary> /// <exception cref="FileFormatException"> /// Thrown, if file at <see cref="Path" /> is not a valid Excel sheet. /// </exception> public void LoadExcelLanguageFileAsyncCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { _logger.Log(LogLevel.Debug, "Loading of the language file was stoped."); } else if (e.Error != null) { if (e.Error.HResult == -2146827284) { ExceptionLoggingUtils.Throw(_logger, new FileFormatException(new Uri(Path), "Expected Excel file format.", e.Error), "File at given path may be corrupted or not have correct format. " + "Expected Excel sheet (.xlsx, .xls, ...)."); } else if (e.Error.GetType() == typeof(CultureNotFoundException)) { _logger.Log(LogLevel.Error, e.Error, "One of the cells in the first row was expected to " + "contain a language code, but did not."); } else { _logger.Log(LogLevel.Error, e.Error, "Unknown error occurred during language file loading."); } } else { _logger.Log(LogLevel.Debug, "BackgroundWorker successfully finished loading the language file."); } }
/// <summary> /// Returns the internal dictionary of translations. /// </summary> /// <exception cref="FileProviderNotInitializedException"> /// Will be thrown if the object has not found a language file to pull translations from. /// </exception> public Dictionary <CultureInfo, Dictionary <string, string> > GetDictionary() { if (Status == ProviderStatus.Empty || Status == ProviderStatus.Initialized) { return(_dictOfDicts); } //ExcelFileProvider is still initializing, cancelling or cancelled. ExceptionLoggingUtils.Throw <FileProviderNotInitializedException>(_logger, "Dictionary was accessed, without ExcelFileProvider being initialized."); throw new NotSupportedException("unreachable code."); }