public static IList <Function> ParseMultiple(string input, IStringWriter stringWriter) { // Split input to function parts var functionValues = input.Split(Environment.NewLine + Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); // Check if all functions match the pattern if (functionValues.Any(x => !ParseCheck.IsMatch(x))) { return(Array.Empty <Function>()); } // Write all function names foreach (var functionValue in functionValues.OrderBy(x => stringWriter.GetHash(GetFunctionName(x)))) { stringWriter.Write(GetFunctionName(functionValue)); } // Write all jump labels foreach (var functionValue in functionValues) { var functionBody = GetFunctionBody(functionValue); var jumps = GetJumpLabels(functionBody).OrderBy(x => stringWriter.GetHash(x.label)); foreach (var jump in jumps) { stringWriter.Write(jump.label); } } // Parse all functions return(functionValues.Select(x => Parse(x, stringWriter)).ToArray()); }
// TODO: Try to detect type from value itself public static Argument Parse(int subType, string input, IStringWriter stringWriter) { if (!ParseCheck.IsMatch(input)) { return(null); } var type = GetArgumentType(input); var value = GetArgumentValue(input); switch (type) { case 1: return(new Argument(type, long.Parse(value))); case 2: if (subType != 0x14 && subType != 0x1E && subType != 0x1F && subType != 0x21) { return(new Argument(type, long.Parse(value))); } if (!StringValue.IsMatch(value)) { return(new Argument(type, long.Parse(value))); } var stringValue = StringValue.Match(value).Groups.Values.Skip(1).First().Value; stringWriter.Write(stringValue); var stringHash = stringWriter.GetHash(stringValue); return(new Argument(type, stringHash)); case 3: return(new Argument(type, BitConverter.SingleToInt32Bits(float.Parse(value, CultureInfo.GetCultureInfo("en-gb"))))); case 4: if (!IsParameter.IsMatch(value)) { return(new Argument(type, long.Parse(value))); } var argumentValue = IsParameter.Match(value).Groups.Values.Skip(1).First().Value; var argType = value[0]; var offset = argType == 'v' ? 1000 : argType == 'x' ? 2000 : argType == 'p' ? 3000 : 4000; return(new Argument(type, long.Parse(argumentValue) + offset)); case 24: var stringValue1 = StringValue.Match(value).Groups.Values.Skip(1).First().Value; return(new Argument(type, stringWriter.Write(stringValue1))); case 25: var stringValue2 = StringValue.Match(value).Groups.Values.Skip(1).First().Value; return(new Argument(type, stringWriter.Write(stringValue2))); default: return(null); } }
public EmailFooEventHandler(IStringWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _writer = writer; }
public CommandDecorator(IStringWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _writer = writer; }
public App(IStringWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _writer = writer; }
public QueryLoggingFilter(IStringWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _writer = writer; }
public BarCommandHandler(IStringWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _writer = writer; }
public RsaKeyPersister( IKeyToExternalRepresentationMapper <RsaKey, EnvCryptKey> pocoMapper, IXmlSerializationUtils <EnvCryptKey> serializationUtils, IStringWriter <StringToFileWriterOptions> writer) : base(pocoMapper, serializationUtils, writer) { Contract.Requires <ArgumentNullException>(pocoMapper != null, "pocoMapper"); Contract.Requires <ArgumentNullException>(serializationUtils != null, "serializationUtils"); Contract.Requires <ArgumentNullException>(writer != null, "writer"); }
public ModelBasedReportController(ReportService reportService, IReportConverter <HtmlReportCell> htmlConverter, IStringWriter stringWriter, IReportConverter <ExcelReportCell> excelConverter, IEpplusWriter excelWriter, ProductService productService, UserService userService) { this.reportService = reportService; this.htmlConverter = htmlConverter; this.stringWriter = stringWriter; this.excelConverter = excelConverter; this.excelWriter = excelWriter; this.productService = productService; this.userService = userService; }
public DatToXmlFileSaver(IDatToExternalRepresentationMapper <EnvCryptEncryptedData> pocoToXmlMapper, IXmlSerializationUtils <EnvCryptEncryptedData> serializationUtils, IStringWriter <StringToFileWriterOptions> fileWriter) { Contract.Requires <ArgumentNullException>(pocoToXmlMapper != null, "pocoToXmlMapper"); Contract.Requires <ArgumentNullException>(serializationUtils != null, "serializationUtils"); Contract.Requires <ArgumentNullException>(fileWriter != null, "fileWriter"); // _pocoToXmlMapper = pocoToXmlMapper; _serializationUtils = serializationUtils; _fileWriter = fileWriter; }
/// <summary> /// Constructs a new writer instance. /// </summary> /// <param name="context">Must not be null. Can be reused from a read operation.</param> public FileChunkWriter(ChunkFileContext context) : base(context) { Check.IfArgumentNull(context, nameof(context)); Check.IfArgumentNull(context.Services, nameof(context.Services)); _streamNavigator = context.Services.GetService <IStreamNavigator>(); _handlerMgr = context.Services.GetService <FileChunkHandlerManager>(); _stringWriter = context.Services.GetService <IStringWriter>(); _numberWriter = context.Services.GetService <INumberWriter>(); context.Services.AddService(GetType(), this); }
internal AsymmetricKeyFilePersister( IKeyToExternalRepresentationMapper <TKey, TKeyXmlPoco> pocoMapper, IXmlSerializationUtils <TKeyXmlPoco> serializationUtils, IStringWriter <TFileWriterOptions> writer) { Contract.Requires <ArgumentNullException>(pocoMapper != null, "pocoMapper"); Contract.Requires <ArgumentNullException>(serializationUtils != null, "serializationUtils"); Contract.Requires <ArgumentNullException>(writer != null, "writer"); // _pocoMapper = pocoMapper; _serializationUtils = serializationUtils; _writer = writer; }
public App(INoticePublisher publisher, IStringWriter writer) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _publisher = publisher; _writer = writer; }
public App(IValidationProvider provider, IStringWriter writer) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _provider = provider; _writer = writer; }
public App(IOperationExecutor executor, IStringWriter writer) { if (executor == null) { throw new ArgumentNullException(nameof(executor)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _executor = executor; _writer = writer; }
public App(DataContext dataContext, IStringWriter writer) { if (dataContext == null) { throw new ArgumentNullException(nameof(dataContext)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _dataContext = dataContext; _writer = writer; }
public App(IMapper mapper, IStringWriter writer) { if (mapper == null) { throw new ArgumentNullException(nameof(mapper)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _mapper = mapper; _writer = writer; }
private static Function Parse(string input, IStringWriter stringWriter) { var functionName = GetFunctionName(input); var parameterCount = GetParameterCount(input); var unknowns = GetUnknowns(input); var functionBody = GetFunctionBody(input); var instructions = GetInstructions(functionBody) .Select(x => Instruction.Parse(x, stringWriter)) .ToArray(); var jumps = GetJumpLabels(functionBody) .Select(x => new Jump(x.label, x.index < instructions.Length ? instructions[x.index] : null)) .ToArray(); return(new Function(functionName, parameterCount, jumps, instructions, unknowns)); }
public App(IStringWriter writer, IFooService fooService, IBarService barService) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (fooService == null) { throw new ArgumentNullException(nameof(fooService)); } if (barService == null) { throw new ArgumentNullException(nameof(barService)); } _writer = writer; _fooService = fooService; _barService = barService; }
public static Instruction Parse(string input, IStringWriter stringWriter) { if (!ParseCheck.IsMatch(input)) { return(null); } var returnParameter = GetReturnParameter(input); var instructionType = GetInstructionType(input); var argumentBody = GetArgumentBody(input); var arguments = string.IsNullOrEmpty(argumentBody) ? Array.Empty <Argument>() : GetArguments(argumentBody) .Select(x => Argument.Parse(instructionType, x, stringWriter)) .ToArray(); return(new Instruction(instructionType, arguments, returnParameter.ParameterValue)); }
public App(IStringWriter writer, IConfiguration <AppSettings> configuration, IConfigurator <AppSettings> configurator) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } _writer = writer; _configuration = configuration; _configurator = configurator; }
public static AsymmetricKeyFilePersister <RsaKey, EnvCryptKey, StringToFileWriterOptions> GetRsaKeyPersister(IStringWriter <StringToFileWriterOptions> writer) { Contract.Ensures(Contract.Result <AsymmetricKeyFilePersister <RsaKey, EnvCryptKey, StringToFileWriterOptions> >() != null); // return(new RsaKeyPersister( new RsaKeyToXmlMapper(new KeyDetailsPersistConverter()), new XmlSerializationUtils <EnvCryptKey>(), writer)); }
public SpecialWorker(IStringWriter stringWriter, INumberWriter numberWriter) { _stringWriter = stringWriter; _numberWriter = numberWriter; }
protected AsymmetricKeyFilePersisterContracts(IKeyToExternalRepresentationMapper <TKey, TKeyXmlPoco> pocoMapper, IXmlSerializationUtils <TKeyXmlPoco> serializationUtils, IStringWriter <TFileWriterOptions> writer) : base(pocoMapper, serializationUtils, writer) { }
public static SymmetricKeyFilePersister <AesKey, EnvCryptKey, StringToFileWriterOptions> GetAesKeyPersister(IStringWriter <StringToFileWriterOptions> writer) { Contract.Requires <ArgumentNullException>(writer != null, "writer"); Contract.Ensures(Contract.Result <SymmetricKeyFilePersister <AesKey, EnvCryptKey, StringToFileWriterOptions> >() != null); // return(new SymmetricKeyFilePersister <AesKey, EnvCryptKey, StringToFileWriterOptions>( new AesKeyToXmlMapper(new KeyDetailsPersistConverter()), new XmlSerializationUtils <EnvCryptKey>(), writer )); }
public DateWriter(IStringWriter writer) { _writer = writer; }
/// <summary> /// Converts provided <see cref="IStringWriter"/> info to <see cref="StringWriter"/>. /// </summary> /// <param name="abstraction">Instance of <see cref="IStringWriter"/> to convert.</param> /// <returns>An instance of <see cref="StringWriter"/>.</returns> public static StringWriter ToImplementation(this IStringWriter abstraction) { return(((IAbstraction <StringWriter>)abstraction)?.UnsafeConvert()); }
private Stream WriteFunctions(IList <Function> functions, IList <Jump> jumps, IList <Instruction> instructions, IStringWriter stringWriter) { var functionStream = new MemoryStream(); var lastInstructionOffset = 0; var lastJumpOffset = 0; var convertedFunctions = new List <Xq32Function>(); foreach (var function in functions) { var currentInstructionOffset = instructions.IndexOf(function.Instructions.FirstOrDefault()); if (currentInstructionOffset >= 0) { lastInstructionOffset = currentInstructionOffset; } var currentJumpOffset = jumps.IndexOf(function.Jumps.OrderBy(x => stringWriter.GetHash(x.Label)).FirstOrDefault()); if (currentJumpOffset >= 0) { lastJumpOffset = currentJumpOffset; } convertedFunctions.Add(new Xq32Function { instructionOffset = (short)lastInstructionOffset, instructionEndOffset = (short)(lastInstructionOffset + function.Instructions.Count), nameOffset = (int)stringWriter.Write(function.Name), crc32 = stringWriter.GetHash(function.Name), jumpOffset = (short)lastJumpOffset, jumpCount = (short)function.Jumps.Count, parameterCount = (short)function.ParameterCount, unk1 = (short)function.Unknowns[0], unk2 = (short)function.Unknowns[1] }); lastInstructionOffset += function.Instructions.Count; lastJumpOffset += function.Jumps.Count; } using var bw = new BinaryWriterX(functionStream, true); bw.WriteMultiple(convertedFunctions.OrderBy(x => x.crc32)); functionStream.Position = 0; return(functionStream); }
public GenericController(IReportConverter <HtmlReportCell> htmlConverter, IStringWriter stringWriter) { this.htmlConverter = htmlConverter; this.stringWriter = stringWriter; }
private Stream WriteJumps(IList <Jump> jumps, IList <Function> functions, IList <Instruction> instructions, IStringWriter stringWriter) { var jumpStream = new MemoryStream(); using var bw = new BinaryWriterX(jumpStream, true); foreach (var jump in jumps) { var relatedFunction = functions.First(x => x.Jumps.Contains(jump)); var lastInstruction = relatedFunction.Instructions.Last(); var instructionIndex = instructions.IndexOf(jump.Instruction); bw.WriteType(new Xq32Jump { instructionIndex = instructionIndex == -1 ? instructions.IndexOf(lastInstruction) + 1 : instructionIndex, nameOffset = (int)stringWriter.Write(jump.Label), crc32 = stringWriter.GetHash(jump.Label) }); } jumpStream.Position = 0; return(jumpStream); }