コード例 #1
0
        public void DoTheJob()
        {
            try
            {
                JobQDAL    jobqDAL    = JobQDAL.Instance;
                JobQDefDTO jobDefInfo = new JobQDefDTO();
                jobDefInfo = jobqDAL.GetJobDefDTO(jobInfo.JobDefIdent);

                if (jobDefInfo.WebServiceURL.Equals(""))
                {
                    runCommand = BuildRunCommand(jobInfo, jobDefInfo);
                    RunCmd(runCommand, jobDefInfo.MaxTimeToCompletion, ref strOut, ref strError, serviceName);
                }
                else
                {
                    url = BuildWebServiceCall(jobInfo, jobDefInfo);
                    CallWebService(url, ref strError, serviceName);
                    strOut = url;
                }
            }
            catch (Exception exc)
            {
                AddError(exc);
            }
            finally
            {
                complete = true;
            }
        }
コード例 #2
0
ファイル: JobQManager.cs プロジェクト: jobanorth/WIN2
        public void ProcessOutStandingJobs(string serviceName, string includedJobIdents, string excludedJobIdents)
        {
            try
            {
                Trace.WriteLine("Starting function checkForNewReport() was called");
                Trace.Indent();

                //int numberJobsProcessed = 0;
                string runCommand;
                string url;
                string jobError = "";
                string jobMessages;
                int    nMaxLength   = 7500;
                string strOut       = "";
                string strError     = "";
                string resultOutput = "";


                JobQDAL jobqDAL = JobQDAL.Instance;

                //while (ServiceRunning)
                //{
                try
                {
                    JobQDTO jobInfo = jobqDAL.GetNextJobDTO(includedJobIdents, excludedJobIdents);

                    //if (!jobInfo.JobQID.Equals(0))
                    while (jobInfo != null)
                    {
                        //numberJobsProcessed++;
                        runCommand   = "";
                        url          = "";
                        strOut       = "";
                        strError     = "";
                        resultOutput = "";
                        jobMessages  = "";
                        jobError     = "";

                        JobQDefDTO jobDefInfo = new JobQDefDTO();
                        jobDefInfo = jobqDAL.GetJobDefDTO(jobInfo.JobDefIdent);

                        strOut = " Job Id  = " + jobInfo.JobQID.ToString() + ", Service Name = " + serviceName
                                 + ", Machine Name = " + System.Environment.MachineName + ", User Name = " + System.Environment.UserDomainName + "\\" + System.Environment.UserName
                                 + ", PID = " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + ", Assembly Version = " + Humana.H1.Common.Utilities.GetAssemblyVersionInfo() + ".     "
                                 + System.Environment.NewLine;

                        try
                        {
                            if (jobDefInfo.WebServiceURL.Equals(""))
                            {
                                string arguments = string.Empty;
                                runCommand = string.Empty;
                                BuildRunCommand(jobInfo, jobDefInfo, ref runCommand, ref arguments);
                                RunCmd(runCommand, jobDefInfo.MaxTimeToCompletion, ref strOut, ref strError, serviceName, jobInfo.JobQID, arguments);
                            }
                            else
                            {
                                url = BuildWebServiceCall(jobInfo, jobDefInfo);
                                CallWebService(url, ref strError, serviceName);
                                strOut += url;
                            }
                        }
                        catch (Exception e)
                        {
                            strError += e.ToString();
                        }

                        // sql has trouble with embedded ' char -- fix by replacing with ''
                        jobError = strError.Replace("\0", "");
                        jobError = jobError.Replace("'", "''");

                        //if (jobError.Length > nMaxLength) jobError = jobError.Substring(0, nMaxLength);
                        jobMessages = Regex.Replace(strOut, "'", "''");
                        if (jobMessages.Length > nMaxLength)
                        {
                            jobMessages = jobMessages.Substring(0, nMaxLength);
                        }

                        //Add the Job ID to the error message
                        if (jobError.Length > 0)
                        {
                            jobError = " Job Id  = " + jobInfo.JobQID.ToString() + System.Environment.NewLine
                                       + " Service Name = " + serviceName + System.Environment.NewLine
                                       + " Machine Name = " + System.Environment.MachineName + System.Environment.NewLine
                                       + " User Name = " + System.Environment.UserDomainName + "\\" + System.Environment.UserName + System.Environment.NewLine
                                       + " PID = " + System.Diagnostics.Process.GetCurrentProcess().Id.ToString() + System.Environment.NewLine
                                       + " Assembly Version = " + Humana.H1.Common.Utilities.GetAssemblyVersionInfo() + ".     "
                                       + System.Environment.NewLine
                                       + jobError;
                        }

                        jobqDAL.UpdateJobStatus(jobInfo.JobQID, jobMessages, jobError, jobDefInfo.JobOwnsStatuses);

                        //Send an email if all retrys failed
                        if (jobError.Length > 0 && jobDefInfo.JobOwnsErrorEmail == false && jobInfo.RetryCount >= jobInfo.RetryMax)
                        {
                            string subject = H1Properties.GetProperty("Adapt.Reports.CoreMetrics.Environment") + ": " + jobInfo.JobDefIdent + " Encountered An Error";
                            jobqDAL.SendEMail(jobError, subject, jobDefInfo.OnErrorEmail);
                        }

                        EventLog.WriteEntry(serviceName + ".Run", string.Format("Ran job {0} using definition for {1}.\n\nSuccess? {2}", jobInfo.JobQID, jobInfo.JobDefIdent, jobError.Length.Equals(0) ? "Yes" : "No"), EventLogEntryType.Information);

                        if (ServiceRunning)
                        {
                            jobInfo = jobqDAL.GetNextJobDTO(includedJobIdents, excludedJobIdents);
                        }
                        else
                        {
                            jobInfo = null;
                        }
                    }
                    //else
                    //{
                    //    if (numberJobsProcessed == 0)
                    //    {
                    //        resultOutput += "No Jobs found.";
                    //        Trace.WriteLine (resultOutput);
                    //    }
                    //    else
                    //    {
                    //        resultOutput += String.Format("Processed {0} Jobs.", numberJobsProcessed);
                    //    }
                    //    //break; not needed this function will be called only once
                    //}
                }
                catch (Exception e)
                {
                    EventLog.WriteEntry(serviceName + ".Run", "Error found: " + e.Message.ToString(), EventLogEntryType.Error);
                    Trace.Unindent();
                }
                //System.Threading.Thread.Sleep(SleepInterval);
                //}
            }
            catch (Exception e)
            {
                EventLog.WriteEntry(serviceName + ".Run", "Error found: " + e.Message.ToString(), EventLogEntryType.Error);
                Trace.Unindent();
            }
            Trace.Unindent();
        }
コード例 #3
0
ファイル: JobQManager.cs プロジェクト: jobanorth/WIN2
        private string BuildRunCommand(JobQDTO jobInfo, JobQDefDTO jodDefInfo, ref string strProgram, ref string strParameters)
        {
            string []     strJobDefParams     = new string [10];
            string []     strJobParams        = new string [10];
            string []     strJobDefTypeParams = new string [10];
            string []     strParams           = new string [10];
            StringBuilder RunCmd = new StringBuilder("", 512);


            //setup params from DTO
            strJobParams[0] = jobInfo.Param1;
            strJobParams[1] = jobInfo.Param2;
            strJobParams[2] = jobInfo.Param3;
            strJobParams[3] = jobInfo.Param4;
            strJobParams[4] = jobInfo.Param5;
            strJobParams[5] = jobInfo.Param6;
            strJobParams[6] = jobInfo.Param7;
            strJobParams[7] = jobInfo.Param8;
            strJobParams[8] = jobInfo.Param9;
            strJobParams[9] = jobInfo.Param10;

            strJobDefParams[0] = jodDefInfo.Param1;
            strJobDefParams[1] = jodDefInfo.Param2;
            strJobDefParams[2] = jodDefInfo.Param3;
            strJobDefParams[3] = jodDefInfo.Param4;
            strJobDefParams[4] = jodDefInfo.Param5;
            strJobDefParams[5] = jodDefInfo.Param6;
            strJobDefParams[6] = jodDefInfo.Param7;
            strJobDefParams[7] = jodDefInfo.Param8;
            strJobDefParams[8] = jodDefInfo.Param9;
            strJobDefParams[9] = jodDefInfo.Param10;

            strJobDefTypeParams[0] = jodDefInfo.Param1Type;
            strJobDefTypeParams[1] = jodDefInfo.Param2Type;
            strJobDefTypeParams[2] = jodDefInfo.Param3Type;
            strJobDefTypeParams[3] = jodDefInfo.Param4Type;
            strJobDefTypeParams[4] = jodDefInfo.Param5Type;
            strJobDefTypeParams[5] = jodDefInfo.Param6Type;
            strJobDefTypeParams[6] = jodDefInfo.Param7Type;
            strJobDefTypeParams[7] = jodDefInfo.Param8Type;
            strJobDefTypeParams[8] = jodDefInfo.Param9Type;
            strJobDefTypeParams[9] = jodDefInfo.Param10Type;



            for (int i = 0; i < 10; i++)
            {
                if (strJobDefTypeParams[i].Equals("FILESPEC"))
                {
                    if (strJobDefTypeParams[i].EndsWith("\\"))
                    {
                        strJobDefTypeParams[i] += '\\';
                    }

                    if (strJobParams.Length.Equals(0) && strJobDefParams[i].Length > 0)
                    {
                        strParams[i] = strJobDefParams[i];
                    }
                    else if (!Regex.IsMatch(strJobParams[i], ":|\\\\", RegexOptions.IgnoreCase) && strJobDefParams[i].Length > 0)
                    {
                        strParams[i] = strJobDefParams[i] + strJobParams[i];
                    }
                }
                else if (strJobParams.Length.Equals(0) && strJobDefParams[i].Length > 0)
                {
                    strParams[i] = strJobDefParams[i];
                }
                else
                {
                    strParams[i] = strJobParams[i];
                }
            }

            RunCmd.Length = 0;
            RunCmd.Append("\"");
            RunCmd.Append(jodDefInfo.ScriptToCall);
            RunCmd.Append("\"");
            strProgram = RunCmd.ToString();
            if (jodDefInfo.UseJobQIDasOnlyParam)
            {
                RunCmd.Append(" \"");
                RunCmd.Append(jobInfo.JobQID.ToString());
                RunCmd.Append("\"");
                strParameters = " \"" + jobInfo.JobQID.ToString() + "\"";
            }
            else
            {
                for (int i = 0; i < 10 && !strParams[i].Length.Equals(0); i++)
                {
                    RunCmd.Append(" \"");
                    RunCmd.Append(strParams[i]);
                    RunCmd.Append("\"");
                    strParameters += " \"" + strParams[i] + "\"";
                }
            }

            return(RunCmd.ToString());
        }
コード例 #4
0
ファイル: JobQManager.cs プロジェクト: jobanorth/WIN2
        /// <summary>
        /// Builds a HTTP-GET url to be used for calling the web service using parmaters defined by jobInfo
        /// </summary>
        /// <param name="jobInfo">a JobQDTO that gives us information about the specific execution of the job</param>
        /// <param name="jobDefInfo">a JobQDefDTO that gives us general information about the execution of a job of this type</param>
        /// <returns>a url that calls the web service requested by the jobQDTO </returns>
        private string BuildWebServiceCall(JobQDTO jobInfo, JobQDefDTO jobDefInfo)
        {
            string []     strJobDefParams     = new string [10];
            string []     strJobParams        = new string [10];
            string []     strJobDefTypeParams = new string [10];
            string []     strParams           = new string [10];
            StringBuilder webServiceCall      = new StringBuilder(string.Concat(jobDefInfo.WebServiceURL, "?"), 1024);


            //setup params from DTO
            strJobParams[0] = jobInfo.Param1;
            strJobParams[1] = jobInfo.Param2;
            strJobParams[2] = jobInfo.Param3;
            strJobParams[3] = jobInfo.Param4;
            strJobParams[4] = jobInfo.Param5;
            strJobParams[5] = jobInfo.Param6;
            strJobParams[6] = jobInfo.Param7;
            strJobParams[7] = jobInfo.Param8;
            strJobParams[8] = jobInfo.Param9;
            strJobParams[9] = jobInfo.Param10;

            strJobDefParams[0] = jobDefInfo.Param1;
            strJobDefParams[1] = jobDefInfo.Param2;
            strJobDefParams[2] = jobDefInfo.Param3;
            strJobDefParams[3] = jobDefInfo.Param4;
            strJobDefParams[4] = jobDefInfo.Param5;
            strJobDefParams[5] = jobDefInfo.Param6;
            strJobDefParams[6] = jobDefInfo.Param7;
            strJobDefParams[7] = jobDefInfo.Param8;
            strJobDefParams[8] = jobDefInfo.Param9;
            strJobDefParams[9] = jobDefInfo.Param10;

            strJobDefTypeParams[0] = jobDefInfo.Param1Type;
            strJobDefTypeParams[1] = jobDefInfo.Param2Type;
            strJobDefTypeParams[2] = jobDefInfo.Param3Type;
            strJobDefTypeParams[3] = jobDefInfo.Param4Type;
            strJobDefTypeParams[4] = jobDefInfo.Param5Type;
            strJobDefTypeParams[5] = jobDefInfo.Param6Type;
            strJobDefTypeParams[6] = jobDefInfo.Param7Type;
            strJobDefTypeParams[7] = jobDefInfo.Param8Type;
            strJobDefTypeParams[8] = jobDefInfo.Param9Type;
            strJobDefTypeParams[9] = jobDefInfo.Param10Type;

            if (jobDefInfo.UseJobQIDasOnlyParam.Equals(false))
            {
                //loop over the params
                for (int i = 0; i < strParams.GetUpperBound(0); i++)
                {
                    //if there is a jobdeftype param and a jobparam that are both populated
                    if (!(strJobDefTypeParams[i].Equals("") || strJobParams[i].Equals("")) || string.Compare(strJobDefTypeParams[i], "JobQID", true).Equals(0))
                    {
                        if (string.Compare(strJobDefTypeParams[i], "JobQID", true).Equals(0))
                        {
                            //get jobQ's value from the DTO since it can't be known at insert time of the JobQ record (thus wouldn't be in the appropriate parameter spot)
                            webServiceCall.Append(string.Concat(strJobDefTypeParams[i], "=", jobInfo.JobQID, "&"));
                        }
                        else
                        {
                            //add it on to the query string in a "<type_param>=<job_param>&" fashion
                            webServiceCall.Append(string.Concat(strJobDefTypeParams[i], "=", strJobParams[i], "&"));
                        }
                    }
                }
            }
            else
            {
                webServiceCall.Append(string.Concat("JobQID=", jobInfo.JobQID, "&"));
            }

            //return the url with the last & trimmed
            return(webServiceCall.ToString().Substring(0, webServiceCall.ToString().Length - 1));
        }