protected override void run() { try { MessageTO jobResponse = null; if (String.Equals("false", ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.EnforceCallback], StringComparison.CurrentCultureIgnoreCase)) { jobResponse = _client.sendNewJobRequest("SansCallback", 0); } else // default if config item doesn't exist or it set to anything but false { jobResponse = _client.sendNewJobRequest(_server.SocketContainer.HostName, _server.SocketContainer.ListeningPort); } _client.disconnect(); // check job stack isn't empty if (jobResponse != null && jobResponse.MessageType == MessageTypeTO.NewJobResponse && !String.IsNullOrEmpty(jobResponse.Message) && jobResponse.Message.Contains("No more jobs")) { _report.addInfo("The Orchestrator service reported there are no more jobs on the work stack. Exiting normally..."); return; } // then check we received a valid response if (jobResponse == null || jobResponse.MessageType != MessageTypeTO.NewJobResponse || jobResponse.Configuration == null || !jobResponse.Configuration.isCompleteConfiguration()) { throw new DownstreamException(null, null, null, jobResponse, "Invalid new job response!", null); } _report.addInfo("Successfully connected and registered with orchestrator and received a valid job!"); _config = jobResponse.Configuration; _report.setConfiguration(_config); _report.BatchId = jobResponse.Message; // we have the batch ID now - set it on the report for easy tracing _extractor = jobResponse.Extractor; // now that we have our config, we can create our file DAO _fileDao = new FileDaoFactory().getFileDao(); _fileDao.setExtractsDirectory(_config.SiteCode, jobResponse.Message); // messsage should contain correct directory name // Create the top level query that will drive any subqueries _vistaQuery = new VistaQuery(_config, _config.QueryConfigurations.RootNode.Value); if (checkSiteForWork()) { _report.addDebug(_config.SiteCode + " appears to have work! Starting extraction job..."); extract(); } else { _report.addDebug("Site appears to have no work!"); } // finally, try and notify orchestrator we have finished sendUnlockRequest(MessageTypeTO.JobCompletedRequest, _client); } catch (Exception exc) { _report.Errored = true; _report.addException(exc); if (_config != null) // if this was set then we know we received a job { sendUnlockRequest(MessageTypeTO.JobErrorRequest, _client); } } finally { try { _client.disconnect(); _server.stopListener(); } catch (Exception) { /* nothing we can do if these error */ } GC.Collect(); } }