//
        // GetImageFileName
        //
        // Will get the image file name representing the item
        //
        public static string GetImageFileName(string language, string location, string templateDirectory, string weatherImageDirectory, SlideShowImageSize imageSize, bool bypassCaches)
        {
            string fileName = ImageUtil.GetCompiledImageDirectory("Weather") + language + "_" + location + "_" + ((int)imageSize).ToString() + ".jpg";

            if (!bypassCaches && MiscUtil.TTLFileExists(fileName, CompiledWeather.weatherImageTTL))
            {
                return(fileName);
            }
            else
            {
                CompiledWeather compiledWeather = CompiledWeather.LoadForImage(language, location, bypassCaches);

                Bitmap bitmap = compiledWeather.GenerateImage(fileName, templateDirectory, weatherImageDirectory, imageSize);

                return(fileName);
            }
        }
        public override SlideShowItem CreateSlideShowItem(Hashtable compileCache, DateTime dateContext, bool bypassCaches)
        {
            CompiledWeather compiledWeather;

            if (compileCache[this.ChannelGuid] != null)
            {
                compiledWeather = (CompiledWeather)compileCache[this.ChannelGuid];
            }
            else
            {
                compiledWeather = CompiledWeather.LoadForCompile(this.Language, this.Location, dateContext);
                compileCache[this.ChannelGuid] = compiledWeather;
            }

            string url = Config.GetSetting("CompiledImageBaseUrl") + "weatheritem.ashx" +
                         "?lan=" + this.Language +
                         "&loc=" + this.Location +
                         "&<SIZE>" +
                         (bypassCaches ? "&bc=1" : "") +
                         "&ti=" + compiledWeather.FetchDataDate.Ticks;

            return(new SlideShowItem(compiledWeather.FetchDataDate.Add(new TimeSpan(0, WeatherChannel.weatherChannelExpiresTTL, 0)), dateContext, this.Name, url, true));
        }
        //
        // Load
        //
        // Loads the object from the database, and if it doesn't exist, creates it
        static public CompiledWeather Load(string language, string location, bool forImage, DateTime dateContext, bool bypassCaches)
        {
            CompiledWeather compiledWeather = null;

            using (PhotoMixQuery query = new PhotoMixQuery("SelectCompiledWeather"))
            {
                query.Parameters.Add("@Language", SqlDbType.Char).Value    = language;
                query.Parameters.Add("@Location", SqlDbType.VarChar).Value = location;
                if (forImage)
                {
                    query.Parameters.Add("@ImageGeneratedDate", SqlDbType.DateTime).Value = dateContext;
                }
                else
                {
                    query.Parameters.Add("@CompiledDate", SqlDbType.DateTime).Value = dateContext;
                }

                if (query.Reader.Read())
                {
                    compiledWeather          = new CompiledWeather();
                    compiledWeather.language = language;
                    compiledWeather.location = location;

                    compiledWeather.compiledDate       = query.Reader.IsDBNull(3) ? DateTime.MinValue : query.Reader.GetDateTime(3);
                    compiledWeather.imageGeneratedDate = query.Reader.IsDBNull(4) ? DateTime.MinValue : query.Reader.GetDateTime(4);

                    if (!query.Reader.IsDBNull(2))
                    {
                        XmlDocument xmlDoc = new XmlDocument();

                        compiledWeather.weatherData          = xmlDoc.CreateNode(XmlNodeType.Element, "weatherdata", "");
                        compiledWeather.weatherData.InnerXml = query.Reader.IsDBNull(2) ? null : query.Reader.GetString(2);
                        compiledWeather.fetchDataDate        = query.Reader.IsDBNull(5) ? DateTime.MinValue : query.Reader.GetDateTime(5);
                    }
                    else
                    {
                        compiledWeather.weatherData   = null;
                        compiledWeather.fetchDataDate = DateTime.MinValue;
                    }
                }
            }

            if (compiledWeather != null &&
                (bypassCaches || compiledWeather.weatherData == null || compiledWeather.fetchDataDate.AddMinutes(CompiledWeather.weatherFetchTTL) < dateContext))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("http://weather.msn.com/weatherdata.aspx?wealocations=" + location);
                XmlNode weatherData = xmlDoc.SelectSingleNode("weatherdata");

                string sql = "update CompiledWeather " +
                             "set WeatherData = @WeatherData, FetchDataDate = @FetchDataDate " +
                             "where Language = @Language and Location = @Location";
                using (PhotoMixQuery query2 = new PhotoMixQuery(sql, CommandType.Text))
                {
                    query2.Parameters.Add("@Language", SqlDbType.Char).Value          = language;
                    query2.Parameters.Add("@Location", SqlDbType.VarChar).Value       = location;
                    query2.Parameters.Add("@WeatherData", SqlDbType.Text).Value       = String.IsNullOrEmpty(weatherData.InnerXml) ? (Object)DBNull.Value : (Object)weatherData.InnerXml;
                    query2.Parameters.Add("@FetchDataDate", SqlDbType.DateTime).Value = dateContext;
                    query2.Execute();
                }

                compiledWeather.weatherData   = weatherData;
                compiledWeather.fetchDataDate = dateContext;
            }

            return(compiledWeather);
        }