public static Warn ( object message ) : void | ||
message | object | |
Результат | void |
static string Format(string formatstring, object[] formatitems) { try { return(String.Format(StringParser.Parse(formatstring), formatitems)); } catch (FormatException ex) { LoggingService.Warn(ex); StringBuilder b = new StringBuilder(StringParser.Parse(formatstring)); foreach (object formatitem in formatitems) { b.Append("\nItem: "); b.Append(formatitem); } return(b.ToString()); } }
/// <summary> /// Retrieves a single element from this Properties-container. /// </summary> /// <param name="key">Key of the item to retrieve</param> /// <param name="defaultValue">Default value to be returned if the key is not present.</param> public T Get<T>(string key, T defaultValue) { lock (syncRoot) { object val; if (dict.TryGetValue(key, out val)) { try { return (T)Deserialize(val, typeof(T)); } catch (SerializationException ex) { LoggingService.Warn(ex); return defaultValue; } } else { return defaultValue; } } }
public void Load() { string currentLanguage = service.currentLanguage; string logMessage = "Loading resources " + baseResourceName + "." + currentLanguage + ": "; ResourceManager manager = null; if (assembly.GetManifestResourceInfo(baseResourceName + "." + currentLanguage + ".resources") != null) { LoggingService.Info(logMessage + " loading from main assembly"); manager = new ResourceManager(baseResourceName + "." + currentLanguage, assembly); } else if (currentLanguage.IndexOf('-') > 0 && assembly.GetManifestResourceInfo(baseResourceName + "." + currentLanguage.Split('-')[0] + ".resources") != null) { LoggingService.Info(logMessage + " loading from main assembly (no country match)"); manager = new ResourceManager(baseResourceName + "." + currentLanguage.Split('-')[0], assembly); } else { // try satellite assembly manager = TrySatellite(currentLanguage); if (manager == null && currentLanguage.IndexOf('-') > 0) { manager = TrySatellite(currentLanguage.Split('-')[0]); } } if (manager == null) { LoggingService.Warn(logMessage + "NOT FOUND"); } else { if (isIcons) { service.localIconsResMgrs.Add(manager); } else { service.localStringsResMgrs.Add(manager); } } }
/// <summary> /// Shows an error. /// If <paramref name="ex"/> is null, the message is shown inside /// a message box. /// Otherwise, the custom error reporter is used to display /// the exception error. /// </summary> public static void ShowError(Exception ex, string message) { if (message == null) { message = string.Empty; } if (ex != null) { LoggingService.Error(message, ex); LoggingService.Warn("Stack trace of last error log:\n" + Environment.StackTrace); if (CustomErrorReporter != null) { CustomErrorReporter(ex, message); return; } } else { LoggingService.Error(message); } ServiceManager.MessageService.ShowError(ex, message); }
/// <summary> /// Installs the AddIns from AddInInstallTemp to the UserAddInPath. /// In case of installation errors, a error message is displayed to the user /// and the affected AddIn is added to the disabled list. /// </summary> public static void InstallAddIns(List <string> disabled) { if (!Directory.Exists(addInInstallTemp)) { return; } LoggingService.Info("AddInManager.InstallAddIns started"); if (!Directory.Exists(userAddInPath)) { Directory.CreateDirectory(userAddInPath); } string removeFile = Path.Combine(addInInstallTemp, "remove.txt"); bool allOK = true; List <string> notRemoved = new List <string>(); if (File.Exists(removeFile)) { using (StreamReader r = new StreamReader(removeFile)) { string addInName; while ((addInName = r.ReadLine()) != null) { addInName = addInName.Trim(); if (addInName.Length == 0) { continue; } string targetDir = Path.Combine(userAddInPath, addInName); if (!UninstallAddIn(disabled, addInName, targetDir)) { notRemoved.Add(addInName); allOK = false; } } } if (notRemoved.Count == 0) { LoggingService.Info("Deleting remove.txt"); File.Delete(removeFile); } else { LoggingService.Info("Rewriting remove.txt"); using (StreamWriter w = new StreamWriter(removeFile)) { notRemoved.ForEach(w.WriteLine); } } } foreach (string sourceDir in Directory.GetDirectories(addInInstallTemp)) { string addInName = Path.GetFileName(sourceDir); string targetDir = Path.Combine(userAddInPath, addInName); if (notRemoved.Contains(addInName)) { LoggingService.Info("Skipping installation of " + addInName + " because deinstallation failed."); continue; } if (UninstallAddIn(disabled, addInName, targetDir)) { LoggingService.Info("Installing " + addInName + "..."); Directory.Move(sourceDir, targetDir); } else { allOK = false; } } if (allOK) { try { Directory.Delete(addInInstallTemp, false); } catch (Exception ex) { LoggingService.Warn("Error removing install temp", ex); } } LoggingService.Info("AddInManager.InstallAddIns finished"); }
/// <summary> /// Shows a warning message. /// </summary> public static void ShowWarning(string message) { LoggingService.Warn(message); ServiceManager.MessageService.ShowWarning(message); }
/// <summary> /// Shows an exception. /// </summary> public static void ShowException(Exception ex, string message) { LoggingService.Error(message, ex); LoggingService.Warn("Stack trace of last exception log:\n" + Environment.StackTrace); ServiceManager.Instance.MessageService.ShowException(ex, message); }