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));
                }
            }
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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);
                    }
                }
            }
        }
Beispiel #4
0
        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");
        }
Beispiel #5
0
        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);
     }
 }
Beispiel #7
0
        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();
        }
        private async Task <IApplicationVersion> LoadOnlineVersionAsyncInternal(bool forceDownload = false, bool onlyCache = false)
        {
            _logger.Debug("Get online Version");

            var url         = _updateInformationProvider.UpdateInfoUrl;
            var sectionName = _updateInformationProvider.SectionName;

            try
            {
                var contents = await RetrieveFileFromCacheOrUrl(url, "update-info.txt", forceDownload);

                using (var stream = CreateStreamFromString(contents))
                {
                    _logger.Debug("Loading update-info.txt");
                    var data       = Data.CreateDataStorage();
                    var iniStorage = new IniStorage("");
                    iniStorage.ReadData(stream, data);

                    var onlineVersion = new System.Version(data.GetValue(sectionName + "\\Version"));
                    var downloadUrl   = data.GetValue(sectionName + "\\DownloadUrl");
                    var fileHash      = data.GetValue(sectionName + "\\FileHash");
                    _logger.Info("Online Version: " + onlineVersion);

                    var versionsInfo       = new List <Release>();
                    var applicationVersion = _versionHelper.ApplicationVersion;

                    if (applicationVersion.CompareTo(onlineVersion) < 0)
                    {
                        var downloadString = await RetrieveFileFromCacheOrUrl(_updateInformationProvider.ChangeLogUrl, "Releases.json", forceDownload);

                        var availableInfos = _changeParser.Parse(downloadString);
                        versionsInfo = availableInfos.FindAll(release => release.Version > applicationVersion);

                        CurrentReleaseVersion = availableInfos.FirstOrDefault(x => x.Version.IsEqualToCurrentVersion(applicationVersion));
                    }

                    _onlineVersion = new ApplicationVersion(onlineVersion, downloadUrl, fileHash, versionsInfo);
                }
            }
            catch (Exception e)
            {
                _logger.Warn(e.Message);

                _onlineVersion = new ApplicationVersion(new System.Version(0, 0, 0), "", "", new List <Release>());
            }

            return(_onlineVersion);
        }
Beispiel #10
0
        private JobInfo ReadFromInfFile(string infFile, TitleReplacer titleReplacer)
        {
            var jobInfo = new JobInfo();

            jobInfo.InfFile = infFile;
            var infData = Data.CreateDataStorage();
            var ini     = new IniStorage(jobInfo.InfFile, Encoding.GetEncoding("Unicode"));

            ini.ReadData(infData);

            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.OriginalFilePath    = sourceFiles[0].OriginalFilePath;
                jobInfo.PrinterName         = sourceFiles[0].PrinterName;
                jobInfo.PrinterParameter    = sourceFiles[0].PrinterParameter;
                jobInfo.ProfileParameter    = sourceFiles[0].ProfileParameter;
                jobInfo.OutputFileParameter = sourceFiles[0].OutputFileParameter;

                jobInfo.JobType = sourceFiles[0].Type;
            }

            ConsiderStoredParameters(jobInfo);

            jobInfo.Metadata = metadata;

            jobInfo.PrintDateTime = File.GetCreationTime(infFile);

            return(jobInfo);
        }
Beispiel #11
0
        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);
        }