示例#1
0
        protected override LocalizedImageData RetrieveImage(string key)
        {
            Hashtable imageData = GetImages();

            if (imageData[key] == null)
            {
                imageData[key] = new LocalizedImageData(0, 0, string.Empty);
#if DEBUG
                //throw new ApplicationException("Resource value not found for key: " + key);
#endif
            }
            return((LocalizedImageData)imageData[key]);
        }
示例#2
0
        private Hashtable LoadImages(string defaultCulture, string currentCulture)
        {
            SqlConnection connection = null;
            SqlCommand    command    = null;
            SqlDataReader reader     = null;
            Hashtable     resources  = new Hashtable();

            try
            {
                connection          = new SqlConnection(connectionString);
                command             = new SqlCommand("LoadImages", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@DefaultCulture", SqlDbType.Char, 5).Value = defaultCulture;
                command.Parameters.Add("@CurrentCulture", SqlDbType.Char, 5).Value = currentCulture;
                connection.Open();
                reader = command.ExecuteReader(CommandBehavior.SingleResult);
                int nameOrdinal   = reader.GetOrdinal("Name");
                int heightOrdinal = reader.GetOrdinal("Height");
                int widthOrdinal  = reader.GetOrdinal("Width");
                int altOrdinal    = reader.GetOrdinal("Alt");
                while (reader.Read())
                {
                    LocalizedImageData data = new LocalizedImageData();
                    data.Height = reader.GetInt32(heightOrdinal);
                    data.Width  = reader.GetInt32(widthOrdinal);
                    data.Alt    = reader.GetString(altOrdinal);
                    resources.Add(reader.GetString(nameOrdinal), data);
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }
            }
            return(resources);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            LocalizedImageData data = ResourceManager.GetImage(key);

            if (data != null)
            {
                base.Src    = string.Format(imageUrlFormat, LocalizationConfiguration.GetConfig().ImagePath, ResourceManager.CurrentCultureName, base.Src);
                base.Width  = data.Width;
                base.Height = data.Height;
                base.Alt    = data.Alt;
            }
            if (colon)
            {
                base.Alt += ResourceManager.Colon;
            }
            base.Render(writer);
        }
        private void LoadImage(Hashtable resource, string culture, string cacheKey)
        {
            string      file = string.Format("{0}\\{1}\\Images.xml", fileName, culture);
            XmlDocument xml  = new XmlDocument();

            xml.Load(file);
            foreach (XmlNode n in xml.SelectSingleNode("Images"))
            {
                if (n.NodeType != XmlNodeType.Comment)
                {
                    LocalizedImageData data = new LocalizedImageData();
                    data.Alt    = n.InnerText;
                    data.Height = Convert.ToInt32(n.Attributes["height"].Value);
                    data.Width  = Convert.ToInt32(n.Attributes["width"].Value);
                    resource[n.Attributes["name"].Value] = data;
                }
            }
            HttpRuntime.Cache.Insert(cacheKey, resource, new CacheDependency(file), DateTime.MaxValue, TimeSpan.Zero);
        }