/// <summary> /// Executes the action returning an number of messages. /// </summary> /// <param name="sessionId">The session Id of the user executing this action.</param> /// <param name="integrationMessage">Accepts a string integration message that can be deserialized into the required class.</param> public void Execute(string sessionId, string integrationMessage) { string jsonIntegration = "Unknown JSON Integration"; string jsonBaseAddress = "<unknown>"; try { var message = JObject.Parse(integrationMessage); jsonIntegration = (string)message["integration"] ?? "JSON Integration"; jsonBaseAddress = (string)message["baseaddress"]; string jsonEndpoint = (string)message["endpoint"]; var jsonMessage = message["message"]; JArray jsonHeaders = (JArray)message["headers"]; var additionalHeaders = jsonHeaders.Select(h => new KeyValuePair <string, string>((string)h["header"], (string)h["value"])).ToDictionary(i => i.Key, i => i.Value); var proxyInfoBlock = message["proxy"]; var restPost = PostRestMessage(new Uri(jsonBaseAddress), jsonEndpoint, (object)jsonMessage, additionalHeaders, ParseWebProxyInfo(proxyInfoBlock)); restPost.Wait(10000); if (restPost.IsFaulted) { throw restPost.Exception; } var result = restPost.Result; var debugInfo = new MarvalApplicationException(String.Format("Success: {0} ({1}) - {2}", (int)result.StatusCode, result.StatusCode, result.ReasonPhrase)); Log.Debug(debugInfo, String.Format("{0}: {1}: {2}", this.ActionName, jsonIntegration, debugInfo.Message)); #if DEBUG // send a message to the UI SendMessage(this, new MessageEventArgs(sessionId, new TrayMessage { Heading = jsonIntegration, Text = "Successful postback", Type = TrayMessage.MessageTypes.Information })); #endif } catch (JsonReaderException e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, jsonIntegration, e.Message)); ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Error while parsing Action Message", this.ActionName, jsonIntegration), e)); } catch (HttpRequestException e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, jsonIntegration, e.Message)); ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Unable to connect with {2}", this.ActionName, jsonIntegration, jsonBaseAddress ?? "<unset>"), e)); } catch (Exception e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, jsonIntegration, (e.InnerException ?? e).Message)); if ((e is AggregateException) && (e.InnerException != null)) { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Error while communicating with {2}", this.ActionName, jsonIntegration, jsonBaseAddress ?? "<unset>"), e.InnerException)); } else { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Exception in JSON Integration", this.ActionName, jsonIntegration), e)); } } }
/// <summary> /// Executes the action, executing an agent with the supplied parameters. /// </summary> /// <param name="sessionId">The session Id of the user executing this action.</param> /// <param name="integrationMessage">Accepts a string integration message that can be deserialized into the required class.</param> public void Execute(string sessionId, string integrationMessage) { string agentIntegration = "Unknown Agent Integration"; string agentFullPath = "<unknown>"; try { AgentActionMessage executeAgentMessage = integrationMessage.XmlDeserialize <AgentActionMessage>(); agentIntegration = executeAgentMessage.IntegrationName ?? "Agent Integration"; agentFullPath = executeAgentMessage.AgentFullPath; if (!File.Exists(agentFullPath)) { #if DEBUG // send a message to the UI SendMessage(this, new MessageEventArgs(sessionId, new TrayMessage { Heading = agentIntegration, Text = String.Format("Agent executable not found: {0}", agentFullPath), Type = TrayMessage.MessageTypes.Warning })); #endif var logException = new MarvalApplicationException(String.Format(" Agent executable not found: {0} ", agentFullPath)); Log.Error(logException, String.Format("{0}: {1}: {2}", this.ActionName, agentIntegration, logException.Message)); return; } var agentExecution = ExecuteAgent(agentFullPath, executeAgentMessage.Parameters.Select(p => p.Value).ToArray()); agentExecution.Wait(10000); if (agentExecution.IsFaulted) { throw agentExecution.Exception; } var result = agentExecution.Result; var debugInfo = new MarvalApplicationException(String.Format("Success: {0} ", result)); Log.Debug(debugInfo, String.Format("{0}: {1}: {2}", this.ActionName, agentIntegration, debugInfo.Message)); #if DEBUG // send a message to the UI SendMessage(this, new MessageEventArgs(sessionId, new TrayMessage { Heading = agentIntegration, Text = "Successful agent execution", Type = TrayMessage.MessageTypes.Information })); #endif } catch (Exception e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, agentIntegration, (e.InnerException ?? e).Message)); if ((e is AggregateException) && (e.InnerException != null)) { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Error while executing {2}", this.ActionName, agentIntegration, agentFullPath ?? "<unset>"), e.InnerException)); } else { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Exception in agent integration", this.ActionName, agentIntegration), e)); } } }
/// <summary> /// Executes the action returning an number of messages. /// </summary> /// <param name="sessionId">The session Id of the user executing this action.</param> /// <param name="integrationMessage">Accepts a string integration message that can be deserialized into the required class.</param> public void Execute(string sessionId, string integrationMessage) { string postIntegration = "Unknown Post Integration"; string postBaseAddress = "<unknown>"; try { FormPostMessage postIntegrationMessage = integrationMessage.XmlDeserialize <FormPostMessage>(); postIntegration = postIntegrationMessage.IntegrationName ?? "Post Integration"; postBaseAddress = postIntegrationMessage.BaseUrl; var formValues = postIntegrationMessage.FormValues.ToDictionary(fv => fv.Key, fv => fv.Value); var additionalHeaders = postIntegrationMessage.Headers.ToDictionary(h => h.Key, h => h.Value); var formPost = PostForm(new Uri(postBaseAddress), postIntegrationMessage.PostEndpoint, formValues, additionalHeaders, ParseWebProxyInfo(postIntegrationMessage.Proxy)); formPost.Wait(10000); if (formPost.IsFaulted) { throw formPost.Exception; } var result = formPost.Result; var debugInfo = new MarvalApplicationException(String.Format("Success: {0} ({1}) - {2}", (int)result.StatusCode, result.StatusCode, result.ReasonPhrase)); Log.Debug(debugInfo, String.Format("{0}: {1}: {2}", this.ActionName, postIntegration, debugInfo.Message)); #if DEBUG // send a message to the UI SendMessage(this, new MessageEventArgs(sessionId, new TrayMessage { Heading = postIntegration, Text = "Successful postback", Type = TrayMessage.MessageTypes.Information })); #endif } catch (HttpRequestException e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, postIntegration, e.Message)); ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Unable to connect with {2}", this.ActionName, postIntegration, postBaseAddress ?? "<unset>"), e)); } catch (Exception e) { Log.Error(e, String.Format("{0}: {1}: {2}", this.ActionName, postIntegration, (e.InnerException ?? e).Message)); if ((e is AggregateException) && (e.InnerException != null)) { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Error while communicating with {2}", this.ActionName, postIntegration, postBaseAddress ?? "<unset>"), e.InnerException)); } else { ExceptionHandler.Publish(new MarvalApplicationException(String.Format("[{0}] {1}: Exception in Form Post Integration", this.ActionName, postIntegration), e)); } } }