public override SlideShowItem CreateSlideShowItem(Hashtable compileCache, DateTime dateContext, bool bypassCaches) { if (this.webPageType == WebPageType.ImagesOnly) { return(base.CreateSlideShowItem(compileCache, dateContext, bypassCaches)); } else { CompiledWebPage compiledWebPage; if (compileCache[this.ChannelGuid] != null) { compiledWebPage = (CompiledWebPage)compileCache[this.ChannelGuid]; } else { compiledWebPage = CompiledWebPage.LoadForCompile(this.url, dateContext); compileCache[this.ChannelGuid] = compiledWebPage; } string url = Config.GetSetting("CompiledImageBaseUrl") + "webpageitem.ashx?" + "ch=" + compiledWebPage.CompiledWebPageHash + "&cid=" + compiledWebPage.CompiledWebPageGuid + (bypassCaches ? "&bc=1" : "") + "&ti=" + compiledWebPage.FetchDataDate.Ticks; return(new SlideShowItem(compiledWebPage.FetchDataDate.Add(new TimeSpan(0, WebPageChannel.webPageChannelExpiresTTL, 0)), compiledWebPage.FetchDataDate, this.Name, url, 600, 400)); } }
// // Load // // Loads the object from the database, and if it doesn't exist, creates it // static private CompiledWebPage Load(string url, int compiledWebPageHash, Guid compiledWebPageGuid, bool forImage, DateTime dateContext, bool bypassCaches) { CompiledWebPage compiledWebPage = null; using (PhotoMixQuery query = new PhotoMixQuery("SelectCompiledWebPage")) { if (forImage) { query.Parameters.Add("@ImageGeneratedDate", SqlDbType.DateTime).Value = dateContext; query.Parameters.Add("@CompiledWebPageGuid", SqlDbType.UniqueIdentifier).Value = compiledWebPageGuid; query.Parameters.Add("@CompiledWebPageHash", SqlDbType.Int).Value = compiledWebPageHash; } else { query.Parameters.Add("@CompiledDate", SqlDbType.DateTime).Value = dateContext; query.Parameters.Add("@Url", SqlDbType.NVarChar).Value = url; query.Parameters.Add("@CompiledWebPageGuid", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid(); query.Parameters.Add("@CompiledWebPageHash", SqlDbType.Int).Value = url.GetHashCode(); } if (query.Reader.Read()) { compiledWebPage = new CompiledWebPage(); compiledWebPage.compiledWebPageHash = query.Reader.GetInt32(0); compiledWebPage.compiledWebPageGuid = query.Reader.GetGuid(1); compiledWebPage.url = query.Reader.GetString(2); compiledWebPage.compiledDate = query.Reader.GetDateTime(3); compiledWebPage.imageGeneratedDate = query.Reader.IsDBNull(4) ? DateTime.MinValue : query.Reader.GetDateTime(4); compiledWebPage.fetchDataDate = query.Reader.IsDBNull(5) ? DateTime.MinValue : query.Reader.GetDateTime(5); } } if (compiledWebPage != null && (bypassCaches || compiledWebPage.fetchDataDate.AddMinutes(CompiledWebPage.webPageFetchTTL) < dateContext) || !CheckFetchWebPageData(compiledWebPage.compiledWebPageGuid) ) { FetchWebPageData(compiledWebPage.url, compiledWebPage.compiledWebPageGuid); string sql = "update CompiledWebPages " + "set FetchDataDate = @FetchDataDate " + "where CompiledWebPageGuid = @CompiledWebPageGuid"; using (PhotoMixQuery query2 = new PhotoMixQuery(sql, CommandType.Text)) { query2.Parameters.Add("@CompiledWebPageGuid", SqlDbType.UniqueIdentifier).Value = compiledWebPage.compiledWebPageGuid; query2.Parameters.Add("@FetchDataDate", SqlDbType.DateTime).Value = dateContext; query2.Execute(); } compiledWebPage.fetchDataDate = dateContext; } return(compiledWebPage); }
// // GetImageFileName // // Will get the image file name representing the the web page, and will generate the image if necessary // public static string GetImageFileName(int compiledWebPageHash, SlideShowImageSize imageSize, Guid compiledWebPageGuid, bool bypassCaches) { string fileName = ImageUtil.GetCompiledImageDirectory("WebPage") + compiledWebPageGuid.ToString() + ".jpg"; if (!bypassCaches && MiscUtil.TTLFileExists(fileName, CompiledWebPage.webPageImageTTL)) { return(fileName); } else { CompiledWebPage compiledWebPage = CompiledWebPage.LoadForImage(compiledWebPageHash, compiledWebPageGuid, DateTime.Now, bypassCaches); Bitmap bitmap = compiledWebPage.GenerateImage(fileName, imageSize); return(fileName); } }