private ApplicationVersion GetOnlineVersion() { _logger.Debug("Get online Version"); var url = _updateInformationProvider.UpdateInfoUrl; var sectionName = _updateInformationProvider.SectionName; using (var webClient = new WebClient()) { var contents = webClient.DownloadString(url); using (var stream = CreateStreamFromString(contents)) { _logger.Debug("Loading update-info.txt"); var data = Data.CreateDataStorage(); var iniStorage = new IniStorage(); iniStorage.SetData(data); iniStorage.ReadData(stream, true); var onlineVersion = new Version(iniStorage.Data.GetValue(sectionName + "\\Version")); var downloadUrl = iniStorage.Data.GetValue(sectionName + "\\DownloadUrl"); var fileHash = iniStorage.Data.GetValue(sectionName + "\\FileHash"); _logger.Info("Online Version: " + onlineVersion); return(new ApplicationVersion(onlineVersion, downloadUrl, fileHash)); } } }
public void SaveToInfFile(JobInfo jobInfo) { if (string.IsNullOrEmpty(jobInfo.InfFile)) { throw new InvalidOperationException("The inf file must not be empty"); } var infData = Data.CreateDataStorage(); var ini = new IniStorage(Encoding.GetEncoding("Unicode")); ini.SetData(infData); var sourceFileReader = new SourceFileInfoDataReader(); var sectionId = 0; foreach (var sourceFileInfo in jobInfo.SourceFiles) { var section = sectionId.ToString(CultureInfo.InvariantCulture) + "\\"; sourceFileReader.WriteSourceFileInfoToData(infData, section, sourceFileInfo); sectionId++; } ini.WriteData(jobInfo.InfFile); }
private void TestTokensInTranslation(Data englishTranslationData, Language language) { Data translationData = Data.CreateDataStorage(); IniStorage iniStorage = new IniStorage(); iniStorage.SetData(translationData); iniStorage.ReadData(Path.Combine(_languagePath, language.FileName), true); Translator trans = new BasicTranslator(language.CommonName, translationData); foreach (var section in englishTranslationData.GetSubSections("")) { if (section.StartsWith("General")) { continue; } var values = englishTranslationData.GetValues(section); foreach (var keyValuePair in values) { string translation = trans.GetRawTranslation(section.TrimEnd('\\'), keyValuePair.Key); if (translation != "") { ValidateSingleTranslation(keyValuePair.Value, translation, language, section + keyValuePair.Key); } } } }
private void ReadInf(string infFile, TitleReplacer titleReplacer) { InfFile = infFile; var infData = Data.CreateDataStorage(); var ini = new IniStorage(Helper.EncodingHelper.GetEncoding(infFile)); ini.SetData(infData); ini.ReadData(infFile); foreach (var section in infData.GetSections()) { var sfi = SourceFileInfo.ReadSourceFileInfo(infFile, infData, section); if (sfi != null) { SourceFiles.Add(sfi); } } Metadata = new Metadata(); if (SourceFiles.Count > 0) { Metadata.PrintJobAuthor = SourceFiles[0].Author; Metadata.PrintJobName = titleReplacer.Replace(SourceFiles[0].DocumentTitle); Metadata.Title = ""; //Set to avoid null exception when replacing tokens Metadata.Author = ""; JobType = SourceFiles[0].Type; } }
private void TestLanguage(Language lang) { Data translationData = Data.CreateDataStorage(); IniStorage iniStorage = new IniStorage(); iniStorage.SetData(translationData); iniStorage.ReadData(Path.Combine(_languagePath, lang.FileName), true); Translator trans = new BasicTranslator(lang.CommonName, translationData); trans.TranslationError += trans_TranslationError; // Do some work to include all resources as we do not have our WPF app context here EnsureApplicationResources(); var args = new Dictionary <Type, object[]>(); // Everything with the type "Window" is tested automatically. If special parameters are needed for a type, they can be declared here args.Add(typeof(EditEmailTextWindow), new object[] { false }); args.Add(typeof(EncryptionPasswordsWindow), new object[] { EncryptionPasswordMiddleButton.Remove, true, true }); args.Add(typeof(FtpPasswordWindow), new object[] { FtpPasswordMiddleButton.Remove }); args.Add(typeof(MessageWindow), new object[] { "", "", MessageWindowButtons.YesLaterNo, MessageWindowIcon.PDFCreator }); args.Add(typeof(ProfileSettingsWindow), new object[] { new PdfCreatorSettings(new IniStorage()), new GpoSettings() }); args.Add(typeof(RecommendPdfArchitectWindow), new object[] { false }); args.Add(typeof(SignaturePasswordWindow), new object[] { PasswordMiddleButton.Skip, null }); args.Add(typeof(SmtpPasswordWindow), new object[] { SmtpPasswordMiddleButton.Remove }); args.Add(typeof(UpdateDownloadWindow), new object[] { null }); TestWindows(trans, lang, args); TestActionControls(trans, lang); Assert.IsEmpty(trans.TranslationErrors, "There were errors while translating the forms"); }
public void AllWindows_WhenTranslatedWithAllLanguages_DoNotThrowExceptions(string translation) { var lang = GetLanguage(translation); var translationData = Data.CreateDataStorage(); var iniStorage = new IniStorage(); iniStorage.SetData(translationData); var translationFile = Path.Combine(_languagePath, lang.FileName); iniStorage.ReadData(translationFile, true); var exceptionTranslator = new ExceptionTranslator(_translationProxy); _translationProxy.Translator = new BasicTranslator(lang.CommonName, translationData); _translationProxy.LoadOldSectionNames(translationFile); // Do some work to include all resources as we do not have our WPF app context here EnsureApplicationResources(); var container = BuildContainer(); LoggingHelper.InitConsoleLogger("TranslationTest", LoggingLevel.Off); var settingsProvider = container.GetInstance <ISettingsProvider>(); settingsProvider.Settings.Returns(new PdfCreatorSettings(new IniStorage())); settingsProvider.GpoSettings.Returns(new GpoSettingsDefaults()); // Everything with the type "Window" is tested automatically. If special parameters are needed for a type, they can be declared here TestWindows(_translationProxy, lang, container); TestActionControls(_translationProxy, lang, container); Assert.IsEmpty(exceptionTranslator.TranslationErrors, "There were errors while translating the forms"); }
private Data ReadEnglishTranslation() { using (var stream = GenerateStreamFromString(TranslationResources.English)) { var data = Data.CreateDataStorage(); var iniStorage = new IniStorage(); iniStorage.SetData(data); iniStorage.ReadData(stream, clear: true); return(data); } }
public void AllLanguages_ContainSameTokensAsEnglish(string translation) { // These translations contain something that looks like a token, but it is okay if they do not match var exceptions = new[] { "pdfforge.PDFCreator.UI.Views.ActionControls.UserTokenActionControl\\DescriptionText.Text" }; var englishLanguage = _translations.First(x => x.CommonName.Equals("English", StringComparison.InvariantCultureIgnoreCase)); var englishTranslationData = Data.CreateDataStorage(); var iniStorage = new IniStorage(); iniStorage.SetData(englishTranslationData); iniStorage.ReadData(Path.Combine(_languagePath, englishLanguage.FileName), true); var lang = GetLanguage(translation); var translationData = Data.CreateDataStorage(); var translatedIni = new IniStorage(); translatedIni.SetData(translationData); translatedIni.ReadData(Path.Combine(_languagePath, lang.FileName), true); ITranslator trans = new BasicTranslator(lang.CommonName, translationData); foreach (var section in englishTranslationData.GetSubSections("")) { if (section.StartsWith("General")) { continue; } var values = englishTranslationData.GetValues(section); foreach (var keyValuePair in values) { if (exceptions.Contains(section + keyValuePair.Key)) { continue; } var translatedString = trans.GetTranslation(section.TrimEnd('\\'), keyValuePair.Key); if (translatedString != "") { ValidateSingleTranslation(keyValuePair.Value, translatedString, lang, section + keyValuePair.Key); } } } }
public void LoadOldSectionNames(string languageFile) { var iniReader = new IniStorage(Encoding.UTF8); var data = Data.CreateDataStorage(); iniReader.SetData(data); iniReader.ReadData(languageFile); _sectionNames = data.GetSections() .Where(section => section.Contains(".")) .Select(section => section.TrimEnd('\\')) .ToList(); }
public void AllLanguages_ContainSameTokensAsEnglish() { var englishLanguage = _translations.First(x => x.CommonName.Equals("English", StringComparison.InvariantCultureIgnoreCase)); Data englishTranslationData = Data.CreateDataStorage(); IniStorage iniStorage = new IniStorage(); iniStorage.SetData(englishTranslationData); iniStorage.ReadData(Path.Combine(_languagePath, englishLanguage.FileName), true); foreach (Language lang in _translations) { if (lang != englishLanguage) { TestTokensInTranslation(englishTranslationData, lang); } } }
private JobInfo ReadFromInfFile(string infFile, TitleReplacer titleReplacer) { var jobInfo = new JobInfo(); jobInfo.InfFile = infFile; var infData = Data.CreateDataStorage(); var ini = new IniStorage(Encoding.GetEncoding("Unicode")); ini.SetData(infData); ini.ReadData(infFile); var sourceFiles = new List <SourceFileInfo>(); var sourceFileReader = new SourceFileInfoDataReader(); foreach (var section in infData.GetSections()) { var sfi = sourceFileReader.ReadSourceFileInfoFromData(infFile, infData, section); if (sfi != null) { sourceFiles.Add(sfi); } } jobInfo.SourceFiles = sourceFiles; var metadata = new Metadata(); if (sourceFiles.Count > 0) { metadata.PrintJobAuthor = sourceFiles[0].Author; metadata.PrintJobName = titleReplacer.Replace(sourceFiles[0].DocumentTitle); metadata.Title = ""; //Set to avoid null exception when replacing tokens metadata.Author = ""; metadata.Subject = ""; metadata.Keywords = ""; jobInfo.JobType = sourceFiles[0].Type; } jobInfo.Metadata = metadata; return(jobInfo); }
private JobInfo ReadFromInfFile(string infFile, TitleReplacer titleReplacer) { var jobInfo = new JobInfo(); jobInfo.InfFile = infFile; var infData = Data.CreateDataStorage(); var ini = new IniStorage(Encoding.GetEncoding("Unicode")); ini.SetData(infData); ini.ReadData(infFile); var sourceFiles = new ObservableCollection <SourceFileInfo>(); var sourceFileReader = new SourceFileInfoDataReader(); foreach (var section in infData.GetSections()) { var sfi = sourceFileReader.ReadSourceFileInfoFromData(infFile, infData, section); if (sfi != null) { sourceFiles.Add(sfi); } } jobInfo.SourceFiles = sourceFiles; var metadata = new Metadata(); if (sourceFiles.Count > 0) { metadata.PrintJobAuthor = sourceFiles[0].Author; metadata.PrintJobName = titleReplacer.Replace(sourceFiles[0].DocumentTitle); jobInfo.JobType = sourceFiles[0].Type; } jobInfo.Metadata = metadata; jobInfo.PrintDateTime = File.GetCreationTime(infFile); return(jobInfo); }
/// <summary> /// Save the inf file to the path from the InfFile property /// </summary> public void SaveInf() { if (string.IsNullOrEmpty(InfFile)) { throw new InvalidOperationException("The inf file must not be empty"); } var infData = Data.CreateDataStorage(); var ini = new IniStorage(Encoding.GetEncoding("Unicode")); ini.SetData(infData); var sectionId = 0; foreach (var sourceFileInfo in SourceFiles) { sourceFileInfo.WriteSourceFileInfo(infData, sectionId.ToString(CultureInfo.InvariantCulture) + "\\"); sectionId++; } ini.WriteData(InfFile); }