Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
        /// <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));
        }
Пример #5
0
 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);
         }
     }
 }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
 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);
         }
     }
 }
Пример #8
0
 public static void IsInvalidOperation(bool condition, string message = "")
 {
     if (condition)
     {
         if (Guard.IsNullOrEmpty(message))
         {
             throw new InvalidOperationException(ArgumentMessages.IsInvalidOperation());
         }
         else
         {
             throw new InvalidOperationException(message);
         }
     }
 }
Пример #9
0
        /// <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);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
 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);
         }
     }
 }
Пример #12
0
 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);
         }
     }
 }