⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metadatadescriptor.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Web.Caching;
using System.Xml;
using CommunityServer.Components;
using CommunityServer.Configuration;

namespace CommunityServer.Galleries.Components
{
	/// <summary>
	/// Summary description for PropertyDescriptor.
	/// </summary>
	public class MetadataDescriptor
	{

		#region Private Members

		private ExifProperty tagType;
		private string description;
		private PropertyFormat formatCode;
		private string format;
		private object value;

		#endregion

		#region Public Properties

		public ExifProperty TagType
		{
			get { return tagType; }
			set { tagType = value; }
		}

		public string Description
		{
			get { return description; }
			set { description = value; }
		}

		public PropertyFormat FormatCode
		{
			get { return formatCode; }
			set { formatCode = value; }
		}

		public string Format
		{
			get { return format; }
			set { format = value; }
		}

		public object Value
		{
			get { return this.value; }
			set { this.value = value; }
		}

		#endregion

		#region Public Methods

		public override string ToString()
		{
			string retval = "";

			if(value is string)
			{
				if(formatCode == PropertyFormat.DateTime)
				{
					DateTime date = DateTime.MinValue;
					
					try { date = DateTime.ParseExact((string)value, "yyyy:MM:dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.CurrentInfo, System.Globalization.DateTimeStyles.AllowWhiteSpaces); }
					catch { date = DateTime.MinValue; }

					retval = date.ToString( CSContext.Current.User.Profile.DateFormat ) + " " + date.ToString( CSContext.Current.SiteSettings.TimeFormat );
				}
				else
					retval = value.ToString();
			}
			else if(value is Rational)
			{
				retval = ((Rational)value).ToString(formatCode);
			}
			else
				retval = value.ToString();

			return string.Format( format, retval );
		}

		public static MetadataDescriptor GetDescriptor(ExifProperty prop)
		{
			return GetResources()[prop] as MetadataDescriptor;
		}

		public static MetadataDescriptor GetDescriptor(ExifProperty prop, object value)
		{
			MetadataDescriptor descriptor = GetDescriptor(prop);
			descriptor.Value = value;
			return descriptor;
		}

		#endregion

		#region Private Static Methods

		private static Hashtable GetResources()
		{
			string userLanguage = CSContext.Current.User.Profile.Language;

			if(userLanguage == "")
				userLanguage = CSConfiguration.GetConfig().DefaultLanguage;

			return GetResources(userLanguage);
		}

		private static Hashtable GetResources(string language)
		{
			CSContext csContext = CSContext.Current;
			string cacheKey = "ExifMetadataResources-" + language;
			Hashtable resources = CSCache.Get(cacheKey) as Hashtable;

			if(resources == null)
			{
				string filePath = csContext.Context.Server.MapPath("~" + CSConfiguration.GetConfig().FilesPath + "/Languages/" + language + "/metadata/ExifMetadata.xml");
				CacheDependency dp = new CacheDependency(filePath);
				XmlDocument d = new XmlDocument();
				resources = new Hashtable();

				try 
				{
					d.Load( filePath );
				} 
				catch 
				{
					return null;
				}

				foreach(XmlNode n in d.SelectSingleNode("tags").ChildNodes) 
				{
					if (n.NodeType != XmlNodeType.Comment) 
					{
						MetadataDescriptor item = new MetadataDescriptor();

						item.TagType = (ExifProperty)Enum.Parse(typeof(ExifProperty), n.Attributes["type"].Value, true);
						item.Description = n.SelectSingleNode("description").InnerText;
					
						XmlNode formatting = n.SelectSingleNode("format");

						if(formatting.Attributes["style"] != null)
							item.FormatCode = (PropertyFormat)Enum.Parse(typeof(PropertyFormat), formatting.Attributes["style"].Value, true);

						if(formatting.InnerText == "")
							item.Format = "{0}";
						else
							item.Format = formatting.InnerText;

						resources.Add(item.TagType, item);
					}
				}
				CSCache.Max(cacheKey, resources, dp);
			}

			return resources;
		}

		#endregion

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -