/// <summary> /// Processes the message. /// </summary> /// <param name="item">Message to process.</param> public void Process(Routable item) { Payload slackPayload = new Payload() { text = this.GetMessageSource(item), channel = this.GetHeader("Channel"), username = this.GetHeader("Username") }; if (item.Error == null) { var payloadJson = JsonSerializer.Serialize(slackPayload); string uri = $"{SLACKURI}{this.headers["Target"]}"; var dataContent = new StringContent(payloadJson, Encoding.UTF8, "application/json"); using (HttpClient client = this.GetHttpClient()) { this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Information, "Sending slack message")); var response = client.PostAsync(uri, dataContent).Result; if (!response.IsSuccessStatusCode) { item.SetInError(this.RaiseError("SendSlackMessage", "Error communicating with slack.")); } } } }
/// <summary> /// Deletes source file. /// </summary> /// <param name="item">Message to process.</param> private void DeleteFile(Routable item) { this.Log(LogLevel.Information, string.Format(Resources.INFO_ACTION_DELETE, item.Headers["SourceFile"])); try { this.fileUtils.Delete(item.Headers["FullSource"]); } catch (Exception ex) { this.Log(LogLevel.Error, Resources.ERROR_ACTION_DELETE, ex); item.SetInError(this.RaiseError("DeleteError", "Error writing file")); } }
/// <summary> /// Process Message. /// </summary> /// <param name="item">Message to process.</param> public void Process(Routable item) { try { this.ftpClient.UploadFile(this.GetSource(item), item.Headers["SourceFile"]); this.ArchiveFile(item); } catch (Exception ex) { item.SetInError(this.GetError("Upload", string.Format(Resources.ERROR_UPLOADING, item.Headers["FileName"]))); this.RaiseLog(string.Format(Resources.ERROR_UPLOADING, item.Headers["FileName"]), LogLevel.Error, ex); } }
/// <summary> /// Copies the source file but leaves original in place. /// </summary> /// <param name="item">Message to process.</param> private void CopyFile(Routable item) { this.Log(LogLevel.Information, string.Format(Resources.INFO_ACTION_COPY, item.Headers["SourceFile"])); try { this.EnsureDestinationExists(); this.fileUtils.CopyFile(item.Headers["FullSource"], this.GetDestination(item.Headers["SourceFile"]), this.overwrite); } catch (Exception ex) { this.Log(LogLevel.Error, Resources.ERROR_ACTION_COPY, ex); item.SetInError(this.RaiseError("CopyFile", "Error writing file")); } }
/// <summary> /// Process the incoming message. /// </summary> /// <param name="routable">Routable message.</param> public void Process(Routable routable) { this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Debug, Resources.DEBUG_HEADER_DETERMINE)); switch (this.callbackOption) { case 0: this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Debug, Resources.DEBUG_HEADER_RUNNING)); routable.SetHeader(this.header, this.value); break; case 1: try { routable.SetHeader(this.header, this.callback()); } catch (Exception ex) { routable.SetInError(this.SetError("Callback", Resources.ERROR_HEADER_CALLBACK)); this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Error, Resources.ERROR_HEADER_CALLBACK, ex)); } break; case 2: try { routable.SetHeader(this.header, this.callbackTwo(routable)); } catch (Exception ex) { routable.SetInError(this.SetError("Callback", Resources.ERROR_HEADER_CALLBACK)); this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Error, Resources.ERROR_HEADER_CALLBACK, ex)); } break; } }
/// <summary> /// Passes processing to the next in the chain. /// </summary> /// <param name="item">Message to process.</param> public override void Handle(Routable item) { if (item.InError) { try { this.errorComponent.Process(item); } catch (Exception ex) { this.Logger.KyameruException(this.identity, ex.Message, ex); item.SetInError(new Entities.Error("Error Component", "Handle", ex.Message)); } } }
public void Process(Routable item) { if (this.Headers["Host"] == "kyameru") { this.OnLog.Invoke(this, new Log(LogLevel.Warning, "Will not process")); item.SetInError(new Error("To", "Process", "Error")); GlobalCalls.Calls.Add("TO"); this.OnLog?.Invoke(this, new Log(LogLevel.Error, "Error", new ArgumentException("Error"))); } if (item.Headers.ContainsKey("SetExit") && item.Headers["SetExit"] == "true") { item.SetExitRoute("Exit triggered"); } GlobalCalls.Calls.Add("TO"); this.OnLog?.Invoke(this, new Log(LogLevel.Information, "TO")); }
/// <summary> /// Gets the message source. /// </summary> /// <param name="routable">Message to process.</param> /// <returns>Returns the message to send via slack.</returns> private string GetMessageSource(Routable routable) { string response = string.Empty; if (this.headers.ContainsKey("MessageSource") && this.headers["MessageSource"].ToLower() == "body") { response = (string)routable.Body; } else if (routable.Headers.ContainsKey("SlackMessage")) { response = routable.Headers["SlackMessage"]; } else { routable.SetInError(this.RaiseError("GettingMessageSource", "Error getting message source.")); } return(response); }
/// <summary> /// Writes a file to disk. /// </summary> /// <param name="item">Message to process.</param> private void WriteFile(Routable item) { this.Log(LogLevel.Information, string.Format(Resources.INFO_ACTION_WRITE, item.Headers["SourceFile"])); try { this.EnsureDestinationExists(); if (item.Headers["DataType"] == "String") { this.fileUtils.WriteAllText(this.GetDestination(item.Headers["SourceFile"]), (string)item.Body, this.overwrite); } else { this.fileUtils.WriteAllBytes(this.GetDestination(item.Headers["SourceFile"]), (byte[])item.Body, this.overwrite); } this.DeleteFile(item); } catch (Exception ex) { this.Log(LogLevel.Error, Resources.ERROR_ACTION_WRITE, ex); item.SetInError(this.RaiseError("WriteFile", "Error writing file")); } }