/// <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> /// 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 async Task FromException() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); IHostedService service = this.GetHostedService(true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsNull(routable); }
public async Task AtomicError() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); IHostedService service = this.GetHostedService(false, false, true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Atomic Component")); }
/// <summary> /// Create a routable message. /// </summary> /// <param name="sourceFile">Full source of the file.</param> /// <param name="file">Byte array of the file.</param> private void CreateAndRoute(string sourceFile, byte[] file) { FileInfo info = new FileInfo(sourceFile); sourceFile = sourceFile.Replace("\\", "/"); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("SourceDirectory", System.IO.Path.GetDirectoryName(sourceFile)); headers.Add("SourceFile", System.IO.Path.GetFileName(sourceFile)); headers.Add("FullSource", sourceFile); headers.Add("DateCreated", info.CreationTimeUtc.ToLongDateString()); headers.Add("Readonly", info.IsReadOnly.ToString()); headers.Add("DataType", "byte"); headers.Add("FtpSource", this.ConstructFtpUri(this.settings.Path, System.IO.Path.GetFileName(sourceFile))); Routable dataItem = new Routable(headers, file); this.RaiseOnDownload(dataItem); }
public async Task ErrorComponentErrors() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; throw new ProcessException("Manual Error", new IndexOutOfRangeException("Random index")); }); IHostedService service = this.GetHostedService(false, false, true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Error Component")); }
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")); }
public void CanUploadFile(bool stringBody) { Mock <IWebRequestUtility> webRequestUtility = this.GetWebRequest(); To to = new To(this.GetRoute().Headers, webRequestUtility.Object); Routable routable = new Routable(new Dictionary <string, string>() { { "SourceFile", "Test.txt" } }, Encoding.UTF8.GetBytes("Hello") ); if (stringBody) { routable.SetBody <string>("Hello"); } to.Process(routable); webRequestUtility.VerifyAll(); }
public async Task CanRunDIComponent() { AutoResetEvent autoResetEvent = new AutoResetEvent(false); Routable routable = null; this.diProcessor.Reset(); this.diProcessor.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); IHostedService service = this.SetupDIComponent(); await service.StartAsync(CancellationToken.None); autoResetEvent.WaitOne(TimeSpan.FromSeconds(5)); await service.StopAsync(CancellationToken.None); Assert.AreEqual("Yes", routable.Headers["ComponentRan"]); }
/// <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> /// Gets the source to upload. /// </summary> /// <param name="item">Message to process.</param> /// <returns>Returns a byte array of the file.</returns> private byte[] GetSource(Routable item) { byte[] response = null; if (this.source == "File" || string.IsNullOrWhiteSpace(this.source)) { response = System.IO.File.ReadAllBytes(item.Headers["FullSource"]); } else { if (item.Headers.ContainsKey("DataType") && item.Headers["DataType"] == "String") { response = System.Text.Encoding.UTF8.GetBytes((string)item.Body); } else { response = (byte[])item.Body; } } return(response); }
public async Task ComponentError() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); this.processComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { throw new Kyameru.Core.Exceptions.ProcessException("Manual Error"); }); IHostedService service = this.GetHostedService(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Processing component")); }
/// <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")); } }
/// <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; } }
public void Process(Routable routable) { routable.SetBody <string>("Kyameru testing...sorry #notsorry"); }
public void Process(Routable routable) { this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Information, "Setting header")); routable.SetHeader("ComponentRan", "Yes"); }
public void Process(Routable routable) { throw new NotImplementedException("This is meant to throw an error"); }
/// <summary> /// Raises the on download event. /// </summary> /// <param name="routable">Message to route.</param> private void RaiseOnDownload(Routable routable) { this.OnDownloadFile?.Invoke(this, routable); }
/// <summary> /// Event raised when file is downloaded. /// </summary> /// <param name="sender">Object sending the event.</param> /// <param name="e">Message to route.</param> private void Ftp_OnDownloadFile(object sender, Routable e) { this.OnAction?.Invoke(this, e); }
public void Process(Routable routable) { this.Log(LogLevel.Information, routable.Headers["Test"]); }
/// <summary> /// Auswertung der Optionen /// </summary> /// <param name="args"></param> public void Evaluate(string[] args) { if (args == null) { return; } List <string> InputArray_Tmp = new List <string>(); try { cmd.Parse(args); foreach (MyOptions opt in Enum.GetValues(typeof(MyOptions))) // jede denkbare Option testen { int optcount = cmd.OptionAssignment((int)opt); // Wie oft wurde diese Option verwendet? string arg; if (optcount > 0) { switch (opt) { case MyOptions.Input: for (int i = 0; i < optcount; i++) { InputArray_Tmp.Add(cmd.StringValue((int)opt, i).Trim()); } break; case MyOptions.InputWithSubdirs: if (cmd.ArgIsUsed((int)opt)) { InputWithSubdirs = cmd.BooleanValue((int)opt); } else { InputWithSubdirs = true; } break; case MyOptions.InputListfile: InputArray_Tmp.AddRange(System.IO.File.ReadAllLines(cmd.StringValue((int)opt))); for (int i = InputArray_Tmp.Count - 1; i >= 0; i--) { InputArray_Tmp[i] = InputArray_Tmp[i].Trim(); if (InputArray_Tmp[i].Length == 0) { InputArray_Tmp.RemoveAt(i); } } break; case MyOptions.Output: Output = cmd.StringValue((int)opt).Trim(); break; case MyOptions.OutputOverwrite: if (cmd.ArgIsUsed((int)opt)) { OutputOverwrite = cmd.BooleanValue((int)opt); } else { OutputOverwrite = true; } break; case MyOptions.Info: if (cmd.ArgIsUsed((int)opt)) { switch (cmd.UnsignedIntegerValue((int)opt)) { case 0: ToDo = ToDoType.Info; break; case 1: ToDo = ToDoType.LongInfo; break; case 2: ToDo = ToDoType.ExtLongInfo; break; default: ToDo = ToDoType.VeryLongInfo; break; } } else { ToDo = ToDoType.Info; } break; case MyOptions.Split: if (cmd.ArgIsUsed((int)opt)) { arg = cmd.StringValue((int)opt); if (arg == "r") { ToDo = ToDoType.SplitRecursive; } else if (arg == "j") { ToDo = ToDoType.SplitJoin; } else if (arg == "rj" || arg == "jr") { ToDo = ToDoType.SplitRecursiveJoin; } } else { ToDo = ToDoType.Split; } break; case MyOptions.CreateFiles4Mapsource: for (int i = 0; i < optcount; i++) { if (cmd.ArgIsUsed((int)opt, i)) { arg = cmd.StringValue((int)opt, i); if (!string.IsNullOrEmpty(arg)) { if (arg.StartsWith("pid:")) { PID.Set(InterpretUInt(arg)); } else if (arg.StartsWith("fid:")) { FID.Set(InterpretUInt(arg)); } else if (arg.StartsWith("cp:")) { Codepage.Set(InterpretUInt(arg)); //} else if (arg.StartsWith("ovno:")) { // MapsourceOverviewNo.Set(InterpretUInt(arg)); } else if (arg.StartsWith("ov:")) { MapsourceOverviewfile.Set(arg.Substring(3)); } else if (arg.StartsWith("typ:")) { MapsourceTYPfile.Set(arg.Substring(4)); } else if (arg.StartsWith("tdb:")) { MapsourceTDBfile.Set(arg.Substring(4)); } else if (arg.StartsWith("mdx:")) { MapsourceMDXfile.Set(arg.Substring(4)); } else if (arg.StartsWith("mdr:")) { MapsourceMDRfile.Set(arg.Substring(4)); } else if (arg.StartsWith("tdb:")) { MapsourceTDBfile.Set(arg.Substring(4)); } else if (arg.StartsWith("mindim:")) { MapsourceMinDimension.Set(InterpretUInt(arg)); } else if (arg.StartsWith("points:")) { InterpretTypes(arg, MapsourceOVPointtypes); } else if (arg.StartsWith("lines:")) { InterpretTypes(arg, MapsourceOVLinetypes); } else if (arg.StartsWith("areas:")) { InterpretTypes(arg, MapsourceOVAreatypes); } else if (arg == "noov") { MapsourceNoOverviewfile.Set(true); } else if (arg == "notyp") { MapsourceNoTYPfile.Set(true); } else if (arg == "nomdx") { MapsourceNoMDXfile.Set(true); } else if (arg == "nomdr") { MapsourceNoMDRfile.Set(true); } else if (arg == "notdb") { MapsourceNoTDBfile.Set(true); } else if (arg == "noinst") { MapsourceNoInstfiles.Set(true); } else { throw new Exception("unbekanntes Argument: " + arg); } } } } ToDo = ToDoType.CreateFiles4Mapsource; break; case MyOptions.Join: if (cmd.ArgIsUsed((int)opt)) { arg = cmd.StringValue((int)opt); if (arg == "device") { ToDo = ToDoType.JoinDevice; } else if (arg == "tile") { ToDo = ToDoType.JoinTile; } } else { ToDo = ToDoType.Join; } break; case MyOptions.AnalyzingTypes: switch (cmd.UnsignedIntegerValue((int)opt)) { case 1: ToDo = ToDoType.AnalyzingTypesLong; break; default: ToDo = ToDoType.AnalyzingTypes; break; } break; case MyOptions.SetPID: PID.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetFID: FID.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetCodepage: Codepage.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetTDBCopyright: for (int j = 0; j < optcount; j++) { arg = cmd.StringValue((int)opt, j); if (arg.Length < 3) { throw new Exception("Falscher Aufbau der Copyright-Option '" + arg + "'"); } else { switch (arg[0]) { case 'S': TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.SourceInformation, true)); break; case 'C': TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.CopyrightInformation, true)); break; case '*': TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.Unknown, true)); break; default: throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[0] + "'"); } switch (arg[1]) { case 'I': TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.ProductInformation, true)); break; case 'P': TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.Printing, true)); break; case 'E': TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.ProductInformationAndPrinting, true)); break; case '*': TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.Unknown, true)); break; default: throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[1] + "'"); } switch (arg[2]) { case 'N': string sText = arg.Substring(3).Trim(); if (sText.Length >= 2) { if (sText[0] == '"' && sText[sText.Length - 1] == '"') { sText = sText.Substring(1, sText.Length - 2); } } TDBCopyrightText.Add(new Property(sText, true)); break; case 'D': TDBCopyrightText.Add(new Property(null, false)); break; case '*': TDBCopyrightText.Add(new Property(null, true)); break; default: throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[1] + "'"); } } } break; case MyOptions.SetDescription: Description.Set(cmd.StringValue((int)opt)); break; case MyOptions.SetTransparent: Transparent.Set(cmd.BooleanValue((int)opt) ? 1 : 0); break; case MyOptions.SetPriority: Priority.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetMapFamilyName: MapFamilyName.Set(cmd.StringValue((int)opt)); break; case MyOptions.SetMapSeriesName: MapSeriesName.Set(cmd.StringValue((int)opt)); break; case MyOptions.SetVersion: Version.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetRoutable: Routable.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetHighestRoutable: HighestRoutable.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetHasDEM: HasDEM.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetHasProfile: HasProfile.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.SetMaxCoordBits4Overview: MaxCoordBits4Overview.Set((int)cmd.UnsignedIntegerValue((int)opt)); break; case MyOptions.RefreshTDB: ToDo = ToDoType.RefreshTDB; break; case MyOptions.NewTypfile: NewTypfile.Set(cmd.StringValue((int)opt)); ToDo = ToDoType.SetNewTypfile; break; case MyOptions.Help: ShowHelp(); break; } } } //TestParameter = new string[cmd.Parameters.Count]; //cmd.Parameters.CopyTo(TestParameter); if (cmd.Parameters.Count > 0) { throw new Exception("Es sind keine Argumente sondern nur Optionen erlaubt."); } Input = new string[InputArray_Tmp.Count]; InputArray_Tmp.CopyTo(Input); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); ShowHelp(); throw new Exception("Fehler beim Ermitteln oder Anwenden der Programmoptionen."); } }
public void CreatedHeaderError() { Routable routable = this.CreateMessage(); Assert.Throws <Kyameru.Core.Exceptions.CoreException>(() => routable.SetHeader("Test", "changed")); }
public void Process(Routable routable) { routable.SetBody <string>(System.Text.Encoding.UTF8.GetString( (byte[])routable.Body)); this.Log(LogLevel.Information, routable.Headers["DataType"]); }
public void Process(Routable item) { this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Error, "I have been called, i am your error component")); }
/// <summary> /// Process the message. /// </summary> /// <param name="item">Message to process.</param> public void Process(Routable item) { this.toActions[this.headers["Action"]](item); }
public void Process(Routable item) { this.OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Information, "ATOMIC")); GlobalCalls.Calls.Add("ATOMIC"); }
public bool IsEqual(Routable routable) { routable.SetBody <T>(item); return(expected == routable.Headers["DataType"]); }
public void Process(Routable item) { GlobalCalls.Calls.Add("TO"); item.SetBody <string>("Injected Test Complete"); this.OnLog?.Invoke(this, new Log(LogLevel.Information, "TO")); }