예제 #1
0
파일: Repository.cs 프로젝트: jgoodso2/PMIS
        /// <summary>
        /// Wait for the queue job completion of the specified message type.
        /// </summary>
        /// <param name="trackingGuid">Tracking GUID, used for getting the job group wait time. 
        ///    Not used in this implementation.</param>
        /// <param name="messageType">Type of queue message, specified by SvcQueueSystemQueueMsgType.
        ///    BugBug: using -1 for now.</param>
        /// <returns></returns>
        public static bool WaitForQueueJobCompletion(Guid jobGUID, Guid trackingGuid, int messageType)
        {
            SvcQueueSystem.QueueStatusDataSet queueStatusDataSet = new SvcQueueSystem.QueueStatusDataSet();
            SvcQueueSystem.QueueStatusRequestDataSet queueStatusRequestDataSet =
                new SvcQueueSystem.QueueStatusRequestDataSet();

            SvcQueueSystem.QueueStatusRequestDataSet.StatusRequestRow statusRequestRow =
                queueStatusRequestDataSet.StatusRequest.NewStatusRequestRow();
            statusRequestRow.JobGUID = jobGUID;
            statusRequestRow.JobGroupGUID = Guid.NewGuid();
            statusRequestRow.MessageType = messageType;
            queueStatusRequestDataSet.StatusRequest.AddStatusRequestRow(statusRequestRow);

            bool inProcess = true;
            bool result = false;
            DateTime startTime = DateTime.Now;
            int successState = (int)SvcQueueSystem.JobState.Success;
            int failedState = (int)SvcQueueSystem.JobState.Failed;
            int blockedState = (int)SvcQueueSystem.JobState.CorrelationBlocked;

            List<int> errorList = new List<int>();

            using (OperationContextScope scope = new OperationContextScope(queueSystemClient.InnerChannel))
            {

                while (inProcess)
                {
                    queueStatusDataSet = queueSystemClient.ReadJobStatus(queueStatusRequestDataSet, false,
                        SvcQueueSystem.SortColumn.Undefined, SvcQueueSystem.SortOrder.Undefined);

                    foreach (SvcQueueSystem.QueueStatusDataSet.StatusRow statusRow in queueStatusDataSet.Status)
                    {
                        if (statusRow["ErrorInfo"] != System.DBNull.Value)
                        {
                            errorList = CheckStatusRowErrors(statusRow["ErrorInfo"].ToString());

                            if (errorList.Count > 0
                                || statusRow.JobCompletionState == blockedState
                                || statusRow.JobCompletionState == failedState)
                            {
                                inProcess = false;
                                ShowErrorList("Queue", statusRow.JobCompletionState, errorList);
                            }
                        }
                        if (statusRow.JobCompletionState == successState)
                        {
                            inProcess = false;
                            result = true;
                        }
                        else
                        {
                            inProcess = true;
                            System.Threading.Thread.Sleep(500);  // Sleep 1/2 second.
                        }
                    }
                    DateTime endTime = DateTime.Now;
                    TimeSpan span = endTime.Subtract(startTime);

                    if (span.Seconds > 20) //Wait for only 20 secs - and then bail out.
                    {
                        Console.Write("Something is wrong in the queue. Check or clear the queue and then redo your action.");
                        inProcess = false;
                        result = false;
                    }
                }
            }
            return result;
        }
예제 #2
0
        public static bool WaitForQueueJobCompletion(Guid trackingGuid, int messageType, SvcQueueSystem.QueueSystemClient queueSystemClient)
        {
            //System.Threading.Thread.Sleep(2000);
            SvcQueueSystem.QueueStatusDataSet queueStatusDataSet = new SvcQueueSystem.QueueStatusDataSet();
            SvcQueueSystem.QueueStatusRequestDataSet queueStatusRequestDataSet =
                new SvcQueueSystem.QueueStatusRequestDataSet();

            SvcQueueSystem.QueueStatusRequestDataSet.StatusRequestRow statusRequestRow =
                queueStatusRequestDataSet.StatusRequest.NewStatusRequestRow();
            statusRequestRow.JobGUID = trackingGuid; //Guid.NewGuid();
            statusRequestRow.JobGroupGUID = Guid.NewGuid();
            statusRequestRow.MessageType = messageType;
            queueStatusRequestDataSet.StatusRequest.AddStatusRequestRow(statusRequestRow);

            bool inProcess = true;
            bool result = false;
            DateTime startTime = DateTime.Now;
            int successState = (int)SvcQueueSystem.JobState.Success;
            int failedState = (int)SvcQueueSystem.JobState.Failed;
            int blockedState = (int)SvcQueueSystem.JobState.CorrelationBlocked;

            List<int> errorList = new List<int>();

                while (inProcess)
                {

                        queueStatusDataSet = queueSystemClient.ReadJobStatus(queueStatusRequestDataSet, false,
                        SvcQueueSystem.SortColumn.Undefined, SvcQueueSystem.SortOrder.Undefined);

                    bool noRow = true;
                    foreach (SvcQueueSystem.QueueStatusDataSet.StatusRow statusRow in queueStatusDataSet.Status)
                    {
                        noRow = false;
                        if (statusRow["ErrorInfo"] != System.DBNull.Value)
                        {
                            errorList = CheckStatusRowErrors(statusRow["ErrorInfo"].ToString());

                            if (errorList.Count > 0
                                || statusRow.JobCompletionState == blockedState
                                || statusRow.JobCompletionState == failedState)
                            {
                                inProcess = false;

                            }
                        }
                        if (statusRow.JobCompletionState == successState)
                        {
                            inProcess = false;
                            result = true;
                        }
                        else
                        {
                            inProcess = true;
                            System.Threading.Thread.Sleep(500);  // Sleep 1/2 second.
                        }
                    }
                    if (noRow) return true;
                    DateTime endTime = DateTime.Now;
                    TimeSpan span = endTime.Subtract(startTime);

                    if (span.Seconds > 20) //Wait for only 20 secs - and then bail out.
                    {
                        return result;//result = false;
                    }
                }
            return result;
        }