Ejemplo n.º 1
0
        /// <summary>
        /// Handles serialization of the Song class, or of any types derived from it.
        /// </summary>
        /// <param name="instance">The instance to serialize</param>
        /// <param name="file">The XML file to serialize to</param>
        public static void SerializeTo(Song instance, string file)
        {
            // We need to save these and restore them after serializing, or else whoever is holding
            // a reference to this "instance" will end up with a broken object because we set these
            // to "null" below so that we don't serialize them.
            string savedBGImagePath = instance.BGImagePath;

            Type          type = instance.GetType();
            XmlSerializer xs   = new XmlSerializer(type);

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            FileStream fs = null;

            // When files are de-serialized, they retain the version they were
            // originally serialized under. We need to update it here.
            instance.Version = DreamTools.GetAppVersion();

            if (instance.UseDesign)
            {
                Console.WriteLine("Saving Design..");
                instance.Theme.SaveFile(DreamTools.GetDirectory(DirType.SongDesigns) + "\\" + Path.GetFileNameWithoutExtension(file) + ".SongTheme.xml");
                instance.ThemePath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.SongDesigns), Path.GetFileNameWithoutExtension(file) + ".SongTheme.xml");
            }

            try {
                fs = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Read);
                xs.Serialize(fs, instance);
            } finally {
                if (fs != null)
                {
                    fs.Close();
                }
                instance.BGImagePath = savedBGImagePath;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the background image for the content (unless HideBG is true).
        /// </summary>
        /// <param name="ConfigBGImagePath">This background is used unless the user selected a custom one.</param>
        /// <param name="graphics">The Graphics object to render the background on</param>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        public void RenderBGImage(string ConfigBGImagePath, Graphics graphics, int Width, int Height)
        {
            if (this.HideBG == false)
            {
                string fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), this.BGImagePath);
                if (DreamTools.FileExists(fullPath))
                {
                    if (this.bgImage == null)
                    {
                        try {
                            this.bgImage = Image.FromFile(fullPath);
                        } catch { }
                    }
                }
                else if (DreamTools.FileExists(DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), ConfigBGImagePath)))
                {
                    if (this.bgImage == null)
                    {
                        try {
                            this.bgImage = Image.FromFile(DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), ConfigBGImagePath));
                        } catch { }
                    }
                }

                if (this.bgImage != null)
                {
                    graphics.DrawImage(this.bgImage, 0, 0, Width, Height);
                }
            }
            else
            {
                // Draw blank rectangle if no image is defined
                graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, Width, Height));
            }
        }
Ejemplo n.º 3
0
        ///<summary>Loads the MediaList. The "filename" must be relative to
        ///the MediaLists directory.</summary>
        public void Load(string filename)
        {
            Count = 0;
            XmlDocument document = new XmlDocument();

            try {
                document.Load(DreamTools.GetDirectory(DirType.MediaLists, filename + ".xml"));
            } catch (XmlException xmle) {
                MessageBox.Show(xmle.Message);
            }

            XmlNodeList list = null;
            string      fullPath;

            // Get the Path
            list = document.GetElementsByTagName("Path");
            foreach (XmlNode n in list)
            {
                fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), n.InnerText);
                if (fullPath != null && File.Exists(fullPath))
                {
                    this.iItem[Count].Path = fullPath;
                    this.iItem[Count].Name = Path.GetFileName(this.iItem[Count].Path);
                    Count++;
                }
            }
            this.Name = filename;
        }
Ejemplo n.º 4
0
        public Bitmap GetBitmap(int Width, int Height)
        {
            if (this.RenderedFramesContains(this.VisibleHashCode()))
            {
                Console.WriteLine("ImageContent pre-render cache hit.");
                return(this.RenderedFramesGet(this.VisibleHashCode()) as Bitmap);
            }

            Bitmap   bmp      = new Bitmap(Width, Height);
            Graphics graphics = Graphics.FromImage(bmp);

            #region Render background image
            // Draw background image
            if (this.HideBG == false)
            {
                string fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), this.BGImagePath);
                if (DreamTools.FileExists(fullPath))
                {
                    if (this.bgImage == null)
                    {
                        try {
                            this.bgImage = Image.FromFile(fullPath);
                        } catch { }
                    }
                }

                if (this.bgImage != null)
                {
                    if (this._proportional)
                    {
                        graphics.DrawImage(ShowBeam.DrawProportionalBitmap(new System.Drawing.Size(Width, Height), this.bgImage).Bitmap, 0, 0, Width, Height);
                    }
                    else
                    {
                        graphics.DrawImage(this.bgImage, 0, 0, Width, Height);
                    }
                }
            }
            else
            {
                // Draw blank rectangle if no image is defined
                graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, Width, Height));
            }
            #endregion

            graphics.Dispose();
            this.RenderedFramesSet(this.VisibleHashCode(), bmp);

            return(bmp);
        }
Ejemplo n.º 5
0
        public static object DeserializeFrom(Type type, string file)
        {
            XmlSerializer xs = null;

            file = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), file);
            if (file == null)
            {
                return(null);
            }
            try {
                xs = new XmlSerializer(type);
            } catch (InvalidOperationException ex) {
                // Invalid class. Does the class have a public constructor?
                Console.WriteLine("DeserializeFrom exception: " + ex.Message);
            }

            if (xs != null)
            {
                try {
                    using (FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read)) {
                        Theme t = (Theme)xs.Deserialize(fs);
                        if (t != null)
                        {
                            t.ThemeFile = DreamTools.GetRelativePath(DirType.DataRoot, file);
                            if (type == typeof(SongTheme))
                            {
                                t.CreateTextFormats(Enum.GetValues(typeof(SongTextType)).Length);
                            }
                            else if (type == typeof(BibleTheme))
                            {
                                t.CreateTextFormats(Enum.GetValues(typeof(BibleTextType)).Length);
                            }
                            else if (type == typeof(SermonTheme))
                            {
                                t.CreateTextFormats(Enum.GetValues(typeof(TextToolType)).Length);
                            }
                        }
                        return(t);
                    }
                } catch (FileNotFoundException) {
                    return(null);
                } catch (InvalidOperationException) {
                    // Invalid XML code
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles deserialization of the Config class, or of any types derived from it.
        /// </summary>
        /// <param name="instance">An instance of the class to deserialize</param>
        /// <param name="file">The XML file to deserialize</param>
        /// <returns></returns>
        public static object DeserializeFrom(Config instance, string file)
        {
            Type          type     = instance.GetType();
            XmlSerializer xs       = null;
            string        fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.Config), file);


            try {
                xs = new XmlSerializer(type);
            } catch (InvalidOperationException ex) {
                // Invalid class. Does the class have a public constructor?
                Console.WriteLine("DeserializeFrom exception: " + ex.Message);
            }

            if (!DreamTools.FileExists(fullPath))
            {
                // fullPath could be NULL here, so use "file"
                Config.SerializeTo(instance, file);
            }
            else if (xs != null)
            {
                try {
                    using (FileStream fs = File.Open(fullPath, FileMode.Open, FileAccess.Read)) {
                        Config config = xs.Deserialize(fs) as Config;
                        if (config != null)
                        {
                            return(DeserializeCleanup(config));
                        }
                        else
                        {
                            Config.SerializeTo(instance, fullPath);
                        }
                    }
                } catch (FileNotFoundException) {
                    Config.SerializeTo(instance, fullPath);
                } catch (InvalidOperationException) {
                    // Invalid XML code
                    Config.SerializeTo(instance, fullPath);
                }
            }

            return(DeserializeCleanup(instance));
        }