private void ExecuteFlowWithReturnWorkerMethod(object param) { FlowParams flowParams = param as FlowParams; string flowID = flowParams.FlowID; string[] keys = flowParams.Keys; string[] values = flowParams.Values; NameValueCollection inputParameters = GenerateInputParameters(flowID, keys, values); // // Force insertion of ResponseInBrowser = true // string respInBrowser = inputParameters["ResponseInBrowser"]; if (respInBrowser != null) { inputParameters.Remove("ResponseInBrowser"); } inputParameters["ResponseInBrowser"] = "True"; FlowManifest manifest = new FlowManifest(); manifest.RequestInitiated = DateTime.Now; manifest.InputParameters = inputParameters; manifest.FlowID = flowID; manifest.GUID = Guid.NewGuid(); byte[] returnValue = new byte[0]; string msmqPath = ConfigurationManager.AppSettings["DestinationMsmqPath"]; try { manifest.FlowStatus = FlowStatus.CompletedGateway; // // Send to Retrival. // using (MessageQueue mqPublisher = new MessageQueue(msmqPath)) { mqPublisher.Formatter = new BinaryMessageFormatter(); System.Messaging.Message msgPublisher = new System.Messaging.Message(); msgPublisher.Formatter = new BinaryMessageFormatter(); msgPublisher.Body = manifest.ToXmlDocument().OuterXml; msgPublisher.Label = string.Format("{0} - {1}", manifest.FlowID, manifest.FlowStatus.ToString()); mqPublisher.Send(msgPublisher); } // // Send message to log. // bool bLogToEvents = bool.Parse(ConfigurationManager.AppSettings["LogToEvents"]); if (bLogToEvents) { msmqPath = ConfigurationManager.AppSettings["EventsMsmqPath"]; using (MessageQueue mqLog = new MessageQueue(msmqPath)) { mqLog.Formatter = new BinaryMessageFormatter(); System.Messaging.Message msgLog = new System.Messaging.Message(); msgLog.Formatter = new BinaryMessageFormatter(); msgLog.Body = manifest.ToXmlDocument().OuterXml; msgLog.Label = string.Format("{0} - {1}", manifest.FlowID, manifest.FlowStatus.ToString()); mqLog.Send(msgLog); } } // Handle response and return. ResponseInBrowserHost host = new ResponseInBrowserHost(this.Context, "net.pipe://localhost/CompuFlow.Gateway." + manifest.GUID.ToString()); host.NoHttpContextWrite = true; host.Start(manifest.GUID); returnValue = host.ResponseInBrowserData; } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { string msg = string.Format("Failure to send message to MSMQ Path: {0}\r\nFlow: {0}.", msmqPath, manifest.GUID.ToString()); ExceptionManager.PublishException(new Exception(msg, x), "Error"); } flowParams.ReturnValue = returnValue; flowParams.ResetEvent.Set(); }
/// <summary> /// /// </summary> public void ProcessRequest( ) { try { // // Create and read from named pipe. // if (this.RequestState.HttpContext.Request.QueryString["guid"] == null) { this.RequestState.HttpContext.Response.Write("Missing required parameter: guid"); return; } string guidString = this.RequestState.HttpContext.Request.QueryString["guid"]; if (string.IsNullOrEmpty(guidString) || string.IsNullOrWhiteSpace(guidString)) { this.RequestState.HttpContext.Response.Write("Invalid parameter: guid"); return; } Guid guid; try { guid = Guid.Parse(guidString); } catch (FormatException) { this.RequestState.HttpContext.Response.Write("Invalid format parameter: guid"); return; } ResponseInBrowserHost host = new ResponseInBrowserHost(this.RequestState.HttpContext, "net.pipe://localhost/CompuFlow.Gateway." + guid.ToString()); host.Start(guid); } catch (OutOfMemoryException) { throw; } catch (StackOverflowException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { ExceptionManager.PublishException(new Exception("An error occured in ResponseInBrowser handler.", x), "Error"); this.RequestState.HttpContext.Response.ClearHeaders( ); this.RequestState.HttpContext.Response.AddHeader("Content-Type", "text/html"); this.RequestState.HttpContext.Response.Clear( ); this.RequestState.HttpContext.Response.Write("<html>"); this.RequestState.HttpContext.Response.Write("<head><title>ItSoftware - CompuFlow - Exception Information</title></head>"); this.RequestState.HttpContext.Response.Write("<body style=\"font-family:tahoma, verdana;font-size:9pt\">"); this.RequestState.HttpContext.Response.Write("<h3>An error occured in ResponseInBrowser handler.</h3><br><br>Exception information:<br>"); this.RequestState.HttpContext.Response.Write("<textarea cols=80 rows=30 style=\"font-family:tahoma,verdana;font-size:9pt\">"); this.RequestState.HttpContext.Response.Write(Formatter.FormatException(x)); this.RequestState.HttpContext.Response.Write("</textarea>"); this.RequestState.HttpContext.Response.Write("</body>"); this.RequestState.HttpContext.Response.Write("</html>"); this.RequestState.HttpContext.Response.End( ); } // // Complete the request. // m_asyncRequestState.CompleteRequest( ); }