250 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			250 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text;
 | |
| using System.IO;
 | |
| using System.Configuration;
 | |
| using System.Reflection;
 | |
| 
 | |
| namespace Volian.Base.Library
 | |
| {
 | |
| 	public static class VlnSettings
 | |
| 	{
 | |
| 		// This is used to toggle the colored text during the Data Conversion
 | |
| 		// and will set the font and background in PROMS 2010 for Demo/Release mode (white background black text)
 | |
| 		// or for Debug mode (shaded background, and color text on PDF output
 | |
| 		// For PROMS 2010, this is set via the App.config setting:
 | |
| 		//   <appSettings>
 | |
| 		//		<add key ="OperatingMode" value ="Debug"|"Demo"|"Production"/>
 | |
| 		// For DataLoader, this is set via the Debug checkbox on the form.
 | |
| 		private static bool WasLoaded = false;
 | |
| 		private static bool _DoUpdateRO = true;
 | |
| 		public static bool DoUpdateRO
 | |
| 		{
 | |
| 			get { return VlnSettings._DoUpdateRO; }
 | |
| 			set { VlnSettings._DoUpdateRO = value; }
 | |
| 		}
 | |
| 		private static bool _DebugPagination = false;
 | |
| 		public static bool DebugPagination
 | |
| 		{
 | |
| 			get { return VlnSettings._DebugPagination; }
 | |
| 			set { VlnSettings._DebugPagination = value; }
 | |
| 		}
 | |
| 		private static bool _DebugText = false;
 | |
| 		public static bool DebugText
 | |
| 		{
 | |
| 			get { return VlnSettings._DebugText; }
 | |
| 			set { VlnSettings._DebugText = value; }
 | |
| 		}
 | |
| 		private static bool _DebugMode = false;
 | |
| 		public static bool DebugMode
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (!WasLoaded) LoadOperatingMode();
 | |
| 				return _DebugMode;
 | |
| 			}
 | |
| 			set { _DebugMode = value; }
 | |
| 		}
 | |
| 		private static bool _DemoMode = false;
 | |
| 		public static bool DemoMode
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (!WasLoaded) LoadOperatingMode();
 | |
| 				return _DemoMode;
 | |
| 			}
 | |
| 			set { _DemoMode = value; }
 | |
| 		}
 | |
| 		private static bool _ProductionMode = true;   // default to OperatingMode to production
 | |
| 		public static bool ProductionMode
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (!WasLoaded) LoadOperatingMode();
 | |
| 				return _ProductionMode;
 | |
| 			}
 | |
| 			set { _ProductionMode = value; }
 | |
| 		}
 | |
| 		private static bool _OriginalPageBreak = false;   // default to not using 16bit pagebreaks
 | |
| 		public static bool OriginalPageBreak
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (!WasLoaded) LoadOperatingMode();
 | |
| 				return _OriginalPageBreak;
 | |
| 			}
 | |
| 			set { _OriginalPageBreak = value; }
 | |
| 		}
 | |
| 		private static bool _ComparePROMStoPROMSPDF = false; // default to compare 16-bit generated PDFs
 | |
| 		public static bool ComparePROMStoPROMSPDF
 | |
| 		{
 | |
| 			get 
 | |
| 			{ 
 | |
| 				if (!WasLoaded) LoadOperatingMode();
 | |
| 				return _ComparePROMStoPROMSPDF; 
 | |
| 			}
 | |
| 			set { _ComparePROMStoPROMSPDF = value; }
 | |
| 		}
 | |
| 		public static string GetDB()
 | |
| 		{
 | |
| 			string str = GetCommand("DB", null);
 | |
| 			if (str == null) return null;
 | |
| 			if(str.Contains( ":"))
 | |
| 			{
 | |
| 				string[] parts = str.Split(":".ToCharArray());
 | |
| 				if (parts.Length > 1) return parts[1];
 | |
| 			}
 | |
| 			return str;
 | |
| 		}
 | |
| 		public static string GetServer()
 | |
| 		{
 | |
| 			string str = GetCommand("DB", null);
 | |
| 			if (str != null && str.Contains(":"))
 | |
| 			{
 | |
| 				string[] parts = str.Split(":".ToCharArray());
 | |
| 				return parts[0].Replace("._",".\\");
 | |
| 			}
 | |
| 			return GetCommand("Server",null);
 | |
| 		}
 | |
| 		public static string GetItemIDs()
 | |
| 		{
 | |
| 			string str = GetCommand("DB", null);
 | |
| 			if (str != null && str.Contains(":"))
 | |
| 			{
 | |
| 				string[] parts = str.Split(":".ToCharArray());
 | |
| 				if(parts.Length > 2) return parts[2];
 | |
| 			}
 | |
| 			return GetCommand("ItemIDs", "");
 | |
| 		}
 | |
| 		public static string GetCommand(string commandName, string def)
 | |
| 		{
 | |
| 			string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray());
 | |
| 			foreach (string parameter in parameters)
 | |
| 			{
 | |
| 				if (parameter.ToUpper().StartsWith("/" + commandName.ToUpper() + "="))
 | |
| 				{
 | |
| 					return parameter.Substring(commandName.Length + 2);
 | |
| 				}
 | |
| 			}
 | |
| 			return def;
 | |
| 		}
 | |
| 		public static float GetCommandFloat(string commandName, float def)
 | |
| 		{
 | |
| 			string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray());
 | |
| 			foreach (string parameter in parameters)
 | |
| 			{
 | |
| 				if (parameter.ToUpper().StartsWith("/" + commandName.ToUpper() + "="))
 | |
| 				{
 | |
| 					float result = def;
 | |
| 					if (float.TryParse(parameter.Substring(commandName.Length + 2), out result))
 | |
| 						return result;
 | |
| 					else
 | |
| 						return def;
 | |
| 				}
 | |
| 			}
 | |
| 			return def;
 | |
| 		}
 | |
| 		public static bool GetCommandFlag(string commandName)
 | |
| 		{
 | |
| 			string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray());
 | |
| 			foreach (string parameter in parameters)
 | |
| 			{
 | |
| 				if (parameter.ToUpper().Equals("/" + commandName.ToUpper()))
 | |
| 					return true;
 | |
| 			}
 | |
| 			return false;
 | |
| 		}
 | |
| 		private static void LoadOperatingMode()
 | |
| 		{
 | |
| 			string opMode = ConfigurationManager.AppSettings["OperatingMode"];
 | |
| 			opMode = GetCommand("MODE",opMode);
 | |
| 			if (opMode != null && opMode != "")
 | |
| 			{
 | |
| 				_DebugMode = opMode.ToUpper() == "DEBUG";
 | |
| 				_DemoMode = opMode.ToUpper() == "DEMO";
 | |
| 				_ProductionMode = opMode.ToUpper() == "PRODUCTION";
 | |
| 				_ComparePROMStoPROMSPDF = _DebugMode;
 | |
| 			}
 | |
| 			string pageBreak = ConfigurationManager.AppSettings["OriginalPageBreak"];
 | |
| 			if (pageBreak != null && pageBreak != "")
 | |
| 			{
 | |
| 				_OriginalPageBreak = pageBreak.ToUpper() == "TRUE";
 | |
| 			}
 | |
| 			WasLoaded = true;
 | |
| 		}
 | |
| 		private static string _TemporaryFolder = null;
 | |
| 		public static string TemporaryFolder
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (_TemporaryFolder == null)
 | |
| 				{
 | |
| 					// This will create a Temp\VE-PROMS folder in the LocalSettings Folder.
 | |
| 					//XP - C:\Documents and Settings\{user}\Local Settings\Application Data\Temp\VEPROMS
 | |
| 					//Vista - C:\Users\{user}\AppData\Local\Temp\VEPROMS
 | |
| 					_TemporaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Temp";
 | |
| 					if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder);
 | |
| 					_TemporaryFolder += @"\VEPROMS";
 | |
| 					if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder);
 | |
| 				}
 | |
| 				return _TemporaryFolder;
 | |
| 			}
 | |
| 		}
 | |
| 		private static string _UserID=Environment.UserName.ToUpper();
 | |
| 		public static string UserID
 | |
| 		{
 | |
| 			get { return VlnSettings._UserID; }
 | |
| 			set { VlnSettings._UserID = value; }
 | |
| 		}
 | |
| 		private static bool _StepTypeToolTip = false;
 | |
| 		public static bool StepTypeToolType
 | |
| 		{
 | |
| 			get { return VlnSettings._StepTypeToolTip; }
 | |
| 			set { VlnSettings._StepTypeToolTip = value; }
 | |
| 		}
 | |
| 		private static string _ReleaseMode = null;
 | |
| 		public static string ReleaseMode
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (_ReleaseMode == null)
 | |
| 				{
 | |
| 					string relType = "RELEASE"; // default to normal Release Mode setting
 | |
| 					// Get the type of release:
 | |
| 					// "Demo", "Westinghouse", "Release"
 | |
| 					object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
 | |
| 					if (attributes.Length > 0)
 | |
| 						relType = ((AssemblyConfigurationAttribute)attributes[0]).Configuration.ToUpper();
 | |
| 					_ReleaseMode = relType;
 | |
| 				}
 | |
| 				return _ReleaseMode;
 | |
| 			}
 | |
| 		}
 | |
| 		private static string _EULAfile = null;
 | |
| 		public static string EULAfile
 | |
| 		{
 | |
| 			get {
 | |
| 				if (_EULAfile == null)
 | |
| 				{
 | |
| 					switch (ReleaseMode)
 | |
| 					{
 | |
| 						case "DEMO": // Demo CD/DVD release
 | |
| 							_EULAfile = "DemoEULA.txt";
 | |
| 							break;
 | |
| 						case "WESTINGHOUSE":
 | |
| 							_EULAfile = "WestinghouseEULA.txt";
 | |
| 							break;
 | |
| 						case "BARAKAH":
 | |
| 							_EULAfile = "BarakahEULA.txt";  // C2018-037
 | |
| 							break;
 | |
| 						default:
 | |
| 							_EULAfile = "EULA.txt";
 | |
| 							break;
 | |
| 					}
 | |
| 				}
 | |
| 				return _EULAfile; 
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 |