Esempio n. 1
0
		static OracleDbAgent()
		{
			_errorLog 
				= new ErrorLog("OraDbAg", "DxFrmLit", @"C:\Microsoft.Framework.log");

			try
			{
				// 퍼모먼스 카운터 객체가 존재하는지 검사하고 존재하지 않으면
				// 생성한다.
				// 별도의 셋업프로그램이 필요하지 않게 하기 위한 부분이다.
				if (PerformanceCounterCategory.Exists("OracleDbAgent") == false)
				{
					CounterCreationData[] creationDataArray 
						= { 
								new CounterCreationData("Fill","",
								PerformanceCounterType.NumberOfItems32),
								new CounterCreationData("ExecuteNonQuery","",
								PerformanceCounterType.NumberOfItems32),
								new CounterCreationData("ExecuteReader","",
								PerformanceCounterType.NumberOfItems32),
								new CounterCreationData("ExecuteScalar","",
								PerformanceCounterType.NumberOfItems32),
								new CounterCreationData("Update","",
								PerformanceCounterType.NumberOfItems32)
							};
					CounterCreationDataCollection collection 
						= new CounterCreationDataCollection(creationDataArray);
					PerformanceCounterCategory.Create("OracleDbAgent","",collection);
				}

				AppSettingsReader reader
					= new AppSettingsReader(SECTIONNAME_ORACLEDBAGENT);
				reader.RaiseException = false;

				_staticConnectionString 
					= reader[KEYNAME_CONNECTIONSTRING];
				_staticCommandTimeout 
					= reader[KEYNAME_COMMANDTIMEOUT, 30];
				_keyFileResourceName 
					= reader[KEYNAME_KEYFILERESOURCENAME,string.Empty];

				reader
					= new AppSettingsReader(SECTIONNAME_CONNECTIONSTRINGS);
				_connectionStrings = reader.KeyValues;

				if ( _keyFileResourceName != string.Empty )
				{
					string base64Password = null;
					int index;
					int startIndex = -1;
					int endIndex = -1;
          

					string s1 = _staticConnectionString;
					string s2 = "pwd";
					int result = -1;
          
					for ( index = 0; index < s1.Length; index++ )
					{
						result = string.Compare(s1,index,s2,0,s2.Length,true);
						if ( result == 0 )
						{
							startIndex = index + s2.Length + 1;
						}
					}
					if ( startIndex == -1 )
					{
						s2 = "password";

						for ( index = 0; index < s1.Length; index++ )
						{
							result = string.Compare(s1,index,s2,0,s2.Length,true);
							if ( result == 0 )
							{
								startIndex = index + s2.Length + 1;
							}
						}
					}
					if ( startIndex == -1 )
					{
						throw new Exception("암호화된 데이터베이스 연결문자열의 암호를 얻을수가 없습니다.");
					}

					endIndex = s1.IndexOf(";",startIndex);
					if ( endIndex == -1 )
					{
						endIndex = s1.Length;
					}

					base64Password = s1.Substring(startIndex, endIndex - startIndex);

					if ( base64Password == null )
					{
						throw new Exception("암호화된 데이터베이스 연결문자열의 암호를 얻을수가 없습니다.");
					}

					RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

					Stream stm = null;

					foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
					{
						stm = assembly.GetManifestResourceStream(_keyFileResourceName);
						if ( stm != null )
						{
							break;
						}
					}

					if ( stm == null )
					{
						throw new Exception("지정된 키파일의 리소스를 찾을 수 없습니다.");
					}

					RSAParameters parameters;

					XmlSerializer serializer = new XmlSerializer(typeof(RSAParameters));
					parameters = (RSAParameters)serializer.Deserialize(stm);
					stm.Close();

					rsa.ImportParameters(parameters);
					byte[] encryptedpassword = Convert.FromBase64String(base64Password);
					byte[] decryptedPassword = rsa.Decrypt(encryptedpassword,false);
					string password = Encoding.Unicode.GetString(decryptedPassword);
					s1 = _staticConnectionString.Substring(0,startIndex);
					s2 = _staticConnectionString.Substring(endIndex);

					_staticConnectionString = s1 + password + s2;
				}

				_counter = new PerformanceCounter();
				_counter.CategoryName = "OracleDbAgent";
				_counter.ReadOnly = false;
			}
			catch( Exception ex )
			{
				_errorLog.WriteExceptionLog(ex, "OracleDbAgent:");
				throw ex;
			}
		}
Esempio n. 2
0
		/// <summary>
		/// Static 생성자를 이용해서 초기화 해야할것들을 한번만 실행시키도록 함
		/// 초기화과정: 에러로그, 성능카운터객체 초기화, 연결문자열처리(암호화포함)
		/// </summary>
		static SqlDbAgent()
		{
			AppSettingsReader reader = new AppSettingsReader(SECTIONNAME_SQLDBAGENT);
			reader.RaiseException = false;

			reader = new AppSettingsReader(SECTIONNAME_SQLDBAGENT);
			
			Crypto crypto = new Crypto();
			_errorLog = new ErrorLog("SqlDbAgent", "SMFramework", reader[KEYNAME_LOG_FILE_PATH]);

			try
			{
				// 퍼포먼스 카운터 객체가 존재하는지 검사하고 존재하지 않으면 생성한다.
				// 별도의 셋업프로그램이 필요하지 않게 하기 위한 부분이다.
				if (PerformanceCounterCategory.Exists("SqlDbAgent") == false)
				{
					CounterCreationData[] creationDataArray
						= { 
							new CounterCreationData("Fill","",
							PerformanceCounterType.NumberOfItems32),
							new CounterCreationData("ExecuteNonQuery","",
							PerformanceCounterType.NumberOfItems32),
							new CounterCreationData("ExecuteReader","",
							PerformanceCounterType.NumberOfItems32),
							new CounterCreationData("ExecuteScalar","",
							PerformanceCounterType.NumberOfItems32),
							new CounterCreationData("Update","",
							PerformanceCounterType.NumberOfItems32),
							new CounterCreationData("ExecuteXmlReader","",
							PerformanceCounterType.NumberOfItems32)
						};

					CounterCreationDataCollection collection = new CounterCreationDataCollection(creationDataArray);
					PerformanceCounterCategoryType categoryType = new PerformanceCounterCategoryType();
					PerformanceCounterCategory.Create("SqlDbAgent", "", categoryType, collection);
				}

				_encConnStringYn		= reader[KEYNAME_ENCCONNSTRINGYN];
				_staticConnectionString	= reader[KEYNAME_CONNECTIONSTRING];
				_staticCommandTimeout	= reader[KEYNAME_COMMANDTIMEOUT, 30];
				_keyFileResourceName	= reader[KEYNAME_KEYFILERESOURCENAME,string.Empty];

				reader = new AppSettingsReader(SECTIONNAME_CONNECTIONSTRINGS);

				_connectionStrings = reader.KeyValues;
				
				//암호화된 연결문자열을 복호화함
				if (_encConnStringYn != string.Empty)
				{
					if (_encConnStringYn == "true")
					{
						_staticConnectionString = crypto.Decrypt(_staticConnectionString);
					}
				}
				else
				{
					throw new Exception("연결문자열 암호화여부의 설정값을 얻을수 없습니다.");
				}

				_counter = new PerformanceCounter();
				_counter.CategoryName = "SqlDbAgent";
				_counter.ReadOnly = false;
			}
			catch( Exception ex )
			{
				_errorLog.WriteExceptionLog(ex, "SqlDbAgent\t:");				
				throw ex;
			}
		}