Esempio n. 1
0
        protected void ValidateRunningJobs()
        {
            Dictionary <String, Object> sqlParameters = new Dictionary <String, Object>();

            sqlParameters.Add(":machinename", Environment.MachineName);

            // Pull the jobs running on this machine.
            DataTable dt = SqlUtilities.GetData(_ConnectionString, _SqlJobsInProgress, sqlParameters);

            if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
            {
                sqlParameters.Add(":inprogress", false);
                sqlParameters.Add(":scanrequested", false);
                sqlParameters.Add(":jobstatus", "Error");
                sqlParameters.Add(":statusdescription", "See activity log for details.");
                sqlParameters.Add(":pkey", -1);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    try
                    {
                        if (!MiscUtilities.isAlive(dt.Rows[i]["definition_name"].ToString()))
                        {
                            sqlParameters[":pkey"] = MiscUtilities.ObjectToInteger(dt.Rows[i]["pkey"], "No primary key defined.");
                            SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
                        }
                    }
                    catch (Exception ex)
                    {
                        LocalLog.AddLine("Error while updating in progress job status.  Error message was: " + ex.Message);
                        _AppLog.WriteEntry(ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
                    }
                }
            }
        }
Esempio n. 2
0
        protected Boolean BackupCastDatabase(int JobKey, String JobFileName, String RawJobFileName)
        {
            Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();

            sqlParameters.Add(":inprogress", true);
            sqlParameters.Add(":scanrequested", true);
            sqlParameters.Add(":jobstatus", "Ready");
            sqlParameters.Add(":statusdescription", String.Format("Backup Started: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now));
            sqlParameters.Add(":machinename", Environment.MachineName);
            sqlParameters.Add(":jobkey", JobKey);

            JobFileName = _tokens.Resolve("Scheduler", "BackupDatabase", "Missing the Scheduler/BackupDatabase attribute with the name of the backup definition. SQL query. Please add the name of the backup definition to the settings file under SchedulerSettings/Tokens/Scheduler BackupDatabase");
            // Look for backup database request
            DataTable dt = SqlUtilities.GetData(_ConnectionString, _SqlNextDbBackup);

            if ((dt == null) || (dt.Rows.Count == 0))
            {
                return(false);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {
                    JobKey = MiscUtilities.ObjectToInteger(dt.Rows[0]["pkey"], "No primary key is definied");
                    sqlParameters[":jobkey"] = JobKey;
                    RunJava(JobKey, JobFileName, RawJobFileName);

                    // Job finished update record.
                    sqlParameters[":jobstatus"]         = "Backup Completed";
                    sqlParameters[":statusdescription"] = String.Format("Backup Completed: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now);
                }
                catch (Exception ex)
                {
                    LocalLog.AddLine("Database Backup Error: " + ex.Message);
                    sqlParameters[":jobstatus"] = "Error";
                    String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                    if (message.Length > 99)
                    {
                        message = message.Substring(0, 99);
                    }
                    sqlParameters[":statusdescription"] = message;
                }
                SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
            }
            return(false);
        }
Esempio n. 3
0
        protected Boolean RunDefinition(int JobKey, String JobFileName, String RawJobFileName, String processingMessage)
        {
            Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();

            sqlParameters.Add(":inprogress", true);
            sqlParameters.Add(":scanrequested", true);
            sqlParameters.Add(":jobstatus", processingMessage);
            sqlParameters.Add(":statusdescription", String.Format("Started: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now));
            sqlParameters.Add(":machinename", Environment.MachineName);
            sqlParameters.Add(":jobkey", JobKey);

            try
            {
                SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
                // Shell to the JAVA program and run it.
                RunJava(JobKey, JobFileName, RawJobFileName);

                // Job finished update record.
                sqlParameters[":inprogress"]        = false;
                sqlParameters[":scanrequested"]     = false;
                sqlParameters[":jobstatus"]         = "Completed";
                sqlParameters[":statusdescription"] = String.Format("Completed: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now);
                sqlParameters[":machinename"]       = null;

                // Error out this queue item and rest for this application.
            }
            catch (Exception ex)
            {
                LocalLog.AddLine("Code Scan Error: " + ex.Message);
                LocalLog.AddLine(ex);

                String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                if (message.Length > 99)
                {
                    message = message.Substring(0, 99);
                }
                sqlParameters[":statusdescription"] = message;
                sqlParameters[":inprogress"]        = false;
                sqlParameters[":scanrequested"]     = false;
                sqlParameters[":jobstatus"]         = "Error";
                sqlParameters[":machinename"]       = null;
            }
            SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
            return(false);
        }
Esempio n. 4
0
        protected Boolean BackupCastDatabase()
        {
            Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();

            sqlParameters.Add(":jobkey", _JobKey);
            sqlParameters.Add(":jobstatus", "Ready");
            sqlParameters.Add(":statusdescription", "Ready");

            try
            {
                // Look for the next rescan request.
                DataTable requests = SqlUtilities.GetData(_ConnectionString, "SELECT pkey, definition_name, scan_status, dbprefix FROM fnma_measure8.scan_manager WHERE in_progress and scan_status='Backup Database'");
                if ((requests == null) || (requests.Rows.Count == 0))
                {
                    return(false);
                }

                _JobKey                  = (int)requests.Rows[0]["pkey"];
                _JobFileName             = (String)requests.Rows[0]["definition_name"];
                sqlParameters[":jobkey"] = _JobKey;
                _JobFileName             = "DatabaseBackup.xml";

                // Shell to the JAVA program and run it.
                RunJava();

                // Job finished update record.
                sqlParameters[":jobstatus"]         = "Backup Completed";
                sqlParameters[":statusdescription"] = String.Format("Backup Completed: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now);
            }
            catch (Exception ex)
            {
                LocalLog.AddLine("Database Backup Error: " + ex.Message);
                sqlParameters[":jobstatus"] = "Error";
                String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                if (message.Length > 99)
                {
                    message = message.Substring(0, 99);
                }
                sqlParameters[":statusdescription"] = message;
            }

            SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateStatus, sqlParameters);
            return(false);
        }
Esempio n. 5
0
        protected void CheckScheduledJobs()
        {
            DateTime currentDateTime = DateTime.Now;

            // Check = SELECT pkey, definition_name FROM fnma_measure8.scan_manager WHERE scheduled_date is not null and scheduled_date &lt; current_timestamp and definition_name is not null
            // Queue = UPDATE fnma_measure8.scan_manager SET scan_requested=true, request_date=current_timestamp, scan_status='Queued', machine_name=null, scheduled_date=null WHERE pkey=:key and scan_requested=false and machine_name is null and in_progress=false and scan_status='Completed'

            // Put here to lighten the load on the database server, system checks schedules every 2 minutes.
            // With 4 machines running this code, the offset between them should ensure pretty quick schedule pickups.
            if (_nextScheduleCheck > currentDateTime)
            {
                return;
            }

            DataTable dt = SqlUtilities.GetData(_ConnectionString, _sqlScheduleCheck);

            if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
            {
                Dictionary <String, Object> sqlParameters = new Dictionary <String, Object>();
                sqlParameters.Add(":key", -1);
                sqlParameters.Add(":requestdate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string job_name = "";
                    try
                    {
                        if ((DateTime)dt.Rows[i]["scheduled_date"] < DateTime.Now)
                        {
                            job_name = MiscUtilities.ObjectToStringDefault(dt.Rows[i]["definition_name"], "Definition name is blank.");
                            sqlParameters[":key"] = MiscUtilities.ObjectToInteger(dt.Rows[i]["pkey"], "No primary key defined.");
                            SqlUtilities.ExcecuteNonQuery(_ConnectionString, _sqlQueueScheduledJob, sqlParameters);
                        }
                    }
                    catch (Exception ex)
                    {
                        LocalLog.AddLine("Error while queuing scheduled job.  Error message was: " + ex.Message);
                        _AppLog.WriteEntry(ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
                    }
                }
            }
            _nextScheduleCheck = DateTime.Now.AddMinutes(2);
        }
Esempio n. 6
0
        protected Boolean RunDefinition(String processingMessage)
        {
            Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();

            sqlParameters.Add(":jobkey", _JobKey);
            sqlParameters.Add(":jobstatus", "Ready");
            sqlParameters.Add(":statusdescription", "Ready");

            try
            {
                sqlParameters[":jobkey"] = _JobKey;

                // Run the definition and wait till it finishes.
                sqlParameters[":jobstatus"]         = processingMessage;
                sqlParameters[":statusdescription"] = String.Format("Started: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now);
                SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateStatus, sqlParameters);

                // Shell to the JAVA program and run it.
                RunJava();

                // Job finished update record.
                sqlParameters[":jobstatus"]         = "Completed";
                sqlParameters[":statusdescription"] = String.Format("Completed: {0:MMMM d, yyyy HH:mm:ss}", DateTime.Now);
                // Error out this queue item and rest for this application.
            }
            catch (Exception ex)
            {
                LocalLog.AddLine("Code Scan Error: " + ex.Message);
                sqlParameters[":jobstatus"] = "Error";
                String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                if (message.Length > 99)
                {
                    message = message.Substring(0, 99);
                }
                sqlParameters[":statusdescription"] = message;
                SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.automated_queue SET ready=false, status='ERROR' WHERE ready and scan_manager_pkey={0}", _JobKey));
            }
            SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlJobFinished, sqlParameters);
            return(false);
        }
Esempio n. 7
0
        public Boolean ProcessQueue()
        {
            try
            {
                if (this._IsDbBackup)
                {
                    return(BackupCastDatabase());
                }
                else
                {
                    Dictionary <String, Object> aParams = new Dictionary <String, Object>();
                    aParams.Add(":machinename", Environment.MachineName);

                    // Set any definitions left in_progress from previous run to error. -- turned off, to test.
                    SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlErrorOutInProgress, aParams);

                    // Update next ready record with machine name
                    int gotOne = SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlNextJob, aParams);
                    if (gotOne == 0)
                    {
                        return(false);
                    }

                    // Check for next request
                    DataTable requests = SqlUtilities.GetData(_ConnectionString, _SqlNextJob, aParams);
                    if ((requests == null) || (requests.Rows.Count == 0))
                    {
                        // Ready the next application in the automated queue
                        DataTable next_automated_queue = SqlUtilities.GetData(_ConnectionString, "SELECT scan_manager_pkey, code_loc_type, code_loc_url, version_name FROM fnma_measure8.automated_queue WHERE ready and scan_manager_pkey > 0 ORDER BY scan_order, id");
                        if ((next_automated_queue != null) && (next_automated_queue.Rows.Count > 0))
                        {
                            int updatedCount = 0;
                            int lastPkey     = -1;
                            foreach (DataRow dr in next_automated_queue.Rows)
                            {
                                int scanManagerPkey = ObjectToInteger(dr["scan_manager_pkey"], "No scan_manager_pkey is definied");
                                if (scanManagerPkey == lastPkey)
                                {
                                    continue;
                                }

                                lastPkey = scanManagerPkey;
                                try
                                {
                                    int    codeLocationType = ObjectToInteger(dr["code_loc_type"], "No code_loc_type definied");
                                    String codeLocationUrl  = ObjectToString(dr["code_loc_url"], "No code_loc_url defined.");
                                    String versionName      = ObjectToString(dr["version_name"], "No version_name defined.");
                                    String request_date     = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                                    // Queue the next rescan
                                    updatedCount = SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.scan_manager SET scan_requested=true, request_date='{0}', scan_status='Queued', code_url='{1}', code_version='{2}', action_requested='rescan', code_location_type={3} WHERE pkey={4} and machine_name is null and in_progress=false and scan_requested=false and scan_status='Completed'", request_date, codeLocationUrl, versionName, codeLocationType, scanManagerPkey));
                                }
                                catch (Exception exAutomated)
                                {
                                    String error = exAutomated.Message;
                                    // Error out this queue item and rest for this application.
                                    SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.automated_queue SET ready=false, status='ERROR' WHERE ready and scan_manager_pkey={0}", scanManagerPkey));
                                }
                                if (updatedCount > 0)
                                {
                                    break;
                                }
                            }
                        }
                        //if ((next_automated_queue != null) && (next_automated_queue.Rows.Count > 0))
                        //{
                        //    int scanManagerPkey = ObjectToInteger(next_automated_queue.Rows[0]["scan_manager_pkey"], "No scan_manager_pkey is definied");
                        //    try
                        //    {
                        //        int codeLocationType = ObjectToInteger(next_automated_queue.Rows[0]["code_loc_type"], "No code_loc_type definied");
                        //        String codeLocationUrl = ObjectToString(next_automated_queue.Rows[0]["code_loc_url"], "No code_loc_url defined.");
                        //        String versionName = ObjectToString(next_automated_queue.Rows[0]["version_name"], "No version_name defined.");
                        //        String request_date = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                        //        // Queue the next rescan
                        //        SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.scan_manager SET scan_requested=true, request_date='{0}', scan_status='Queued', code_url='{1}', code_version='{2}', action_requested='rescan', code_location_type={3}, machine_name='{5}' WHERE pkey={4} and machine_name is null", request_date, codeLocationUrl, versionName, codeLocationType, scanManagerPkey, Environment.MachineName));
                        //    }
                        //    catch (Exception exAutomated)
                        //    {
                        //        String error = exAutomated.Message;
                        //        // Error out this queue item and rest for this application.
                        //        SqlUtilities.ExcecuteNonQuery(_ConnectionString, String.Format("UPDATE fnma_measure8.automated_queue SET ready=false, status='ERROR' WHERE ready and scan_manager_pkey={0}", scanManagerPkey));
                        //    }
                        //}
                        return(false);
                    }


                    _JobKey         = ObjectToInteger(requests.Rows[0]["pkey"], "No primary key is definied");
                    _JobFileName    = ObjectToString(requests.Rows[0]["definition_name"], "No definition file name is defined.");
                    _RawJobFileName = _JobFileName;

                    // Until the UI is updated, defaulting to 'rescan'
                    //String action_requested = ObjectToString(requests.Rows[0]["action_requested"], "Action_request value is null.  Typical actions include Publish, Rescan, or Onboard.");
                    String action_requested = ObjectToStringDefault(requests.Rows[0]["action_requested"], "rescan");

                    String message = "Scanning";
                    switch (action_requested.ToLower())
                    {
                    case "publish":
                        _JobFileName = ReadTokenValue("SelfServiceScan", "PublishDefinition", "No publish definition defined in the settings file.  Please add a Tokens/SelfServiceScan PublishDefinition");
                        message      = "Publishing";
                        break;

                    case "empty":
                    case "rescan":
                        message = "Processing";
                        break;

                    case "onboard":
                        _JobFileName = ReadTokenValue("SelfServiceScan", "OnBoardDefinition", "No onboard definition defined in the settings file.  Please add a Tokens/SelfServiceScan OnBoardDefinition");
                        message      = "OnBoarding";
                        break;

                    default:
                        throw new Exception(String.Format("{0} is not a valid action request.", action_requested));
                    }
                    return(RunDefinition(message));
                }
            }
            catch (Exception ex)
            {
                LocalLog.AddLine("Queue Error: " + ex.Message);
                _AppLog.WriteEntry(ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);

                if (_JobKey > 0)
                {
                    Dictionary <String, Object> aParams = new Dictionary <string, object>();
                    aParams.Add(":jobkey", _JobKey);
                    aParams.Add(":jobstatus", "Error");
                    String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                    if (message.Length > 99)
                    {
                        message = message.Substring(0, 99);
                    }
                    aParams.Add(":statusdescription", message);
                    SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlJobFinished, aParams);
                }
            }
            return(false);
        }
Esempio n. 8
0
        public void ProcessQueue()
        {
            int JobKey = -1;

            try
            {
                // Validate the processing job and update those that are no long running.
                ValidateRunningJobs();
                // Check for any scheduled work
                CheckScheduledJobs();
                // Check for any queued work
                DataRow dr = GetNextJob();
                if (dr == null)
                {
                    return;
                }

                JobKey = MiscUtilities.ObjectToInteger(dr["pkey"], "No primary key is definied");
                String JobFileName      = MiscUtilities.ObjectToString(dr["definition_name"], "No definition file name is defined.");
                String RawJobFileName   = JobFileName;
                String lockFilename     = MiscUtilities.LockFilename(RawJobFileName);
                String action_requested = MiscUtilities.ObjectToStringDefault(dr["action_requested"], "rescan");

                using (FileStream fs = new FileStream(lockFilename, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("While file is locked open, processing thread is running.  Seeing this message means the thread may not be running, please delete this file.");
                        if (_IsDbBackup)
                        {
                            BackupCastDatabase(JobKey, JobFileName, RawJobFileName);
                        }
                        else
                        {
                            String message = "Processing";
                            switch (action_requested.ToLower())
                            {
                            case "publish":
                                JobFileName = _tokens.Resolve("Scheduler", "PublishDefinition", "No publish definition defined in the settings file.  Please add a Tokens/Scheduler PublishDefinition");
                                message     = "Publishing";
                                break;

                            case "empty":
                            case "rescan":
                                message = "Processing";
                                break;

                            case "onboard":
                                JobFileName = _tokens.Resolve("Scheduler", "OnBoardDefinition", "No onboard definition defined in the settings file.  Please add a Tokens/Scheduler OnBoardDefinition");
                                message     = "OnBoarding";
                                break;

                            default:
                                throw new Exception(String.Format("{0} is not a valid action request.", action_requested));
                            }

                            // Kick off the definition
                            RunDefinition(JobKey, JobFileName, RawJobFileName, message);
                        }
                    }
                    fs.Close();
                }
                File.Delete(lockFilename);
            }
            catch (Exception ex)
            {
                lock (_lock)
                {
                    LocalLog.AddLine("Queue Error: " + ex.Message);
                }
                _AppLog.WriteEntry(ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);

                if (JobKey > 0)
                {
                    Dictionary <String, Object> sqlParameters = new Dictionary <string, object>();
                    sqlParameters.Add(":jobkey", JobKey);
                    sqlParameters.Add(":jobstatus", "Error");
                    sqlParameters.Add(":inprogress", false);
                    sqlParameters.Add(":scanrequested", false);
                    String message = String.Format("Recorded: {0:MMMM d, yyyy HH:mm:ss}, Message: {1} ", DateTime.Now, ex.Message);
                    if (message.Length > 99)
                    {
                        message = message.Substring(0, 99);
                    }
                    sqlParameters.Add(":statusdescription", message);
                    SqlUtilities.ExcecuteNonQuery(_ConnectionString, _SqlUpdateInProgressStatus, sqlParameters);
                }
            }
        }