/// <summary>Deserialize the theme from a file path.</summary> /// <param name="filePath">The file path.</param> /// <returns>The <see cref="Theme" />.</returns> public static Theme Deserialize(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ArgumentMessages.IsNullOrEmpty()); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ArgumentMessages.FileNotFound(filePath)); } Theme _theme = null; try { XDocument themeDocument = XDocument.Load(filePath); _theme = Deserialize(themeDocument); } catch (Exception e) { Logger.WriteDebug(e); } return(_theme); }
/// <summary>Loads the <see cref="Theme" /> from the file path.</summary> /// <param name="filePath">The file path.</param> public void Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ArgumentMessages.IsNullOrEmpty()); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ArgumentMessages.FileNotFound(filePath)); } try { if (File.Exists(filePath)) { Theme theme = ThemeSerialization.Deserialize(filePath); UpdateTheme(theme.Information, theme.ColorPalette); } else { Logger.WriteDebug(new FileNotFoundException(ArgumentMessages.FileNotFound(filePath))); } } catch (Exception e) { Logger.WriteDebug(e); } }
/// <summary>Determines whether the font is installed on the system.</summary> /// <param name="fontName">The font name.</param> /// <returns>The <see cref="bool" />.</returns> public static bool FontInstalled(string fontName) { if (string.IsNullOrEmpty(fontName)) { throw new ArgumentNullException(ArgumentMessages.IsNullOrEmpty()); } return(InstalledFonts().Any(_fontFamily => _fontFamily.Name == fontName)); }
/// <summary>Loads the <see cref="Assembly" /> from a file.</summary> /// <param name="filePath">The file path.</param> /// <returns>The <see cref="Assembly" />.</returns> public static Assembly LoadAssembly(string filePath) { if (string.IsNullOrEmpty(filePath)) { Logger.WriteDebug(new NoNullAllowedException(ArgumentMessages.IsNullOrEmpty())); } if (!File.Exists(filePath)) { Logger.WriteDebug(new NoNullAllowedException(ArgumentMessages.FileNotFound(filePath))); } return(Assembly.LoadFile(filePath)); }
public static void IsNullOrWhiteSpace(string value, string message = "") { if (Guard.IsNullOrWhitespace(value)) { if (Guard.IsNullOrEmpty(message)) { throw new ArgumentException(ArgumentMessages.IsNullOrWhitespace()); } else { throw new ArgumentException(message); } } }
public static void IsNullOrEmpty(string value, string message = "") { if (Guard.IsNullOrEmpty(value)) { if (Guard.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(value), ArgumentMessages.IsNullOrEmpty()); } else { throw new ArgumentNullException(nameof(value), message); } } }
public static void IsNull <T>(T source, string message = "") where T : class { if (Guard.IsNull(source)) { if (Guard.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(source), ArgumentMessages.IsNull(source)); } else { throw new ArgumentNullException(nameof(source), message); } } }
public static void IsInvalidOperation(bool condition, string message = "") { if (condition) { if (Guard.IsNullOrEmpty(message)) { throw new InvalidOperationException(ArgumentMessages.IsInvalidOperation()); } else { throw new InvalidOperationException(message); } } }
/// <summary>Initializes a new instance of the <see cref="Theme" /> class.</summary> /// <param name="filePath">The file.</param> public Theme(string filePath) : this() { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ArgumentMessages.IsNullOrEmpty()); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ArgumentMessages.FileNotFound(filePath)); } Load(filePath); }
/// <summary>Saves the theme to a file.</summary> /// <param name="filePath">The file path.</param> public void Save(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ArgumentMessages.IsNullOrEmpty()); } _rawTheme = ThemeSerialization.Serialize(this); if (string.IsNullOrEmpty(_rawTheme)) { throw new ArgumentNullException(nameof(_rawTheme)); } XDocument _theme = XDocument.Parse(_rawTheme); _theme.Save(filePath); }
public static void IsValid(bool condition, string message = "", string paramName = "") { if (condition) { if (Guard.IsNullOrEmpty(message)) { if (Guard.IsNullOrEmpty(paramName)) { throw new ArgumentException(ArgumentMessages.IsValidOperation()); } else { throw new ArgumentException(ArgumentMessages.IsValidOperation(), paramName); } } else { throw new ArgumentException(message, paramName); } } }
public static void IsOutOfRange <T>(T value, T minimum, T maximum, string message = "", string paramName = "") where T : struct, IComparable <T> { if (Guard.IsOutOfRange(value, minimum, maximum)) { if (Guard.IsNullOrEmpty(paramName)) { if (Guard.IsNullOrEmpty(message)) { throw new ArgumentOutOfRangeException(nameof(value), ArgumentMessages.IsOutOfRangeException(value, minimum, maximum)); } else { throw new ArgumentOutOfRangeException(nameof(value), message); } } else { throw new ArgumentOutOfRangeException(paramName, message); } } }