/// <summary>
        ///
        /// </summary>
        /// <param name="environmentStr"></param>
        /// <param name="errTxt"></param>
        /// <returns></returns>
        private bool loadEnvironmentData(string environmentStr, out string errTxt)
        {
            errTxt = string.Empty;
            var rt = true;

            if (string.IsNullOrEmpty(environmentStr))
            {
                errTxt = "Invalid environment string.";
                return(false);
            }

            //Setup file logger
            FileLogger.Instance.initializeLogger(
                string.Format("logs/dstr_viewer_{0}.log", DateTime.Now.Ticks),
                DefaultLoggerHandlers.defaultLogLevelCheckHandler,
                DefaultLoggerHandlers.defaultLogLevelGenerator,
                DefaultLoggerHandlers.defaultDateStampGenerator,
                DefaultLoggerHandlers.defaultLogMessageHandler,
                DefaultLoggerHandlers.defaultLogMessageFormatHandler);
            FileLogger.Instance.setEnabled(true);
            FileLogger.Instance.setLogLevel(LogLevel.DEBUG);

            //Setup audit logger
            this.auditLogger = AuditLogger.Instance;
            this.auditLogger.SetAuditLogEnabledChangeHandler(auditLogEnabledChangeHandler);
            this.auditLogger.SetAuditLogHandler(logAuditMessageHandler);
            this.auditLogger.SetEnabled(true);

            //Pwn sec tuples (user name, password, host, port, schema, service)
            var internalStorage = new Dictionary <string, Tuple <string, string, string, string, string, string> >(8)
            {
                {
                    "CLXD3", new Tuple <string, string, string, string, string, string>
                        (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==",
                        @"5HYH35IsmBLxuFKgDA0deV4cSI9w/aeE", @"c5oa+iWxTPs=", @"Ny2VIxVYqnA=",
                        @"tN2vG1Y6pleVpj7+YIrMdxtI3uI0kDL1")
                },
                {
                    "CLXI", new Tuple <string, string, string, string, string, string>
                        (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==",
                        @"1xaOn6Ot6HRjXbIPl7E2WJ3Bs9SmWpEy", @"c5oa+iWxTPs=", @"Ny2VIxVYqnA=",
                        @"7GS8RS4GC4MRrLvSkAHG8w==")
                },
                {
                    "CLXT", new Tuple <string, string, string, string, string, string>
                        (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==",
                        @"bYtNZ/PbgPkj30psRLKPF+5CvrNdg5WA", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=",
                        @"BBBxdZodCA0RrLvSkAHG8w==")
                },
                {
                    "CLXT2", new Tuple <string, string, string, string, string, string>
                        (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==",
                        @"bYtNZ/PbgPkj30psRLKPF+5CvrNdg5WA", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=",
                        @"Ny/sG2mylyCVpj7+YIrMdxtI3uI0kDL1")
                },
                {
                    PROD, new Tuple <string, string, string, string, string, string>
                        (@"Ny2VIxVYqnA=", @"jZekk5GlbvfnRVTll7RpCw==",
                        @"bIyV3M7QftbxuFKgDA0deV4cSI9w/aeE", @"07s4aRvDFLs=", @"Ny2VIxVYqnA=",
                        @"ZisF3qmLAEMRrLvSkAHG8w==")
                }
            };



            //Construct data storage at runtime and select based on environment string
            //Grab the tuple and make the proper connections
            if (CollectionUtilities.isNotEmptyContainsKey(internalStorage, environmentStr))
            {
                var cxnInfo = internalStorage[environmentStr];
                var privKey = Common.Properties.Resources.PrivateKey;
                if (cxnInfo != null)
                {
                    //Create pawn security connection credentials
                    this.pwnSecCred = new Credentials
                    {
                        UserName  = StringUtilities.Decrypt(cxnInfo.Item1, privKey, true),
                        PassWord  = StringUtilities.Decrypt(cxnInfo.Item2, privKey, true),
                        DBHost    = StringUtilities.Decrypt(cxnInfo.Item3, privKey, true),
                        DBPort    = StringUtilities.Decrypt(cxnInfo.Item4, privKey, true),
                        DBService = StringUtilities.Decrypt(cxnInfo.Item6, privKey, true),
                        DBSchema  = StringUtilities.Decrypt(cxnInfo.Item5, privKey, true)
                    };

                    //Create pawn security data access tools
                    this.pwnSecDataTools = DataAccessService.CreateDataAccessTools();
                    if (!DataAccessService.Connect(PawnStoreProcedures.PAWNSEC, this.pwnSecCred, DataAccessTools.ConnectMode.MULTIPLE, DataAccessTools.LogMode.DEBUG, ref this.pwnSecDataTools))
                    {
                        errTxt = "Could not connect to pawn security database.";
                        if (FileLogger.Instance.IsLogError)
                        {
                            FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                        }
                        rt = false;
                    }
                    else
                    {
                        //Create pawn sec vo
                        this.pawnSecData = new PawnSecVO();
                        string decryptKey;

                        //Get primary oracle connection credentials
                        if (!PawnStoreProcedures.GetAllPawnSecData(ref this.pwnSecDataTools, ref this.pawnSecData, out decryptKey))
                        {
                            errTxt = "Could not load pawn security data for selected environment";
                            if (FileLogger.Instance.IsLogError)
                            {
                                FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                            }
                            rt = false;
                        }
                        else
                        {
                            //Get the oracle server info
                            this.databaseServer = this.pawnSecData.DatabaseServiceList.Find(
                                vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.ORACLEKEY, StringComparison.Ordinal)));

                            //Connect to the primary Oracle server
                            this.cshLnxCred = new Credentials
                            {
                                UserName  = StringUtilities.Decrypt(this.databaseServer.DbUser, decryptKey, true),
                                PassWord  = StringUtilities.Decrypt(this.databaseServer.DbUserPwd, decryptKey, true),
                                DBHost    = StringUtilities.Decrypt(this.databaseServer.Server, decryptKey, true),
                                DBPort    = StringUtilities.Decrypt(this.databaseServer.Port, decryptKey, true),
                                DBService = StringUtilities.Decrypt(this.databaseServer.AuxInfo, decryptKey, true),
                                DBSchema  = StringUtilities.Decrypt(this.databaseServer.Schema, decryptKey, true)
                            };

                            this.cshLnxDataTools = DataAccessService.CreateDataAccessTools();
                            if (!DataAccessService.Connect(PawnStoreProcedures.CCSOWNER, this.cshLnxCred, DataAccessTools.ConnectMode.MULTIPLE,
                                                           DataAccessTools.LogMode.DEBUG, ref this.cshLnxDataTools))
                            {
                                errTxt = "Could not connect to primary Cashlinx database";
                                if (FileLogger.Instance.IsLogError)
                                {
                                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                                }
                                rt = false;
                            }
                            else
                            {
                                //Get the couch server info
                                this.couchServer = this.pawnSecData.DatabaseServiceList.Find(
                                    vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.COUCHDBKEY, StringComparison.Ordinal)));
                                //Get the LDAP server info

                                //Change #00042 - Removing LDAP authentication from DSTR viewer

                                /*this.ldapServer = this.pawnSecData.DatabaseServiceList.Find(
                                 *  vo => (string.Equals(vo.ServiceType, EncryptedConfigContainer.LDAPKEY, StringComparison.Ordinal)));*/

                                //Setup the LDAP connection
                                this.encConfig = new EncryptedConfigContainer(
                                    Common.Properties.Resources.PrivateKey,
                                    this.pawnSecData.GlobalConfiguration.DataPublicKey,
                                    "00152",   //Hard coded to 00152 for pawn security retrieval - GJL 05/08/2012
                                    this.pawnSecData,
                                    PawnSecApplication.None,
                                    true);

                                //Change #00042 - Removing LDAP authentication from DSTR viewer

                                /*
                                 * var ldapService =
                                 *  conf.GetLDAPService(
                                 *      out loginDN,
                                 *      out searchDN,
                                 *      out userIdKey,
                                 *      out userPwd,
                                 *      out pwdPolicyCN);
                                 * if (ldapService != null && FileLogger.Instance.IsLogDebug)
                                 * {
                                 *  FileLogger.Instance.logMessage(
                                 *      LogLevel.DEBUG, this, "- Connecting to LDAP server:{0}{1}",
                                 *      System.Environment.NewLine, conf.DecryptValue(ldapService.Server));
                                 * }
                                 *
                                 * //Connect to the LDAP server
                                 * PawnLDAPAccessor.Instance.InitializeConnection(
                                 *  conf.DecryptValue(ldapService.Server),
                                 *  conf.DecryptValue(ldapService.Port),
                                 *  loginDN,
                                 *  userPwd,
                                 *  pwdPolicyCN,
                                 *  searchDN,
                                 *  userIdKey);
                                 *
                                 * if (PawnLDAPAccessor.Instance.State != PawnLDAPAccessor.LDAPState.CONNECTED)
                                 * {
                                 *  errTxt = "Could not connect to the LDAP Server";
                                 *  if (FileLogger.Instance.IsLogError)
                                 *  {
                                 *      FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                                 *  }
                                 *  rt = false;
                                 * }
                                 * else
                                 * {
                                 *  //Authenticate the user
                                 *  var attemptCount = 1;
                                 *  DateTime pwdLastMod;
                                 *  bool lockedOut;
                                 *  string[] pwdHistory;
                                 *  string displayName;
                                 *  if (!PawnLDAPAccessor.Instance.AuthorizeUser(
                                 *      this.curUserName, this.curPassword, ref attemptCount,
                                 *      out pwdLastMod, out pwdHistory, out displayName, out lockedOut))
                                 *  {
                                 *      errTxt = "Could not verify user name and password";
                                 *      if (FileLogger.Instance.IsLogError)
                                 *      {
                                 *          FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                                 *      }
                                 *      rt = false;
                                 *  }
                                 * }
                                 */
                            }
                        }
                    }
                }
                else
                {
                    errTxt = "Could not find valid connection info in internal environment data.";
                    if (FileLogger.Instance.IsLogError)
                    {
                        FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                    }
                    rt = false;
                }
            }
            else
            {
                errTxt = "Environment string not found in internal environment data.";
                if (FileLogger.Instance.IsLogError)
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, errTxt);
                }
                rt = false;
            }

            return(rt);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dA"></param>
        /// <param name="pwnSec"></param>
        /// <param name="decryptKey"> </param>
        /// <returns></returns>
        public static bool GetAllPawnSecData(
            ref DataAccessTools dA,
            ref PawnSecVO pwnSec,
            out string decryptKey)
        {
            decryptKey = string.Empty;
            if (pwnSec == null)
            {
                MessageBox.Show("Data passed into method is invalid",
                                "Alert");
                return(false);
            }
            //Get global configuration
            if (!GetGlobalConfig(ref dA, ref pwnSec, out decryptKey))
            {
                MessageBox.Show("Could not acquire global configuration", "Alert");
            }

            //Setup store config as the single parameter needed for the next few queries
            var ptStoCfg = new PairType <string, string> [1];

            ptStoCfg[0] = new PairType <string, string>("STORECONFIGID", "1");

            //Load db services and map
            DataReturnSet dbServices;

            if (!DataAccessService.ExecuteVariableQuery(false,
                                                        PawnStoreSetupQueries.SELECT_PAWNSEC_DB,
                                                        "databaseservice",
                                                        PAWNSEC,
                                                        out dbServices,
                                                        ref dA,
                                                        ptStoCfg))
            {
                MessageBox.Show("Could not execute query against the database service table",
                                "Alert");
                return(false);
            }

            if (dbServices == null || dbServices.NumberRows <= 0)
            {
                MessageBox.Show("Could not find any database services in the pawnsec database",
                                "Alert");
                return(false);
            }

            for (int i = 0; i < dbServices.NumberRows; ++i)
            {
                DataReturnSetRow dR;
                if (!dbServices.GetRow(i, out dR))
                {
                    continue;
                }

                var enabFlag     = Utilities.GetStringValue(dR.GetData("ENABLED"));
                var enabFlagBool = (!string.IsNullOrEmpty(enabFlag) && enabFlag.Equals("1"));
                var userName     = Utilities.GetStringValue(dR.GetData("DBUSER"));
                var userPwd      = Utilities.GetStringValue(dR.GetData("DBUSERPWD"));

                var dbServiceVo = new DatabaseServiceVO(userName, userPwd, enabFlagBool)
                {
                    Id          = Utilities.GetULongValue(dR.GetData("ID")),
                    Name        = Utilities.GetStringValue(dR.GetData("NAME")),
                    Server      = Utilities.GetStringValue(dR.GetData("SERVER")),
                    Port        = Utilities.GetStringValue(dR.GetData("PORT")),
                    Schema      = Utilities.GetStringValue(dR.GetData("SCHEMA")),
                    AuxInfo     = Utilities.GetStringValue(dR.GetData("AUXINFO")),
                    ServiceType = Utilities.GetStringValue(dR.GetData("SERVICETYPE"))
                };
                var dbMapVo = new PawnSecVO.DatabaseServiceStoreMapVO
                {
                    Id            = Utilities.GetULongValue(dR.GetData("DATABASEMAPID")),
                    StoreConfigId =
                        Utilities.GetULongValue(dR.GetData("DATABASEMAPSTORECONFIGID")),
                    DatabaseServiceId = dbServiceVo.Id
                };

                //Add vo objects to lists
                pwnSec.DatabaseServiceList.Add(dbServiceVo);
                pwnSec.DatabaseServiceMapList.Add(dbMapVo);
            }

            return(true);
        }