public Form1(IGTTransactionManager transactionManager) { InitializeComponent(); processing = new GISAuto_ServiceLine(transactionManager); }
/// <summary> /// Queries for new requests and passes the request to the appropriate plug-in. /// </summary> /// <returns>Boolean indicating status</returns> private bool ProcessRequest() { bool returnValue = false; int requestID = 0; int recordsAffected = 0; string logContext = string.Empty; try { object[] queryParams = null; // Query for new requests string sql = "select REQUEST_ID, REQUEST_SYSTEM_NM, REQUEST_SERVICE_NM, REQUEST_TRANSACT_ID, REQUEST_XML, REQUEST_WR_NBR, AUD_CREATE_UID, AUD_CREATE_TS FROM " + m_QueueTable + " where REQUEST_STATUS = 'NEW'"; if (m_InstanceID.Length > 0) { sql += " and AUTO_BROKER_ID = ?"; queryParams = new object[1]; queryParams[0] = m_InstanceID; } sql += " order by AUD_CREATE_TS"; m_Application.SetStatusBarText(GTStatusPanelConstants.gtaspcMessage, "Querying the " + m_QueueTable + " table for new requests..."); Recordset requestRS = m_Application.DataContext.Execute(sql, out recordsAffected, (int)CommandTypeEnum.adCmdText, queryParams); if (requestRS.RecordCount > 0) { m_Application.SetStatusBarText(GTStatusPanelConstants.gtaspcMessage, "Processing Request..."); while (!requestRS.EOF) { // Instantiate a request object and populate it with data provided in the queue row GISAutoRequest autoRequest = new GISAutoRequest(); requestID = Convert.ToInt32(requestRS.Fields["REQUEST_ID"].Value); autoRequest.requestID = requestID; autoRequest.requestSystemName = requestRS.Fields["REQUEST_SYSTEM_NM"].Value.ToString(); autoRequest.requestServiceName = requestRS.Fields["REQUEST_SERVICE_NM"].Value.ToString(); if (!Convert.IsDBNull(requestRS.Fields["REQUEST_TRANSACT_ID"].Value)) { autoRequest.requestTransactionID = Convert.ToInt32(requestRS.Fields["REQUEST_TRANSACT_ID"].Value); } autoRequest.requestXML = requestRS.Fields["REQUEST_XML"].Value.ToString(); autoRequest.requestWRNumber = requestRS.Fields["REQUEST_WR_NBR"].Value.ToString(); autoRequest.auditUserID = requestRS.Fields["AUD_CREATE_UID"].Value.ToString(); autoRequest.auditTimeStamp = requestRS.Fields["AUD_CREATE_TS"].Value.ToString(); // Write a row to the Command Log (GIS.COMMAND_LOG) table to indicate that the request has been claimed. logContext = string.Format("ID {0}: {1}|{2}|{3}|{4}", m_InstanceID, autoRequest.requestSystemName, autoRequest.requestServiceName, autoRequest.requestID, autoRequest.requestWRNumber); WriteToCommandLog("INFO", "Request claimed", logContext); IGISAutoPlugin plugin = null; try { // Update REQUEST_STATUS = PROCESSING for the current request sql = "update " + m_QueueTable + " set REQUEST_STATUS = 'PROCESSING' where REQUEST_ID = ?"; m_Application.DataContext.Execute(sql, out recordsAffected, (int)CommandTypeEnum.adCmdText, requestID); m_Application.DataContext.Execute("commit", out recordsAffected, (int)CommandTypeEnum.adCmdText); // Create appropriate plug-in switch (autoRequest.requestServiceName) { case "GIS_DEISTransaction": // "DEIS": plugin = new GISAuto_DEIS(m_TransactionManager); break; case "GIS_CreateFieldTransaction": // "ServiceLine": plugin = new GISAuto_ServiceLine(m_TransactionManager); break; case "GIS_RequestBatch": // "WMIS": plugin = new BatchProcessingModule(m_TransactionManager); break; default: WriteToCommandLog("ERROR", "Service Name not found in switch statement.", "GISAutomationBroker.ProcessRequest"); break; } // Call plug-in method to process the request plugin.Execute(autoRequest); // The request has been successfully processed. Update request status and status date. sql = "update " + m_QueueTable + " set REQUEST_STATUS = 'COMPLETE', STATUS_DT = sysdate where REQUEST_ID = ?"; m_Application.DataContext.Execute(sql, out recordsAffected, (int)CommandTypeEnum.adCmdText, requestID); m_Application.DataContext.Execute("commit", out recordsAffected, (int)CommandTypeEnum.adCmdText); } catch (Exception ex) { string logmsg = string.Format("Exception caught in Broker: {0}", ex.Message); if (logmsg.Length > 100) { logmsg = logmsg.Substring(0, 99); } WriteToCommandLog("INFO", "Status", logmsg); //using(System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\temp\gisautomator.txt", true)) //{ // file.WriteLine(ex.HResult.ToString().Substring(1, 10)); // file.WriteLine(ex.Message); // file.WriteLine(requestID.ToString()); //} // Add error to request entry sql = "update " + m_QueueTable + " set REQUEST_STATUS = ?, RESPONSE_C = ?, RESPONSE_MSG = ?, STATUS_DT = sysdate where REQUEST_ID = ?"; m_Application.DataContext.Execute(sql, out recordsAffected, (int)CommandTypeEnum.adCmdText, "ERROR", ex.HResult.ToString().Substring(1, 10), ex.Message, requestID); m_Application.DataContext.Execute("commit", out recordsAffected, (int)CommandTypeEnum.adCmdText); // Add error to command_log using logger class WriteToCommandLog("ERROR", ex.HResult + ":" + ex.Message, logContext); } plugin = null; autoRequest = null; // Compare the active job to the job initially active when the command was invoked; // if the active job was changed by the plug-in module, // then reactivate the original job before the next request is processed. string currentJob = m_Application.DataContext.ActiveJob; if (m_StartingJob != currentJob) { m_JobManagement.DataContext = m_Application.DataContext; m_JobManagement.EditJob(m_StartingJob); } requestRS.MoveNext(); } } else { Thread.Sleep(m_PollingInterval * 1000); } returnValue = true; } catch (Exception ex) { WriteToCommandLog("ERROR", "Error processing request.", "GISAutomationBroker.ProcessRequest"); WriteToCommandLog("ERROR", string.Format("Error message: {0}", ex.Message), "GISAutomationBroker.ProcessRequest"); returnValue = false; } return(returnValue); }