//
        // GenerateImage
        //
        // Will generate the bitmap representing this text item
        //
        public Bitmap GenerateImage(string fileName, SlideShowImageSize imageSize, string templateDirectory)
        {
            int width  = SlideShow.slideShowImageWidths[(int)imageSize];
            int height = SlideShow.slideShowImageHeights[(int)imageSize];

            CompiledTextFeed compiledTextFeed = CompiledTextFeed.GetCompiledTextFeed(compiledTextFeedHash, compiledTextFeedGuid);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.AppendChild(xmlDoc.CreateElement("textfeeditem"));
            ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "channeltitle", compiledTextFeed.Title);
            if (!String.IsNullOrEmpty(compiledTextFeed.LogoImageUrl))
            {
                ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "logoimg", compiledTextFeed.LogoImageUrl);
            }
            if (!String.IsNullOrEmpty(this.title))
            {
                ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "itemtitle", this.title);
            }
            if (!String.IsNullOrEmpty(this.description))
            {
                ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "itemdesc", this.description);
            }
            if (compiledTextFeed.RenderAd)
            {
                ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "adurl", Config.GetSetting("AdUrl"));
            }
            ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "width", width.ToString());
            ImageUtil.AddXmlElement(xmlDoc.DocumentElement, "height", height.ToString());
            Bitmap bitmap = WebPageBitmap.LoadXsl(templateDirectory + "textfeeditem.xsl", xmlDoc, width, height);

            ImageUtil.SaveJpeg(fileName, bitmap, 100);

            return(bitmap);
        }
        //
        // Load
        //
        // Loads the object from the database, and if it doesn't exist, creates it
        static public CompiledTextFeed Load(string textFeedUrl, string logoImageUrl, string title, bool renderAd, int compiledTextFeedHash, Guid compiledTextFeedGuid)
        {
            CompiledTextFeed compiledTextFeed = new CompiledTextFeed();

            compiledTextFeed.textFeedUrl = textFeedUrl;
            if (textFeedUrl != null)
            {
                compiledTextFeed.compiledTextFeedHash = ((string)(textFeedUrl.ToLower() + renderAd.ToString())).GetHashCode();
                compiledTextFeed.compiledTextFeedGuid = Guid.NewGuid();
            }
            else
            {
                compiledTextFeed.compiledTextFeedHash = compiledTextFeedHash;
                compiledTextFeed.compiledTextFeedGuid = compiledTextFeedGuid;
            }
            compiledTextFeed.compiledDate       = DateTime.Now;
            compiledTextFeed.imageGeneratedDate = DateTime.Now;

            using (PhotoMixQuery query = new PhotoMixQuery("SelectCompiledTextFeed"))
            {
                query.Parameters.Add("@CompiledTextFeedHash", SqlDbType.Int).Value = compiledTextFeed.compiledTextFeedHash;
                query.Parameters.Add("@CompiledTextFeedGuid", SqlDbType.UniqueIdentifier).Value = compiledTextFeed.compiledTextFeedGuid;
                if (textFeedUrl != null)
                {
                    query.Parameters.Add("@TextFeedUrl", SqlDbType.VarChar).Value  = textFeedUrl;
                    query.Parameters.Add("@LogoImageUrl", SqlDbType.VarChar).Value = String.IsNullOrEmpty(logoImageUrl) ? (Object)DBNull.Value : (Object)logoImageUrl;
                    if (renderAd)
                    {
                        query.Parameters.Add("@Data", SqlDbType.Text).Value = "<RAD>true</RAD>";
                    }
                    query.Parameters.Add("@Title", SqlDbType.VarChar).Value         = String.IsNullOrEmpty(title) ? (Object)DBNull.Value : (Object)title;
                    query.Parameters.Add("@CompiledDate", SqlDbType.DateTime).Value = compiledTextFeed.compiledDate;
                }
                else
                {
                    query.Parameters.Add("@ImageGeneratedDate", SqlDbType.DateTime).Value = DateTime.Now;
                }

                if (query.Reader.Read())
                {
                    compiledTextFeed.logoImageUrl = query.Reader.IsDBNull(0) ? null : query.Reader.GetString(0);
                    compiledTextFeed.title        = query.Reader.IsDBNull(1) ? null : query.Reader.GetString(1);
                    if (!query.Reader.IsDBNull(2))
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(query.Reader.GetString(2));
                        try { compiledTextFeed.renderAd = FormUtil.GetBoolean(xmlDoc.SelectSingleNode("RAD").InnerText); }
                        catch { }
                    }
                    compiledTextFeed.compiledDate         = query.Reader.IsDBNull(3) ? DateTime.MinValue : query.Reader.GetDateTime(3);
                    compiledTextFeed.imageGeneratedDate   = query.Reader.IsDBNull(4) ? DateTime.MinValue : query.Reader.GetDateTime(4);
                    compiledTextFeed.compiledTextFeedGuid = query.Reader.GetGuid(5);
                }
            }

            return(compiledTextFeed);
        }
        public override SlideShowItem CreateSlideShowItem(Hashtable compileCache, DateTime dateContext, bool bypassCaches)
        {
            RssChannel rssFeedChannel = (RssChannel)this.Channel;

            CompiledTextFeed compiledTextFeed;

            if (compileCache[rssFeedChannel.ChannelGuid] != null)
            {
                compiledTextFeed = (CompiledTextFeed)compileCache[rssFeedChannel.ChannelGuid];
            }
            else
            {
                compiledTextFeed = CompiledTextFeed.LoadForCompile(rssFeedChannel.RssFeedUrl, rssFeedChannel.ChannelImageUrl, rssFeedChannel.ChannelTitle, rssFeedChannel.RenderAd);
                compileCache[rssFeedChannel.ChannelGuid] = compiledTextFeed;
            }

            CompiledTextFeedItem compiledTextFeedItem;

            if (compileCache[rssFeedChannel.ChannelGuid + this.title + this.description] != null)
            {
                compiledTextFeedItem = (CompiledTextFeedItem)compileCache[rssFeedChannel.ChannelGuid + this.title + this.description];
            }
            else
            {
                compiledTextFeedItem = CompiledTextFeedItem.LoadForCompile(compiledTextFeed.CompiledTextFeedHash, compiledTextFeed.CompiledTextFeedGuid, this.title, this.description);
                compileCache[rssFeedChannel.ChannelGuid + this.title + this.description] = compiledTextFeedItem;
            }

            string url = Config.GetSetting("CompiledImageBaseUrl") + "textfeeditem.ashx?" +
                         "ch=" + compiledTextFeed.CompiledTextFeedHash +
                         "&cid=" + compiledTextFeed.CompiledTextFeedGuid +
                         "&tih=" + compiledTextFeedItem.CompiledTextFeedItemHash +
                         (bypassCaches ? "&bc=1" : "") +
                         "&<SIZE>";

            return(new SlideShowItem(this.ExpDate, this.PubDate, this.Channel.Name, url, true));
        }
        public static CompiledTextFeed GetCompiledTextFeed(int compiledTextFeedHash, Guid compiledTextFeedGuid)
        {
            CompiledTextFeed compiledTextFeed = CompiledTextFeed.LoadForImage(compiledTextFeedHash, compiledTextFeedGuid);

            return(compiledTextFeed);
        }