public void Download(string targetPath, LanguageSelection selection, bool overwrite, InstallationType installationType, string username, string password) { LogToFile("Downloading " + selection + " files of type " + installationType + " to " + targetPath); bool refresh = _config.NeedsRefresh(selection, installationType); DateTimeOffset refreshedAt = DateTimeOffset.Now; DownloadList downloadList = _downloadListManager.GetEntriesToInstall(targetPath, username, password, selection, installationType, overwrite || refresh); var downloadManager = CreateDownloadManager(targetPath, username, password, selection.Language); downloadManager.DownloadList = downloadList.Missing; downloadManager.InstallationType = installationType; downloadManager.LanguageSelection = selection; LogMessage(TextResources.thereAre + " " + downloadList.Missing.Count + " " + TextResources.newFilesToDownload); downloadManager.Download(); if (InstallationType.CODE.Equals(installationType)) { LogMessage(TextResources.updatingIniFile); _config.CommitEntries(selection, downloadList.All); LogMessage(TextResources.iniFileUpdated); } if (refresh) { _config.UpdateRefresh(selection, installationType, refreshedAt); } }
public DownloadList GetEntriesToInstall(string targetPath, string username, string password, LanguageSelection selection, InstallationType installationType, bool overwrite) { List<PictogramEntry> all = GetCompleteList(username, password, selection.Language, installationType); var missing = overwrite ? all : FilterEntries(targetPath, selection, all, installationType); return new DownloadList(all, missing); }
public PicIni GetPictoIniFile(LanguageSelection selection, InstallationType installationType) { if (InstallationType.SOUND.Equals(installationType)) { return GetPictoWavIniFilePath(selection.Language); } else { return CreatePictoWmfIni(selection); } }
public PicIni CreatePictoWmfIni(LanguageSelection selection) { var languageCode = ""; Language language = selection.Language; if (language != null && !language.IsTextless) { languageCode = language.Code; } var path = Environment.GetEnvironmentVariable("WINDIR") + @"\Pic" + selection.ImageFormat.CapitalizedExtension + languageCode + @".ini"; return new PicIni(path); }
private List<PictogramEntry> FilterEntries(string installPath, LanguageSelection selection, IEnumerable<PictogramEntry> entries, InstallationType installationType) { var newEntries = new List<PictogramEntry>(); foreach (var entry in entries) { var fileName = entry.ToFilename(installationType, selection); var fileInfo = new FileInfo(installPath + @"\" + fileName); if (Files.shouldWriteTo(fileInfo, entry.Modified)) { newEntries.Add(entry); } } return newEntries; }
internal void downloadImage(string Username, string Password, string pictogramCode, string languageCode, InstallationType installationType, LanguageSelection selection, Stream output) { int size = 500; if (selection.IsVectorFormat) { size = 96; } string url = "/languages/" + languageCode + "/pictograms/" + pictogramCode + "/images/" + size + "." + selection.ImageFormat.Extension; if (InstallationType.TEXTLESS.Equals(installationType)) { url += "?textless=true"; } dynamic client = createRestClient(url, RestService.Binary).withCredentials(new NetworkCredential(Username, Password)); dynamic operation = client.get(); if (operation.Error != null) { throw operation.Error as Exception; } operation.Result.CopyTo(output); }
private string GetLastRefreshKey(LanguageSelection selection, InstallationType installationType) { switch (installationType) { case InstallationType.PLAIN_TEXT: return "PlainTextRefresh"; case InstallationType.TEXTLESS: return "TextlessRefresh"; case InstallationType.SOUND: return "SoundRefresh"; case InstallationType.CODE: /* fall-through */ default: return "DirRefresh"; } }
private string GetDefaultTextlessDir(LanguageSelection selection) { string language = ""; if (!selection.Language.IsTextless) { language = selection.LanguageCode; } return @"C:\Picto\" + selection.CapitalizedExtension + language + " " + TextResources.withoutText; }
private void CreateNewIniFile(LanguageSelection selection) { var info = this.iniFileFactory.CreatePictoWmfIni(selection).ToFileInfo(); info.Create().Close(); }
public void UpdateRefresh(LanguageSelection selection, InstallationType installationType, DateTimeOffset refreshedAt) { string key = GetLastRefreshKey(selection, installationType); Profile settings = this.iniFileFactory.GetPictoIniFile(selection, installationType).ToIni(); settings.SetValue("ProgDir", key, refreshedAt); }
public void CommitEntries(LanguageSelection selection, List<PictogramEntry> entries) { Profile profile = this.iniFileFactory.CreatePictoWmfIni(selection).ToIni(); Language language = selection.Language; var categoryCounts = new Dictionary<Category, int>(); foreach (var entry in entries) { var category = this.categoryRepository.FindByCode(entry.CategoryCode); var categoryCount = 0; var categoryTranslation = this.categoryTranslationService.Translate(category, language); if (categoryCounts.ContainsKey(category)) { categoryCount = categoryCounts[category]; } profile.SetValue(categoryTranslation, entry.FullCode, entry.Name); categoryCount++; categoryCounts[category] = categoryCount; } foreach (var category in categoryCounts.Keys) { profile.SetValue(categoryTranslationService.Translate(category, language), "Antal", categoryCounts[category]); } }
/// <summary> /// Should be refactored to use proper dependency injection. /// </summary> private void createDependencyGraph() { this.fileLogger = new FileLogger(); this._languageSelection = new LanguageSelection(); this._authenticationService = new AuthenticationService(); this.categoryRepository = new CategoryRepository(); this.categoryTranslationService = new CategoryTranslationService(); this.pictogramRestService = new PictogramRestService("www.pictogram.se"); this.languageProvider = new LanguageProvider(this.pictogramRestService); this.iniFileFactory = new IniFileFactory(); this.config = new Config(this.categoryRepository, this.categoryTranslationService, this.iniFileFactory); this.downloadManager = new DownloadManager(this.languageProvider, this.pictogramRestService); this.downloadListManager = new DownloadListManager(this.pictogramRestService); this.installationManager = new InstallationManager(this.config, this.downloadListManager, this.languageProvider, this.pictogramRestService); this.imageFormatProvider = new ImageFormatProvider(); this.hargdata = new HargdataProducts(); }
public string getInstallPathForLanguage(LanguageSelection selection, InstallationType installationType) { switch (installationType) { case InstallationType.PLAIN_TEXT: return GetPictoPlainTextInstallPath(selection); case InstallationType.SOUND: return GetPictoSoundInstallPath(selection.Language); case InstallationType.TEXTLESS: return GetTextLessInstallPath(selection); case InstallationType.CODE: /* fall-through */ default: return GetPictoInstallPath(selection); } }
public string GetDefaultPlainTextPath(LanguageSelection selection) { return @"C:\Picto\" + selection.ImageFormat.CapitalizedExtension + selection.LanguageCode + " " + TextResources.inPlainText; }
public string GetDefaultPath(LanguageSelection selection) { return @"C:\Picto\" + selection.CapitalizedExtension + selection.LanguageCode; ; }
public void CreateOrUpdateWmfIni(LanguageSelection selection, string installPath, string plainTextInstallPath) { Language language = selection.Language; if (!IsPictoWmfInstalled(selection)) { CreateNewIniFile(selection); } /* WmfIni */ PicIni picWmf = this.iniFileFactory.CreatePictoWmfIni(selection); Profile profile = picWmf.ToIni(); try { if (!language.IsTextless) { profile.SetValue("ProgDir", "Dir", installPath); } /* Extension in ini file should be all upper case. */ string extension = selection.ImageFormat.AllCapsExtension; safeWriteToProfile(profile, "ProgDir", "Extension", extension); if (!language.IsTextless) { safeWriteToProfile(profile, "ProgDir", "lang" + extension, language.Code); } safeWriteToProfile(profile, "ProgDir", "ver" + extension, "7.0"); safeWriteToProfile(profile, "ProgDir", "CD", "-"); safeWriteToProfile(profile, "ProgDir", "IDNAME", ""); // Place PlainTextDir last in section. if (!language.IsTextless) { profile.SetValue("ProgDir", "PlainTextDir", plainTextInstallPath); } profile.SetValue("ProgDir", "TextlessDir", language.IsTextless ? installPath : GetTextLessInstallPath(selection)); } catch (System.ComponentModel.Win32Exception e) { throw new UnauthorizedAccessException("Access to the path '" + picWmf.Path + "' is denied.", e); } UpdateCategories(profile, language); }
/// <summary> /// A generic picwmf.ini (without language in the name) is required for Pictogram Manager. /// </summary> /// <param name="language"></param> public void CreateGenericPicWmfIni(LanguageSelection selection) { PicIni picIni = this.iniFileFactory.CreatePictoWmfIni(selection); var withoutLanguage = new LanguageSelection(); withoutLanguage.ImageFormat = selection.ImageFormat; withoutLanguage.Language = null; PicIni picGeneric = this.iniFileFactory.CreatePictoWmfIni(withoutLanguage); var picGenericFile = picGeneric.ToFileInfo(); /* Rescue some values from file that will be overwritten */ if (picGenericFile.Exists) { Ini ini = picIni.ToIni(); ini.SetValue("ProgDir", "TextlessRefresh", picGeneric.ToIni().GetValue("ProgDir", "TextlessRefresh", "")); ini.SetValue("ProgDir", "TextlessDir", picGeneric.ToIni().GetValue("ProgDir", "TextlessDir", "")); } /* Only overwrite the generic file with the Swedish file, or create new file in any language. */ if (selection.Language.IsSwedish || !picGenericFile.Exists) { picIni.ToFileInfo().CopyTo(picGenericFile.FullName, true); } }
private string GetPictoInstallPath(LanguageSelection selection) { Language language = selection.Language; if (language.IsTextless) { return GetTextLessInstallPath(selection); } Profile settings = this.iniFileFactory.CreatePictoWmfIni(selection).ToIni(); var path = settings.GetValue("ProgDir", "Dir") as string; if (string.IsNullOrWhiteSpace(path)) { return GetDefaultPath(selection); } return path; }
private string GetPictoPlainTextInstallPath(LanguageSelection selection) { Profile settings = this.iniFileFactory.CreatePictoWmfIni(selection).ToIni(); var path = settings.GetValue("ProgDir", "PlainTextDir") as string; if (string.IsNullOrWhiteSpace(path)) { return GetDefaultPlainTextPath(selection); } return path; }
public String GetTextLessInstallPath(LanguageSelection selection) { Profile settings = this.iniFileFactory.CreatePictoWmfIni(selection).ToIni(); var path = settings.GetValue("ProgDir", "TextlessDir") as string; if (string.IsNullOrWhiteSpace(path)) { return GetDefaultTextlessDir(selection); } return path; }
/// <summary> /// Laddar ner pictogram som saknas. Avsett att köras i egen tråd. /// </summary> private void Download() { ClearDownloadLog(""); SetControlsEnabled(false); if (!this.downloadManager.checkLogin(this.usernameTextbox.Text, this.passwordTextbox.Text)) { if (this._authenticationService.UseFreeAccount) { /* "Please download new version." */ ShowError(TextResources.errorDownloadNew); } else { /* "Check username and password" */ ShowError(TextResources.errorLoginFailed); } DownloadFinished(); return; } try { var language = _languageSelection.Language; LogToFile("Updating ini file with paths " + wmfDirectoryChooser.InstallPath + ", " + plainTextDirectoryChooser.InstallPath); config.CreateOrUpdateWmfIni(_languageSelection, wmfDirectoryChooser.InstallPath, plainTextDirectoryChooser.InstallPath); LogMessage(TextResources.lookingForNewImages); if (language.IsTextless) { installationManager.Download(wmfDirectoryChooser.InstallPath, _languageSelection, overwriteCheckbox.Checked, InstallationType.TEXTLESS, usernameTextbox.Text, passwordTextbox.Text); } else { installationManager.Download(wmfDirectoryChooser.InstallPath, _languageSelection, overwriteCheckbox.Checked, InstallationType.CODE, usernameTextbox.Text, passwordTextbox.Text); } LogMessage(TextResources.downloadComplete); LogMessage(""); if (plainTextCheckbox.Checked) { LogMessage(TextResources.lookingForNewImagesWithText); installationManager.Download(plainTextDirectoryChooser.InstallPath, _languageSelection, overwriteCheckbox.Checked, InstallationType.PLAIN_TEXT, usernameTextbox.Text, passwordTextbox.Text); /* "Nedladdning av pictobilder i klartext klar." */ LogMessage(TextResources.downloadPlainTextComplete); LogMessage(""); } if (textlessCheckBox.Checked) { LogMessage(TextResources.lookingForNewImagesWithoutText); installationManager.Download(textlessDirectoryChooser.InstallPath, _languageSelection, overwriteCheckbox.Checked, InstallationType.TEXTLESS, usernameTextbox.Text, passwordTextbox.Text); LogMessage(TextResources.downloadTextlessComplete); LogMessage(""); } if (soundCheckbox.Checked) { LogMessage(TextResources.lookingForNewSounds); installationManager.Download(soundDirectoryChooser.InstallPath, _languageSelection, overwriteCheckbox.Checked, InstallationType.SOUND, usernameTextbox.Text, passwordTextbox.Text); config.CreateOrUpdateWavIni(language, soundDirectoryChooser.InstallPath); LogMessage(TextResources.downloadSoundsComplete); LogMessage(""); } if (_languageSelection.Language.IsSwedish) { if (hargdata.IsSymWriterInstalled) { LogMessage("Installerar bilder för SymWriter..."); LanguageSelection ls = new LanguageSelection(Language.SWEDISH, ImageFormat.SVG); installationManager.Download(hargdata.SymWriterImagesDirectory, ls, overwriteCheckbox.Checked, InstallationType.TEXTLESS, usernameTextbox.Text, passwordTextbox.Text); LogMessage("Installerar ordlista för SymWriter..."); LogToFile("Installerar ordlista för SymWriter till " + hargdata.SymWriterDictionaryDirectory); hargdata.InstallSymWriterDictionary(); LogMessage(""); } else { LogToFile("Will not install SymWriter dictionary. Application not installed. SymWriter xml path from registry is " + hargdata.SymWriterDirectoriesXmlPath); } if (hargdata.IsWidgitInstalled) { LogMessage("Installerar bilder för Widgit Symbolskrift..."); LanguageSelection ls = new LanguageSelection(Language.SWEDISH, ImageFormat.JPG); installationManager.Download(hargdata.WidgitImagesDirectory, ls, overwriteCheckbox.Checked, InstallationType.PLAIN_TEXT, usernameTextbox.Text, passwordTextbox.Text); LogMessage("Installerar ordlista för Widgit Symbolskrift..."); LogToFile("Installerar ordlista för Widgit Symbolskrift till " + hargdata.WidgitDictionaryPath); hargdata.installWidgitDictionary(); LogMessage(""); } else { LogToFile("Will not install widgit dictionary. Application not installed. Widgit dictionary path from registry is " + hargdata.WidgitDictionaryPath); } if (hargdata.IsCommunicateInstalled) { LogMessage("Installerar bilder för Communicate: In Print"); LanguageSelection ls = new LanguageSelection(Language.SWEDISH, ImageFormat.JPG); installationManager.Download(hargdata.CommunicateImagesDirectory, ls, overwriteCheckbox.Checked, InstallationType.PLAIN_TEXT, usernameTextbox.Text, passwordTextbox.Text); LogMessage("Installerar ordlista för Communicate: In Print..."); LogToFile("Installerar ordlista för Communicate: In Print till " + hargdata.CommunicateDictionaryPath); hargdata.installCommunicateDictionary(); LogMessage(""); } else { LogToFile("Will not install Communicate: In Print dictionary. Application not installed. Dictionary directory from registry is " + hargdata.CommunicateDictionaryPath); } } else { LogToFile("Skipping dictionary installation because language is " + _languageSelection.Language); } config.CreateGenericPicWmfIni(_languageSelection); DownloadFinished(); LogMessage(""); LogMessage(TextResources.installationComplete); SetStatus(TextResources.installationComplete); InstallationFinishedSuccessfully(); } catch (UnauthorizedAccessException e) { LogMessage(TextResources.failedFileAccess + "(" + e.Message + ")"); LogToFile(e.ToString()); } catch (System.Net.WebException e) { LogMessage(TextResources.failedNetworkAccess + "(" + e.Message + ")"); LogToFile(e.ToString()); } }
public bool NeedsRefresh(LanguageSelection selection, InstallationType installationType) { string key = GetLastRefreshKey(selection, installationType); Profile settings = this.iniFileFactory.GetPictoIniFile(selection, installationType).ToIni(); string unparsed = settings.GetValue("ProgDir", key) as string; if (string.IsNullOrEmpty(unparsed)) { return true; } try { DateTimeOffset dto = DateTimeOffset.Parse(unparsed); /* Set to later date to force refresh at a later time. */ DateTimeOffset cutoff = DateTimeOffset.Parse("2013-07-10 21:00:00 +02:00"); if (selection.ImageFormat.IsSvg) { cutoff = DateTimeOffset.Parse("2014-02-05 00:00:00 +02:00"); if (InstallationType.TEXTLESS.Equals(installationType)) { cutoff = DateTimeOffset.Parse("2015-11-28 18:50:00 +01:00"); } } if (dto.CompareTo(cutoff) < 0) { return true; } } catch (FormatException) { return true; } return false; }
public bool IsPictoWmfInstalled(LanguageSelection selection) { var picWmf = this.iniFileFactory.CreatePictoWmfIni(selection); return picWmf.Exists; }
/// <summary> /// Should be refactored to use proper dependency injection. /// </summary> private void createDependencyGraph() { this._languageSelection = new LanguageSelection(); this._authenticationService = new AuthenticationService(); this.categoryRepository = new CategoryRepository(); this.categoryTranslationService = new CategoryTranslationService(); this.languageProvider = new LanguageProvider(); this.pictosysWebService = new PictosysWebService(); this._config = new Config(this.categoryRepository, this.categoryTranslationService); this.downloadManager = new DownloadManager(this.languageProvider, this.pictosysWebService); this.downloadListManager = new DownloadListManager(this.pictosysWebService); this.installationManager = new InstallationManager(this._config, this.downloadListManager, this.languageProvider, this.pictosysWebService); }