static void Main(string[] args) { IOutput stringOutput = new StringOutput(); EmployeeComponent director = new Employee("Director", Program.POSITIONS[0], 20); EmployeeComponent manager = new Employee("Manager of storing", POSITIONS[1], 15); EmployeeComponent manager2 = new Employee("Manager of marketing", POSITIONS[1], 12); EmployeeComponent x = new SubEmployee("X", POSITIONS[2], 10); EmployeeComponent y = new SubEmployee("Y", POSITIONS[2], 10); EmployeeComponent a = new SubEmployee("A", POSITIONS[2], 10); EmployeeComponent b = new SubEmployee("B", POSITIONS[2], 10); EmployeeComponent c = new Employee("Another one manager", POSITIONS[1], 10); EmployeeComponent d = new SubEmployee("D", POSITIONS[2], 10); director.Add(manager, manager2); manager.Add(x, y, c); manager2.Add(a, b); c.Add(d); Company company = new Company(director, stringOutput); System.Console.WriteLine("----------"); company.PrintHierarchy(); System.Console.WriteLine("----------"); company.PrintAllByPosition("manager"); System.Console.WriteLine("----------"); company.PrintAllWithHighestSalaryAndHigherThan(9); System.Console.WriteLine("----------"); company.PrintAllWithParent(manager); System.Console.WriteLine("----------"); company.PrintBackwards(); System.Console.WriteLine("----------"); System.Console.ReadKey(); }
public static PooledObject <StringOutput> Get(int capacity, out StringOutput value) { var po = s_Pool.Get(out value); value.SetCapacity(capacity); return(po); }
private void AffRich(Instruction instruction, RichTextBox richTextBox, StringOutput stringOutput, byte[] buffer, ulong CodeRIP) { const int HEXBYTES_COLUMN_BYTE_LENGTH = 10; var formatter = new MasmFormatter(); formatter.Format(instruction, stringOutput); richTextBox.AppendText(instruction.IP.ToString("X16")); richTextBox.AppendText(" "); int instrLen = instruction.Length; int byteBaseIndex = (int)(instruction.IP - CodeRIP); for (int i = 0; i < instrLen; i++) { richTextBox.AppendText(buffer[byteBaseIndex + i].ToString("X2")); } int missingBytes = HEXBYTES_COLUMN_BYTE_LENGTH - instrLen; for (int i = 0; i < missingBytes; i++) { richTextBox.AppendText(" "); } richTextBox.AppendText(" "); string endasm = stringOutput.ToStringAndReset().PadRight(60); richTextBox.AppendText(endasm + Environment.NewLine); }
public static void Disassemble(ManualLogSource logSource, IntPtr memoryPtr, int size) { var data = new byte[size]; Marshal.Copy(memoryPtr, data, 0, size); var formatter = new NasmFormatter(); var output = new StringOutput(); var codeReader = new ByteArrayCodeReader(data); var decoder = Decoder.Create(64, codeReader); decoder.IP = (ulong)memoryPtr.ToInt64(); while (codeReader.CanReadByte) { decoder.Decode(out var instr); formatter.Format(instr, output); logSource.LogDebug($"{instr.IP:X16} {output.ToStringAndReset()}"); if (instr.Code == Code.Jmp_rm64 && instr.Immediate32 == 0 ) // && instr.IsIPRelativeMemoryOperand && instr.IPRelativeMemoryAddress = 6 { var address = new byte[8]; for (var i = 0; i < 8; i++) { address[i] = (byte)codeReader.ReadByte(); } logSource.LogDebug($"{instr.IP + (ulong) instr.Length:X16} db 0x{BitConverter.ToUInt64(address, 0):X16}"); decoder.IP += 8; } } }
public void StringOutputTest() { var so = new StringOutput(); so.Write("text", 0, 2, null); Assert.AreEqual("te", so.ToString()); }
public void Output_Of_String() { var so = new StringOutput(16); so.Write("text", null !); Assert.AreEqual("text", so.ToString()); }
public async Task WriteHttpRequests_ShouldWriteRequestsFromAllClients() { // Arrange (var services, var httpServer) = BuildServicesWithClientNaivelyMocked(); var client = services.GetRequiredService <TestClient>(); var client2 = services.GetRequiredService <TestClient>(); var output = new StringOutput(); // Act await client.DoAsync(); await client2.DoAsync(); httpServer.WriteHttpRequests(output); // Assert Assert.Equal( @"Method: GET, RequestUri: 'https://example.com/test', Version: 2.0, Content: <null>, Headers: { } TestClient Method: GET, RequestUri: 'https://example.com/test', Version: 2.0, Content: <null>, Headers: { } TestClient ", output.Content); }
public void DetachAllSigEventHandlers() { BooleanOutput.Where(bo => bo.UserObject is UnifiedSigUserObject).ToList().ForEach(bo => bo.UserObject = ((UnifiedSigUserObject)bo.UserObject).UserObject); UShortOutput.Where(uo => uo.UserObject is UnifiedSigUserObject).ToList().ForEach(uo => uo.UserObject = ((UnifiedSigUserObject)uo.UserObject).UserObject); StringOutput.Where(so => so.UserObject is UnifiedSigUserObject).ToList().ForEach(so => so.UserObject = ((UnifiedSigUserObject)so.UserObject).UserObject); UShortInput.Where(ui => ui.UserObject is UnifiedSigUserObject).ToList().ForEach(ui => ui.UserObject = ((UnifiedSigUserObject)ui.UserObject).UserObject); }
private static void DecodeMethod(IntPtr ptr, uint size, StringBuilder builder, Formatter formatter) { // You can also pass in a hex string, eg. "90 91 929394", or you can use your own CodeReader // reading data from a file or memory etc. var codeReader = new UnmanagedCodeReader(ptr, size); var decoder = Decoder.Create(IntPtr.Size * 8, codeReader); decoder.IP = (ulong)ptr.ToInt64(); ulong endRip = decoder.IP + (uint)size; // This list is faster than List<Instruction> since it uses refs to the Instructions // instead of copying them (each Instruction is 32 bytes in size). It has a ref indexer, // and a ref iterator. Add() uses 'in' (ref readonly). var instructions = new InstructionList(); while (decoder.IP < endRip) { // The method allocates an uninitialized element at the end of the list and // returns a reference to it which is initialized by Decode(). decoder.Decode(out instructions.AllocUninitializedElement()); } var output = new StringOutput(); // Use InstructionList's ref iterator (C# 7.3) to prevent copying 32 bytes every iteration foreach (ref var instr in instructions) { // Don't use instr.ToString(), it allocates more, uses masm syntax and default options formatter.Format(in instr, output); builder.AppendLine($"{instr.IP:X16} {output.ToStringAndReset()}"); } }
static void Main(string[] args) { //ActionHandler //new ActionHandler().Init(); //StringBuilderNullRef //new StringBuilderNullRef().Init(); //StringBuilderExample //new StringBuilderExample().Init(); //Array output //ArrayOutput.Init(); //String invariant //StringInvariant.Init(); //Static access //StaticMethodAccess.Init(); //Dynamic variable type //DynamicKeyword.Init(); //String output //StringOutput.Init(); StringOutput.Init("33"); //Increment output //IncrementOperator.Init(); Console.ReadLine(); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); string htmlInput = HtmlInput.Get <string>(executionContext); tracingService.Trace("String supplied = " + htmlInput, htmlInput); string textOutput = string.Empty; //string pattern = "(<div.*>)(.*)(<\\/div>)"; //tracingService.Trace("Applying the following regex pattern: "+ pattern, pattern); //MatchCollection matches = Regex.Matches(htmlInput, pattern); //if (matches.Count > 0) //{ // foreach (Match m in matches) // { // StringOutput.Set(executionContext, HtmlToPlainText(m.Value)); // tracingService.Trace("The results returned are: "+m.Value , m.Value); // } //} StringOutput.Set(executionContext, HtmlToPlainText(htmlInput)); }
/// <summary> /// Initializes a new instance of the <see cref="L20nCore.Objects.StringValue"/> class /// with the format string (<c>value</c>) and the <c>expressions</c> /// given by the callee of this constructor. /// </summary> public StringValue(string value, L20nObject[] expressions) { m_Value = value; m_Expressions = expressions; m_EvaluatedExpressions = new string[expressions.Length]; m_Output = new StringOutput(); }
static void Main(string[] args) { int exampleCodeBitness = 32; if (args.Length == 2) { switch (args[0]) { case "32": { exampleCodeBitness = 32; break; } case "64": { exampleCodeBitness = 64; break; } default: break; } } else { Console.Write("Must use arguments: <bit-length[32|64]> <target file path>"); return; } string filePath = args[1]; BinaryReader reader = new BinaryReader(File.Open(filePath, FileMode.Open)); var fileSize = Convert.ToInt32(new FileInfo(filePath).Length); var codeBytes = reader.ReadBytes(fileSize); var sw = Stopwatch.StartNew(); var codeReader = new ByteArrayCodeReader(codeBytes); var decoder = Decoder.Create(exampleCodeBitness, codeReader); decoder.IP = exampleCodeRIP; ulong endRip = decoder.IP + (uint)codeBytes.Length; var instructions = new InstructionList(); while (decoder.IP < endRip) { decoder.Decode(out instructions.AllocUninitializedElement()); } var formatter = new MasmFormatter(); formatter.Options.DigitSeparator = "`"; formatter.Options.FirstOperandCharIndex = 10; var output = new StringOutput(); foreach (ref var instr in instructions) { formatter.Format(instr, output); Console.WriteLine(instr.IP.ToString("X8") + " " + output.ToStringAndReset()); } sw.Stop(); Console.Error.WriteLine("Total dump time: {0:F} sec.", sw.Elapsed.TotalSeconds); }
public void Output_Of_ValueStringBuilder() { var so = new StringOutput(); using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder(); sb.Append("text"); so.Write(sb, null !); Assert.AreEqual("text", so.ToString()); }
void SignalIn_Edited(INodeWrapper sender, NodeBase oldNode, NodeBase newNode) { var oldSignalIn = oldNode as NodeSignalIn; var newSignalIn = newNode as NodeSignalIn; if (oldSignalIn != null && newSignalIn != null) { StringOutput = StringOutput.SetSignalIn(newSignalIn); } }
private void SetOutputValues(ActivityContext context, double value) { StringOutput.Set(context, String.Format("{0:0.0#####}", value)); MoneyOutput.Set(context, new Money { Value = Convert.ToDecimal(Math.Round(value, 2)) }); TruncatedOutput.Set(context, Convert.ToInt32(Math.Truncate(value))); RoundedOutput.Set(context, Math.Round(value, 0)); FloatOutput.Set(context, value); }
/// <summary> /// Replaces one or more format items in a specified string with the string representation of a specific object. /// </summary> /// <param name="provider">The <see cref="IFormatProvider" /> to use.</param> /// <param name="format">A composite format string.</param> /// <param name="args">The object to format.</param> /// <returns>Returns the formatted input with items replaced with their string representation.</returns> public string Format(IFormatProvider?provider, string format, params object[] args) { var output = new StringOutput(format.Length + args.Length * 8); var formatParsed = Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames()); var current = args.Length > 0 ? args[0] : args; // The first item is the default. var formatDetails = new FormatDetails(this, formatParsed, args, null, provider, output); Format(formatDetails, formatParsed, current); return(output.ToString()); }
public void ReturnBytesToString_Test() { var output = new StringOutput() { StringValue = "test-out" }; var objString = _callHandler.ReturnBytesToString(output.ToByteArray()); objString.ShouldNotBeNullOrEmpty(); objString.Contains("test-out").ShouldBeTrue(); }
public void Format_WithCache_Into_StringOutput() { var data = new { Name = "Joe", City = "Melbourne" }; var formatter = GetSimpleFormatter(); var formatString = "{Name}, {City}"; var format = formatter.Parser.ParseFormat(formatString); var output = new StringOutput(); formatter.FormatInto(output, null, format, data); Assert.That(output.ToString(), Is.EqualTo($"{data.Name}, {data.City}")); }
void StringOutput_uses_input_sb() { var sb = new System.Text.StringBuilder(); sb.Append("Text"); var output = new StringOutput(sb); output.Write("hello", FormatterTextKind.Text); Assert.Equal("Texthello", sb.ToString()); Assert.Equal("Texthello", output.ToString()); }
public void ReturnBytesToString_Test() { var callHandler = CreateServerCallHandler(); var output = new StringOutput() { StringValue = "test-out" }; var objString = callHandler.ReturnBytesToString(output.ToByteArray()); objString.ShouldBe("{ \"stringValue\": \"test-out\" }"); }
/// <summary> /// Replaces one or more format items in a specified string with the string representation of a specific object, /// using the <see cref="FormatCache"/>. /// </summary> /// <param name="cache">The <see cref="FormatCache" /> to use.</param> /// <param name="format">A composite format string.</param> /// <param name="args">The objects to format.</param> /// <returns>Returns the formatted input with items replaced with their string representation.</returns> public string FormatWithCache(ref FormatCache?cache, string format, params object[] args) { var output = new StringOutput(format.Length + args.Length * 8); cache ??= new FormatCache(Parser.ParseFormat(format, GetNotEmptyFormatterExtensionNames())); var current = args.Length > 0 ? args[0] : args; // The first item is the default. var formatDetails = new FormatDetails(this, cache.Format, args, cache, null, output); Format(formatDetails, cache.Format, current); return(output.ToString()); }
private void DisplayResults() { CustomConsole.WriteLine(); ValueOutput <bool> .QuickDisplay("Are texts the same", loremIpsum != stringBuilder.ToString()); CustomConsole.WriteLine(); TimeSpan averageTime = testRunner.CalculateAverage(); StringOutput.QuickDisplay("Average: ", averageTime.TotalMilliseconds + " ms"); }
internal static string Format(Instruction instruction, Formatter formatter, bool printInstructionAddresses, uint pointerSize) { var output = new StringOutput(); if (printInstructionAddresses) { FormatInstructionPointer(instruction, formatter, pointerSize, output); } formatter.Format(instruction, output); return(output.ToString()); }
public void ToString_StringInput_ReturnsString() { //arrange string input = "item1"; IOutput output = new StringOutput(input); //act string result = output.ToString(); //assert Assert.NotNull(output); Assert.NotNull(result); Assert.Equal("item1", result); }
private void DisplayResults() { TimeSpan averageTime = testRunner.CalculateAverage(); StringOutput stringOutput = new StringOutput { Label = "Average:", MarginTop = 1, MarginBottom = 1, Value = averageTime.TotalMilliseconds + " ms" }; stringOutput.Display(); }
public void ReturnBytesToObject_Test() { var output = new StringOutput { StringValue = "test-out" }; var objInfo = _callHandler.ReturnBytesToObject(output.ToByteArray()); objInfo.ShouldNotBeNull(); var output1 = (StringOutput)objInfo; output1.ShouldBe(output); }
private void OnSigChange(SigEventArgs args) { UnifiedSigEventArgs usea = new UnifiedSigEventArgs(args); switch (args.Event) { case eSigEvent.BoolOutputSigsCleared: BooleanOutput.Where(bo => bo.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)bo.UserObject).UnifiedSigEvents != null).Select(bo => ((UnifiedSigUserObject)bo.UserObject).UnifiedSigEvents).ToList().ForEach(lc => lc.FindAll(u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.BoolChange)).ForEach(u => u.SigChange(this, usea))); break; case eSigEvent.UShortOutputSigsCleared: UShortOutput.Where(uo => uo.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)uo.UserObject).UnifiedSigEvents != null).Select(uo => ((UnifiedSigUserObject)uo.UserObject).UnifiedSigEvents).ToList().ForEach(lc => lc.FindAll(u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.UShortChange)).ForEach(u => u.SigChange(this, usea))); break; case eSigEvent.StringOutputSigsCleared: StringOutput.Where(so => so.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)so.UserObject).UnifiedSigEvents != null).Select(so => ((UnifiedSigUserObject)so.UserObject).UnifiedSigEvents).ToList().ForEach(lc => lc.FindAll(u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.StringChange)).ForEach(u => u.SigChange(this, usea))); break; default: var uuo = args.Sig.UserObject as UnifiedSigUserObject; if (uuo == null) { return; } if (uuo.UnifiedSigEvents == null || uuo.UnifiedSigEvents.Count == 0) { args.Sig.UserObject = uuo.UserObject; return; } switch (args.Sig.Type) { case eSigType.Bool: usea.BoolValue = args.Sig.BoolValue; break; case eSigType.UShort: usea.UShortValue = args.Sig.UShortValue; break; case eSigType.String: usea.StringValue = args.Sig.StringValue; break; } uuo.UnifiedSigEvents.FindAll(u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == args.Event)).ForEach(u => u.SigChange(this, usea)); break; } }
public void ToList_StringInput_ReturnsListWithSingleItem() { //arrange string input = "item1"; IOutput output = new StringOutput(input); //act List <String> results = output.ToList(); //assert Assert.NotNull(output); Assert.NotNull(results); Assert.NotEmpty(results); Assert.True(results.Count == 1); }
void FormatMnemonicOptions(string hexBytes, Code code, int bitness, string formattedString, FormatMnemonicOptions options) { var decoder = Decoder.Create(bitness, new ByteArrayCodeReader(hexBytes)); decoder.Decode(out var instruction); Assert.Equal(code, instruction.Code); var formatter = FormatterFactory.Create(); var output = new StringOutput(); formatter.FormatMnemonic(instruction, output, options); var actualFormattedString = output.ToStringAndReset(); #pragma warning disable xUnit2006 // Do not use invalid string equality check // Show the full string without ellipses by using Equal<string>() instead of Equal() Assert.Equal <string>(formattedString, actualFormattedString); #pragma warning restore xUnit2006 // Do not use invalid string equality check }
void DisplInBrackets(string hexBytes, int bitness, string formattedString, Flags flags) { var decoder = Decoder.Create(bitness, new ByteArrayCodeReader(hexBytes)); decoder.IP = bitness switch { 16 => DecoderConstants.DEFAULT_IP16, 32 => DecoderConstants.DEFAULT_IP32, 64 => DecoderConstants.DEFAULT_IP64, _ => throw new InvalidOperationException(), }; decoder.Decode(out var instruction); var resolver = new TestSymbolResolver { tryGetSymbol = (in Instruction instruction, int operand, int instructionOperand, ulong address, int addressSize, out SymbolResult symbol) => { if (instructionOperand == 1 && (flags & Flags.Symbol) != 0) { symbol = new SymbolResult(address, "symbol", FormatterTextKind.Data, (flags & Flags.Signed) != 0 ? SymbolFlags.Signed : SymbolFlags.None); return(true); } symbol = default; return(false); }, }; var formatter = (MasmFormatter)FormatterFactory.Create_Resolver(resolver).formatter; formatter.MasmOptions.SymbolDisplInBrackets = (flags & Flags.SymbolDisplInBrackets) != 0; formatter.MasmOptions.DisplInBrackets = (flags & Flags.DisplInBrackets) != 0; formatter.MasmOptions.RipRelativeAddresses = (flags & Flags.Rip) != 0; formatter.MasmOptions.ShowZeroDisplacements = (flags & Flags.ShowZeroDisplacements) != 0; formatter.MasmOptions.AddDsPrefix32 = (flags & Flags.NoAddDsPrefix32) == 0; var output = new StringOutput(); formatter.Format(instruction, output); var actualFormattedString = output.ToStringAndReset(); #pragma warning disable xUnit2006 // Do not use invalid string equality check // Show the full string without ellipses by using Equal<string>() instead of Equal() Assert.Equal <string>(formattedString, actualFormattedString); #pragma warning restore xUnit2006 // Do not use invalid string equality check }