Пример #1
0
        /// <summary>
        ///   Assigns all member values of this instance to the respective members of the given instance.
        /// </summary>
        /// <param name="other">
        ///   The target instance to assign to.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other" /> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///   <paramref name="other" /> is not castable to <see cref="WallpaperSettingsBase" />.
        /// </exception>
        public void AssignTo(object other)
        {
            if (other == null)
            {
                throw new ArgumentNullException();
            }
            if (!(other is WallpaperSettingsBase))
            {
                throw new ArgumentException();
            }

            WallpaperSettingsBase otherInstance = (WallpaperSettingsBase)other;

            this.AssignTo(otherInstance);
        }
Пример #2
0
        /// <summary>
        ///   Clones all members of the current instance and assigns them to the given instance.
        /// </summary>
        /// <param name="instance">
        ///   The instance to assign the cloned members to.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="instance" /> is <c>null</c>.
        /// </exception>
        protected void Clone(WallpaperSettingsBase instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException();
            }

            this.AssignTo(instance);

            instance.DisabledScreens = new Collection <int>();
            foreach (int screenIndex in this.DisabledScreens)
            {
                instance.DisabledScreens.Add(screenIndex);
            }

            instance.OnPropertyChanged("DisabledScreens");
        }
Пример #3
0
        /// <summary>
        ///   Assigns all member values of this instance to the respective members of the given instance.
        /// </summary>
        /// <param name="other">
        ///   The target instance to assign to.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other" /> is <c>null</c>.
        /// </exception>
        protected override void AssignTo(WallpaperSettingsBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException();
            }

            // Assign all members defined by WallpaperSettingsBase.
            base.AssignTo(other);

            WallpaperDefaultSettings defaultSettingsInstance = (other as WallpaperDefaultSettings);

            if (defaultSettingsInstance != null)
            {
                defaultSettingsInstance.AutoDetermineIsMultiscreen = this.AutoDetermineIsMultiscreen;
                defaultSettingsInstance.AutoDeterminePlacement     = this.AutoDeterminePlacement;
            }
        }
Пример #4
0
        /// <summary>
        ///   Assigns all member values of this instance to the respective members of the given instance.
        /// </summary>
        /// <param name="other">
        ///   The target instance to assign to.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other" /> is <c>null</c>.
        /// </exception>
        protected override void AssignTo(WallpaperSettingsBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException();
            }

            // Assign all members defined by WallpaperSettingsBase.
            base.AssignTo(other);

            Wallpaper wallpaperInstance = (other as Wallpaper);

            if (wallpaperInstance != null)
            {
                wallpaperInstance.ImagePath = this.ImagePath;
                wallpaperInstance.ImageSize = this.ImageSize;
            }
        }
Пример #5
0
        /// <inheritdoc cref="AssignTo(object)" />
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="other" /> is <c>null</c>.
        /// </exception>
        protected virtual void AssignTo(WallpaperSettingsBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException();
            }

            other.IsActivated           = this.IsActivated;
            other.IsMultiscreen         = this.IsMultiscreen;
            other.Placement             = this.Placement;
            other.Scale                 = this.Scale;
            other.Offset                = this.Offset;
            other.Effects               = this.Effects;
            other.Priority              = this.Priority;
            other.BackgroundColor       = this.BackgroundColor;
            other.OnlyCycleBetweenStart = this.OnlyCycleBetweenStart;
            other.OnlyCycleBetweenStop  = this.OnlyCycleBetweenStop;
            other.DisabledScreens       = this.DisabledScreens;
            this.OnPropertyChanged("DisabledScreens");
        }
Пример #6
0
        /// <summary>
        ///   Adds wallpaper related settings to a given <see cref="XmlElement" />.
        /// </summary>
        /// <param name="document">
        ///   The <see cref="XmlDocument" /> to add the data for.
        /// </param>
        /// <param name="element">
        ///   The <see cref="XmlElement" /> to add the data to.
        /// </param>
        /// <param name="wallpaperBaseSettings">
        ///   The wallpaper settings to add.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="document" /> or <paramref name="element" /> or <paramref name="wallpaperBaseSettings" /> is
        ///   <c>null</c>.
        /// </exception>
        protected static void AddWallpaperDataToXmlElement(XmlDocument document, XmlElement element, WallpaperSettingsBase wallpaperBaseSettings)
        {
            if (document == null)
            {
                throw new ArgumentNullException();
            }
            if (element == null)
            {
                throw new ArgumentNullException();
            }
            if (wallpaperBaseSettings == null)
            {
                throw new ArgumentNullException();
            }

            Wallpaper wallpaperSettings = (wallpaperBaseSettings as Wallpaper);
            WallpaperDefaultSettings defaultSettings = (wallpaperBaseSettings as WallpaperDefaultSettings);
            XmlElement currentElement;

            if (wallpaperSettings != null)
            {
                currentElement = document.CreateElement("ImagePath");
                if (wallpaperSettings.ImagePath != Path.None)
                {
                    currentElement.InnerText = wallpaperSettings.ImagePath;
                }
                element.AppendChild(currentElement);
            }

            currentElement           = document.CreateElement("IsActivated");
            currentElement.InnerText = wallpaperBaseSettings.IsActivated.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("IsMultiscreen");
            currentElement.InnerText = wallpaperBaseSettings.IsMultiscreen.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("Priority");
            currentElement.InnerText = wallpaperBaseSettings.Priority.ToString(CultureInfo.InvariantCulture);
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("OnlyCycleBetweenStart");
            currentElement.InnerText = wallpaperBaseSettings.OnlyCycleBetweenStart.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("OnlyCycleBetweenStop");
            currentElement.InnerText = wallpaperBaseSettings.OnlyCycleBetweenStop.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("Placement");
            currentElement.InnerText = wallpaperBaseSettings.Placement.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("HorizontalOffset");
            currentElement.InnerText = wallpaperBaseSettings.Offset.X.ToString(CultureInfo.InvariantCulture);
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("VerticalOffset");
            currentElement.InnerText = wallpaperBaseSettings.Offset.Y.ToString(CultureInfo.InvariantCulture);
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("HorizontalScale");
            currentElement.InnerText = wallpaperBaseSettings.Scale.X.ToString(CultureInfo.InvariantCulture);
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("VerticalScale");
            currentElement.InnerText = wallpaperBaseSettings.Scale.Y.ToString(CultureInfo.InvariantCulture);
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("Effects");
            currentElement.InnerText = wallpaperBaseSettings.Effects.ToString();
            element.AppendChild(currentElement);

            currentElement           = document.CreateElement("BackgroundColor");
            currentElement.InnerText = ColorTranslator.ToHtml(wallpaperBaseSettings.BackgroundColor);
            element.AppendChild(currentElement);

            currentElement = document.CreateElement("DisabledScreens");
            StringBuilder disabledScreensString = new StringBuilder(wallpaperBaseSettings.DisabledScreens.Count * 2);

            for (int i = 0; i < wallpaperBaseSettings.DisabledScreens.Count; i++)
            {
                if (i > 0)
                {
                    disabledScreensString.Append(',');
                }

                disabledScreensString.Append(wallpaperBaseSettings.DisabledScreens[i]);
            }
            currentElement.InnerText = disabledScreensString.ToString();
            element.AppendChild(currentElement);

            if (defaultSettings != null)
            {
                currentElement           = document.CreateElement("AutoDetermineIsMultiscreen");
                currentElement.InnerText = defaultSettings.AutoDetermineIsMultiscreen.ToString(CultureInfo.InvariantCulture);
                element.AppendChild(currentElement);

                currentElement           = document.CreateElement("AutoDeterminePlacement");
                currentElement.InnerText = defaultSettings.AutoDeterminePlacement.ToString(CultureInfo.InvariantCulture);
                element.AppendChild(currentElement);
            }
        }
Пример #7
0
        /// <summary>
        ///   Gets wallpaper related settings from a given <see cref="XmlElement" />.
        /// </summary>
        /// <param name="element">
        ///   The <see cref="XmlElement" /> to get the data from.
        /// </param>
        /// <param name="wallpaperSettingsType">
        ///   The type of the wallpaper settings to read.
        /// </param>
        /// <returns>
        ///   An instance of a type inherited from <see cref="WallpaperSettingsBase" /> containing the data get from the
        ///   <see cref="XmlElement" />.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="element" /> or <paramref name="wallpaperSettingsType" /> is <c>null</c>.
        /// </exception>
        /// <exception cref="XmlException">
        ///   The XML Data are invalid.
        /// </exception>
        protected static WallpaperSettingsBase GetWallpaperDataFromXmlElement(XmlElement element, Type wallpaperSettingsType)
        {
            if (element == null)
            {
                throw new ArgumentNullException();
            }
            if (wallpaperSettingsType == null)
            {
                throw new ArgumentNullException();
            }

            WallpaperSettingsBase    settings        = null;
            WallpaperDefaultSettings defaultSettings = null;
            XmlElement subElement;

            if (wallpaperSettingsType == typeof(Wallpaper))
            {
                subElement = element["ImagePath"];
                if (subElement != null)
                {
                    Wallpaper wallpaper;

                    if (subElement.InnerText.Length > 0)
                    {
                        wallpaper = new Wallpaper(new Path(subElement.InnerText));
                    }
                    else
                    {
                        wallpaper = new Wallpaper();
                    }

                    wallpaper.SuggestIsMultiscreen = false;
                    wallpaper.SuggestPlacement     = false;
                    settings = wallpaper;
                }
            }
            else if (wallpaperSettingsType == typeof(WallpaperDefaultSettings))
            {
                defaultSettings = new WallpaperDefaultSettings();
                settings        = defaultSettings;
            }

            if (settings == null)
            {
                throw new XmlException("A wallpaper setting node is missing.");
            }

            subElement = element["IsActivated"];
            if (subElement != null)
            {
                settings.IsActivated = bool.Parse(subElement.InnerText);
            }

            subElement = element["IsMultiscreen"];
            if (subElement != null)
            {
                settings.IsMultiscreen = bool.Parse(subElement.InnerText);
            }

            subElement = element["Priority"];
            if (subElement != null)
            {
                settings.Priority = byte.Parse(subElement.InnerText, CultureInfo.InvariantCulture);
            }

            subElement = element["OnlyCycleBetweenStart"];
            if (subElement != null)
            {
                settings.OnlyCycleBetweenStart = TimeSpan.Parse(subElement.InnerText, CultureInfo.InvariantCulture);
            }

            subElement = element["OnlyCycleBetweenStop"];
            if (subElement != null)
            {
                settings.OnlyCycleBetweenStop = TimeSpan.Parse(subElement.InnerText, CultureInfo.InvariantCulture);
            }

            subElement = element["Placement"];
            if (subElement != null)
            {
                settings.Placement = (WallpaperPlacement)Enum.Parse(typeof(WallpaperPlacement), subElement.InnerText);
            }

            subElement = element["HorizontalOffset"];
            if (subElement != null)
            {
                int horizontalOffset = int.Parse(subElement.InnerText, CultureInfo.InvariantCulture);

                subElement = element["VerticalOffset"];
                if (subElement != null)
                {
                    settings.Offset = new Point(horizontalOffset, int.Parse(subElement.InnerText, CultureInfo.InvariantCulture));
                }
            }

            subElement = element["HorizontalScale"];
            if (subElement != null)
            {
                int horizontalScale = int.Parse(subElement.InnerText, CultureInfo.InvariantCulture);

                subElement = element["VerticalScale"];
                if (subElement != null)
                {
                    settings.Offset = new Point(horizontalScale, int.Parse(subElement.InnerText, CultureInfo.InvariantCulture));
                }
            }

            subElement = element["Effects"];
            if (subElement != null)
            {
                settings.Effects = (WallpaperEffects)Enum.Parse(typeof(WallpaperEffects), subElement.InnerText);
            }

            subElement = element["BackgroundColor"];
            if (subElement != null)
            {
                settings.BackgroundColor = ColorTranslator.FromHtml(subElement.InnerText);
            }

            subElement = element["DisabledScreens"];
            if (subElement != null)
            {
                string[] disabledScreens = subElement.InnerText.Split(',');

                for (int i = 0; i < disabledScreens.Length; i++)
                {
                    string disabledScreenString = disabledScreens[i].Trim();

                    if (disabledScreens[i].Length != 0)
                    {
                        settings.DisabledScreens.Add(int.Parse(disabledScreenString, CultureInfo.InvariantCulture));
                    }
                }
            }

            if (defaultSettings != null)
            {
                subElement = element["AutoDetermineIsMultiscreen"];
                if (subElement != null)
                {
                    defaultSettings.AutoDetermineIsMultiscreen = bool.Parse(subElement.InnerText);
                }

                subElement = element["AutoDeterminePlacement"];
                if (subElement != null)
                {
                    defaultSettings.AutoDeterminePlacement = bool.Parse(subElement.InnerText);
                }
            }

            return(settings);
        }