www.pudn.com > OracleServiceManager.zip > OsmResources.cs


using System; 
using System.Diagnostics; 
using System.Drawing; 
using System.Resources; 
using System.Threading; 
using kae.ServiceStatePublisher; 
 
namespace kae.OracleServiceManager 
{ 
	///  
	/// Manages the icon and string resources in Oracle Service Manager 
	///  
	public class OsmResources 
	{ 
		private ResourceManager _resourceManager; 
 
		public OsmResources() 
		{ 
			_resourceManager = new ResourceManager( "kae.OracleServiceManager.OSM", this.GetType().Assembly); 
		} 
 
		protected ResourceManager Resources 
		{ 
			get { return _resourceManager; } 
		} 
 
		#region Icon Resources 
		public Icon GetApplicationImage() 
		{ 
			return GetIconFromResource( "App.Icon.Application"); 
		} 
 
		public Icon GetActionImage( string action, bool isEnabled) 
		{ 
			return (isEnabled) ? GetEnabledActionImage( action) : GetDisabledActionImage( action); 
		} 
 
		public Icon GetEnabledActionImage( string action) 
		{ 
			string resourceName = String.Format( @"App.Icon.{0}.Enabled", action); 
			return GetIconFromResource( resourceName); 
		} 
 
		public Icon GetDisabledActionImage( string action) 
		{ 
			string resourceName = String.Format( @"App.Icon.{0}.Disabled", action); 
			return GetIconFromResource( resourceName); 
		} 
 
		public Icon GetSmallStateImage( ServiceState state) 
		{ 
			string resourceName = String.Format( @"App.Icon.{0}.Small", GetStateStatus( state)); 
			return GetIconFromResource( resourceName); 
		} 
 
		public Icon GetLargeStateImage( ServiceState state) 
		{ 
			string resourceName = String.Format( @"App.Icon.{0}.Large", GetStateStatus( state)); 
			return GetIconFromResource( resourceName); 
		} 
 
		private string GetStateStatus( ServiceState state) 
		{ 
			if (state.IsChanging) 
				return "Unknown"; 
			else 
				return state.Status; 
		} 
 
		private Icon GetIconFromResource( string name) 
		{ 
			return (System.Drawing.Icon) Resources.GetObject( name); 
		} 
		#endregion 
 
		#region String Resources 
		public string ApplicationName 
		{ 
			get { return Resources.GetString( "App.String.ApplicationName"); } 
		} 
 
		public string ApplicationAbbrev 
		{ 
			get { return Resources.GetString( "App.String.ApplicationAbbrev"); } 
		} 
 
		public string Producer 
		{ 
			get { return Resources.GetString( "App.String.Producer"); } 
		} 
 
		public string GetAppString( string name) 
		{ 
			string resourceName = String.Format( "App.String.{0}", name); 
			return Resources.GetString( resourceName); 
		} 
 
		public string GetString( Type context, string name) 
		{ 
			string resourceName = String.Format( "{0}.String.{1}", context.Name, name); 
			return Resources.GetString( resourceName); 
		} 
		#endregion 
	} 
}