Ejemplo n.º 1
0
        ///<summary>NO LONGER USED.
        ///Leaving function here in case we want to reuse the code in future.  We only support connecting to archive DB directly.</summary>
        public static T RunFuncOnArchiveDatabase <T>(Func <T> f)
        {
            //Makes a connection to the archive database, validates that the version of the database is the same as the current database version,
            //executes the func passed in, and then sets the connection back to the original database before returning the results of the func passed in.
            //Optionally pass in connection settings to override the archive preferences.  Throws exceptions.
            if (RemotingClient.RemotingRole.In(RemotingRole.ClientWeb, RemotingRole.ServerWeb))            //May already be behind a remoting role check.
            //This method will eventually invoke SetDB() which is unacceptable for the Middle Tier.
            {
                throw new ApplicationException(Lans.g(nameof(MiscData), "Archive databases are not available when using a Middle Tier connection.") + "\r\n" +
                                               Lans.g(nameof(MiscData), "Archive databases may only be created or accessed on a direct database connection."));
            }
            string         connectionStrOrig = DataConnection.GetCurrentConnectionString();
            DatabaseType   dbTypeOrig        = DataConnection.DBtype;
            DataConnection dcon = new DataConnection();

            try {
                //Keep track of the original connection settings so that we can revert back to them once finished archiving.
                Version versionDbOrig     = new Version(PrefC.GetString(PrefName.DataBaseVersion));
                string  archiveServerName = PrefC.GetString(PrefName.ArchiveServerName);
                string  archiveUserName   = PrefC.GetString(PrefName.ArchiveUserName);
                string  decryptedPass;
                CDT.Class1.Decrypt(PrefC.GetString(PrefName.ArchivePassHash), out decryptedPass);
                //Connect to the archive database.  This can throw many exceptions.
                dcon.SetDb(archiveServerName, MiscData.GetArchiveDatabaseName(), archiveUserName, decryptedPass, "", "", dbTypeOrig);
                #region Validate archive database version
                //At this point there is an active connection to the archive database, validate the DataBaseVersion.
                string version = PrefC.GetStringNoCache(PrefName.DataBaseVersion);
                if (string.IsNullOrEmpty(version))
                {
                    //Preference table does not have version information.  Somehow they have a database with proper structure but no data.
                    //This archive database can't be trusted and we have no idea what version the schema is at.
                    //They need to call support so that we can take a look or they need to delete the invalid archive (or remove it from the data dir)
                    //so that a new archive database can be made from scratch.
                    throw new ApplicationException("Invalid archive database detected.");
                }
                Version versionDbArchive = new Version(version);
                if (versionDbOrig > versionDbArchive)
                {
                    //The archive database needs to be updated before funcs can be invoked against it.
                    throw new ApplicationException("Archive database is at a lower version than the current database."
                                                   + "  Run the Archive tool in order to update the database.");
                }
                else if (versionDbArchive > versionDbOrig)
                {
                    throw new ApplicationException("Archive database version is higher than the current database.  Process cannot continue.");
                }
                #endregion
                //Invoke the func passed in.
                return(f());
            }
            finally {                                          //Always put the connection back to the original no matter what happened above when trying to make an archive.
                dcon.SetDb(connectionStrOrig, "", dbTypeOrig); //It is acceptable to crash the program if this fails.
            }
        }
Ejemplo n.º 2
0
 ///<summary>Uses bulk insertion techniques to find and insert all securityloghash rows that are in the specified server/database and equal to or prior to the date.
 ///NOTE ----- MUST BE RUN AFTER BulkInsertSecurityLogs - DOES NOT WORK WITH RANDOM PRIMARY KEYS</summary>
 public static string BulkInsertSecurityLogHashes()
 {
     DatabaseTo  = MiscData.GetArchiveDatabaseName();
     TableName   = "securityloghash";
     TablePriKey = "SecurityLogHashNum";
     try {
         //Insert security log hashes that correspond to maximum security log primary key obtained previously.
         if (LargeTableHelper.ListPriKeyMaxPerBatch != null && LargeTableHelper.ListPriKeyMaxPerBatch.Count > 0)
         {
             InsertIntoLargeTable("WHERE SecurityLogNum <= " + POut.Long(LargeTableHelper.ListPriKeyMaxPerBatch.Max()));
         }
     }
     catch (Exception ex) {
         return(ex.Message);
     }
     return("");
 }
Ejemplo n.º 3
0
 ///<summary>Uses bulk insertion techniques to find and insert all securitylog rows that are in the specified server/database and equal to or prior to the date.
 ///NOTE ----- DOES NOT WORK WITH RANDOM PRIMARY KEYS</summary>
 public static string BulkInsertSecurityLogs(string serverName, string userName, string pass, DateTime dateArchive)
 {
     ServerTo    = POut.String(serverName);
     UserTo      = POut.String(userName);
     PasswordTo  = POut.String(pass);
     DatabaseTo  = MiscData.GetArchiveDatabaseName();
     TableName   = "securitylog";
     TablePriKey = "SecurityLogNum";
     try {
         //Insert security logs
         InsertIntoLargeTable("WHERE DATE(LogDateTime) <= " + POut.Date(dateArchive));
     }
     catch (Exception ex) {
         return(ex.Message);
     }
     return("");
 }