/// <summary> /// Writes the passed message to the Console Window the application is running in and adds the passed message it to the Process Log File for the application. /// </summary> /// <param name="Message"> /// The message (text string) that is to be written to the Console Window and Process Log File. /// </param> /// <param name="MessageBreakLength"> /// The number of characters that shoudl be included on a line in the Console Window and the Process Log File. Messages longer than the specified value will be /// broken up to be written on multiple lines. /// </param> /// <param name="LogFileManager"> /// The Log File Manager Object that contains the pointer to the Process Log File for the application. /// </param> public void SendMessage(string Message, int MessageBreakLength, PDX.BTS.DataMaintenance.MaintTools.LogFileManager LogFileManager) { System.Collections.Specialized.StringCollection messages = null; try { // If the message is too long to fit in the process status list box, break it onto multiple lines. if (Message.Length > MessageBreakLength) { // Break the passed message on to multiple lines since it is too long to fit on a single line in the Process Status List Box. messages = CreateMessagesCollection(Message, MessageBreakLength); } else { // Create a Message Collection and add the current message to it. messages = new System.Collections.Specialized.StringCollection(); messages.Add(Message); } // Write the items in the Messages Collection to the Console Window and the Process Log File. foreach (string currentMessage in messages) { // Write the Message to the Console Window. Console.WriteLine(currentMessage); // If necessary, write the Message to the Process Log File. if (LogFileManager != null) { LogFileManager.WriteLine(currentMessage); } } // Exit the method. return; } catch { // Exit this method. return; } finally { // If the Messages String Collection was instantiated, close it. if (messages != null) { messages = null; } } }
/// <summary> /// Retrieves a Parameter Value from the Parameter Table indicated by the Parameter Manager Object that was /// passed to the Method. If the Value cannot be determined, a NULL String is returned. /// </summary> /// <param name="ParameterName"> /// The Name of the Parameter that is t be looked up in the Parameter Table. /// </param> /// <param name="ParameterManager"> /// A Parameter Manager Object that provides the connection information for the Parameter Table. /// </param> /// <returns> /// String - The value for the Parameter named in the "ParameterName" input parameter. A NULL String is returned /// if the Parameter Value cannot be determined. /// </returns> public string RetrieveParameterValue(string ParameterName, PDX.BTS.DataMaintenance.MaintTools.ParameterManager ParameterManager, bool DecryptValue = true) { PDX.BTS.DataMaintenance.MaintTools.EncryptionManager encryptionManager = null; try { // If the Parameter Manager Object is not initialized, return an empty string to indicate that the Parameter Value could not // be determined. if (!ParameterManager.IsInitialized()) { // Return an empty string to indicate that the value could not determined. return ""; } // Determine if the Parameter exists in the Parameter Table. If it does, return // the value. Otherwise, return an empty string to indicate that the Parameter // Value could not be found in the Table. string parameterValue = null; if (ParameterManager.ParameterExists(ParameterName)) { // Retrieve the Paarameter Value from the Parameter Table. parameterValue = ParameterManager.ReadParameter(ParameterName); // If the Parameter Value is encrypted, decrypt it. if (ParameterManager.ParameterEncrypted(ParameterName)) { // Instantiate an Encryption Manager Object. encryptionManager = new PDX.BTS.DataMaintenance.MaintTools.EncryptionManager(); // Decrypt the encrypted parameter value. parameterValue = encryptionManager.DecryptString(parameterValue); } } else { // Set the return value to an empty string to indicate that the value could not // be found in the Parameter Table. parameterValue = ""; } // Return the Parameter Value to the calling method. return parameterValue; } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this method failed. if (ErrorMessage != null) { ErrorMessage("The RetrieveParameterValue() Method failed with error message - " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return a NULL String to the calling Method to indicate that this Method failed. return null; } finally { // If the Encryption Manager was instantiated and not released, release it before exiting. if (encryptionManager != null) { encryptionManager = null; } } }