/// <summary> /// Returns the localized values for the given enumeration objects. /// </summary> /// <param name="properties">The <see cref="LocalizationProperties" />-instance to use for the localization.</param> /// <param name="objects">The objects for the localization.</param> /// <returns>Returns the found localizations.</returns> internal static IEnumerable <string> GetLocalizedEnumerationValues(LocalizationProperties properties, object[] objects) { foreach (var o in objects) { var fieldInfo = o.GetType().GetField(o.ToString()); var descriptionAttributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (descriptionAttributes.Length > 0) { var resourceId = descriptionAttributes[0].Description; yield return ((string) properties.GetType() .GetProperties() .First(x => x.Name == resourceId) .GetValue(properties, null)); } else { yield return(o.ToString()); } } }
/// <summary> /// Returns the localized values for the given enumeration objects. /// </summary> /// <param name="properties">The <see cref="LocalizationProperties" />-instance to use for the localization.</param> /// <param name="objects">The objects for the localization.</param> /// <returns>Returns the found localizations.</returns> public static IEnumerable<string> GetLocalizedEnumerationValues(LocalizationProperties properties, Object[] objects) { foreach (var o in objects) { var fieldInfo = o.GetType().GetField(o.ToString()); var descriptionAttributes = (DescriptionAttribute[]) fieldInfo.GetCustomAttributes(typeof (DescriptionAttribute), false); if (descriptionAttributes.Length > 0) { var resourceId = descriptionAttributes[0].Description; yield return (string) properties.GetType() .GetProperties() .First(x => x.Name == resourceId) .GetValue(properties, null); } else { yield return o.ToString(); } } }
private void NoUpdateFoundDialog_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(LanguageFilePath)) { try { _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(LanguageFilePath)); } catch (Exception) { _lp = new LocalizationProperties(); } } else if (String.IsNullOrEmpty(LanguageFilePath) && LanguageName != "en") { string resourceName = String.Format("nUpdate.Core.Localization.{0}.json", LanguageName); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { _lp = Serializer.Deserialize<LocalizationProperties>(stream); } } else if (String.IsNullOrEmpty(LanguageFilePath) && LanguageName == "en") { _lp = new LocalizationProperties(); } closeButton.Text = _lp.CloseButtonText; headerLabel.Text = _lp.NoUpdateDialogHeader; infoLabel.Text = _lp.NoUpdateDialogInfoText; Icon = _appIcon; Text = Application.ProductName; }
private void NewUpdateDialog_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(LanguageFilePath)) { try { _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(LanguageFilePath)); } catch (Exception) { _lp = new LocalizationProperties(); } } else if (String.IsNullOrEmpty(LanguageFilePath) && LanguageName != "en") { string resourceName = String.Format("nUpdate.Core.Localization.{0}.json", LanguageName); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { _lp = Serializer.Deserialize<LocalizationProperties>(stream); } } else if (String.IsNullOrEmpty(LanguageFilePath) && LanguageName == "en") { _lp = new LocalizationProperties(); } headerLabel.Text = String.Format(PackageConfigurations.Count() > 1 ? _lp.NewUpdateDialogMultipleUpdatesHeader : _lp.NewUpdateDialogSingleUpdateHeader, PackageConfigurations.Count()); infoLabel.Text = String.Format(_lp.NewUpdateDialogInfoText, Application.ProductName); var availableVersions = PackageConfigurations.Select(item => new UpdateVersion(item.LiteralVersion)).ToArray(); newestVersionLabel.Text = String.Format(_lp.NewUpdateDialogAvailableVersionsText, PackageConfigurations.Count() <= 2 ? String.Join(", ", availableVersions.Select(item => item.FullText)) : String.Format("{0} - {1}", UpdateVersion.GetLowestUpdateVersion(availableVersions).FullText, UpdateVersion.GetHighestUpdateVersion(availableVersions).FullText)); currentVersionLabel.Text = String.Format(_lp.NewUpdateDialogCurrentVersionText, CurrentVersion.FullText); changelogLabel.Text = _lp.NewUpdateDialogChangelogText; cancelButton.Text = _lp.CancelButtonText; installButton.Text = _lp.InstallButtonText; var size = SizeHelper.ConvertSize(PackageSize); updateSizeLabel.Text = String.Format("{0} {1}", String.Format(_lp.NewUpdateDialogSizeText, size.Item1), size.Item2); Icon = _appIcon; Text = Application.ProductName; iconPictureBox.Image = _appIcon.ToBitmap(); iconPictureBox.BackgroundImageLayout = ImageLayout.Center; foreach (var updateConfiguration in PackageConfigurations) { var versionText = new UpdateVersion(updateConfiguration.LiteralVersion).FullText; var changelogText = updateConfiguration.Changelog.ContainsKey(new CultureInfo(LanguageName)) ? updateConfiguration.Changelog.First(item => item.Key.Name == LanguageName).Value : updateConfiguration.Changelog.First(item => item.Key.Name == "en").Value; if (PackageSize > GB) changelogTextBox.Text += _lp.NewUpdateDialogBigPackageWarning; changelogTextBox.Text += String.Format(String.IsNullOrEmpty(changelogTextBox.Text) ? "{0}:\n{1}" : "\n\n{0}:\n{1}", versionText, changelogText); } AddShieldToButton(installButton); if (OperationAreas == null || OperationAreas.Count == 0) { accessLabel.Text = String.Format("{0} -", _lp.NewUpdateDialogAccessText); _allowCancel = true; return; } accessLabel.Text = String.Format("{0} {1}", _lp.NewUpdateDialogAccessText, String.Join(", ", LocalizationHelper.GetLocalizedEnumerationValues(_lp, OperationAreas.Cast<object>().GroupBy(item => item).Select(item => item.First()).ToArray()))); _allowCancel = true; }
private void Initialize() { if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "nUpdate"))) { try { Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "nUpdate", Application.ProductName)); } catch (Exception ex) { throw new IOException(String.Format(_lp.MainFolderCreationExceptionText, ex.Message)); } } var languageFilePath = CultureFilePaths.Any(item => item.Key.Equals(_languageCulture)) ? CultureFilePaths.First(item => item.Key.Equals(_languageCulture)).Value : null; if (!String.IsNullOrEmpty(languageFilePath)) { try { _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(languageFilePath)); } catch (Exception) { _lp = new LocalizationProperties(); } } else if (String.IsNullOrEmpty(languageFilePath) && _languageCulture.Name != "en") { string resourceName = String.Format("nUpdate.Core.Localization.{0}.json", _languageCulture.Name); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { _lp = Serializer.Deserialize<LocalizationProperties>(stream); } } else if (String.IsNullOrEmpty(languageFilePath) && _languageCulture.Name == "en") { _lp = new LocalizationProperties(); } }