public void ClearDatabase(string filePath) { var appendToFile = false; var value = ""; _fileWriter.Write(filePath, appendToFile, value); }
public void Write(byte[] buffer, int bufferOffset, int bufferSize) { semaphore.Wait(); try { decoratee.Write(buffer, bufferOffset, bufferSize); } finally { semaphore.Release(); } }
public void Log(ErrorDetails errorDetails) { if (_errorFilter.SkipError(errorDetails.Exception)) { return; } var formattedException = _exceptionSerializer.Serialize(errorDetails.Exception); var rawRequest = errorDetails.HttpRequest.AsRawString(); var content = new StringBuilder(); content.AppendLine(DateTime.UtcNow.ToString("dddd, dd MMMM yyyy HH:mm:ss")); content.AppendLine(""); content.AppendLine("Exception:"); content.AppendLine("--------------"); content.AppendLine(formattedException); content.AppendLine(""); content.AppendLine("HTTP Request:"); content.AppendLine("--------------"); content.AppendLine(rawRequest); var logFilePath = _logFilePathGenerator.CreateNewLogFilePath(); _fileWriter.Write(logFilePath, content.ToString()); }
public void Execute() { while (generator.TryDequeue(out var info)) { if (info.source.size > readBuffer.Length) { readBuffer = new byte[info.source.size]; } if (info.target.size > decompressBuffer.Length) { decompressBuffer = new byte[info.target.size]; } reader.Read(readBuffer, 0, info.source.size, info.source.offset); var decompressedSize = decompressor.Decompress(readBuffer, 0, info.source.size, decompressBuffer); if (decompressedSize != info.target.size) { throw new Exception(); } writer.Write(decompressBuffer, 0, info.target.size, info.target.offset); } }
private static void ExtractFiles(FileList fileList, IFileWriter writer) { Console.WriteLine($"Extracting {fileList.Name}"); writer.CreateDirectory(fileList.Name); foreach (FileData file in fileList.GetFiles()) { if (file.Compressed) { using (var compressed = new MemoryStream(file.Contents)) { using (var decompressed = new MemoryStream()) { LZSS.Decompress(compressed, decompressed); file.Contents = decompressed.ToArray(); } } } if (file.IsArchive()) { ExtractFiles(new ArchiveFileList(Path.Combine(fileList.Name, file.Name), file.Contents), writer); } else { writer.Write(Path.Combine(fileList.Name, $"{file.Name}.{file.GetExtension()}"), file.Contents); } } }
private void MainLoop() { while (!_exit) { LogLine logLine = null; try { logLine = _lines.Take(); } catch (Exception) { _exit = true; } if (logLine != null && (!_exit || _quitWithFlush)) { _writer.Write(logLine); } if (_quitWithFlush && _lines.Count == 0) { _exit = true; } } _lines?.Dispose(); _writer?.Dispose(); }
public override void SaveTo(IEnumerable <Chunk> chunks, IFileWriter fileWriter) { if (fileWriter == null) { throw new ArgumentNullException(nameof(fileWriter)); } long lengthTotal = 0; using (fileWriter) { foreach (var item in chunks) { if (item != null) { var buffer = item.Buffer; var totalSize = BitConverter.GetBytes(buffer.Length); var size = BitConverter.GetBytes(item.Length); buffer = ConcatArrays(totalSize, buffer, size); fileWriter.Write(buffer, buffer.Length); lengthTotal += item.Length; } } WriteTotalLength(fileWriter, lengthTotal); } }
public void Reverse(string inputFile, string outputFile) { var content = _fileReader.Read(inputFile); var reversedContent = new string(content.Reverse().ToArray()); _fileWriter.Write(outputFile, reversedContent); }
public void Log(LogLevel level, string logMessage) { string path = _filePathProvider.GetFilePath(); var logInfo = GetLogInfo(level); string message = GetMessage(logInfo.Item1, logMessage, _dateTimeProvider.UtcNow); _fileWriter.Write(path, message); }
/// <summary> /// Generates a report filled with the content supplied by <paramref name="report"/>. /// </summary> /// <param name="report">Specifies the report model.</param> public void Generate(IReport report) { var contentBuilder = CreateContent(report); _fileWriter.Write( string.Concat(report.ReflectedAssembly, ".txt"), writer => writer.Write(contentBuilder.ToString())); }
public void WriteFile_Should_Write_The_ExpectedMessage_To_Expected_Path() { const string path = "Path"; const string message = "Message"; _fileWriter.Write(path, message); _fileWriterWrapperMock.Received().Write(Arg.Is(path), Arg.Is(message)); }
/// <summary> /// Writes a DataTable to a CSV file specified by the path /// </summary> /// <param name="dataTable">The datatable to write</param> /// <param name="filePath">The location of the CSV to create</param> /// <param name="settings">Optional csv settings</param> public static void ToCsv(this DataTable dataTable, string filePath, ToCsvSettings settings = null) { settings = settings ?? new ToCsvSettings(); using (IFileWriter fileWriter = FileWriterFactory.GetFileWriter(filePath, settings.Compression)) { fileWriter.Write(dataTable.ToCsv(settings)); } }
public void GenerateReport(string source, string rootModule, string destination) { _netlistDataBuilder.Build(source); var result = _countLibraryGatesQuery.CountLibraryGates(source, rootModule); var content = _countLibraryGatesFileContentDirector.Construct(result); _fileWriter.Write(destination, "Count Library Gates", content); }
public void Save(object data) { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream()){ formatter.Serialize(stream, data); byte[] bytes = stream.ToArray(); fileWriter.Write(bytes, savePath); } }
public void Generate(RawFileSchema rawFileSchema, DataSource dataSource) { var validationErrors = _schemaValidator.ValidateSchema(rawFileSchema); if (validationErrors.Any()) { throw new Exception("Errors"); } var fileFormat = rawFileSchema.FileFormat.ToEnum <FileSchemaType>(); var rootDirectory = Path.Combine(_rootFolder, rawFileSchema.RootOutputDir); if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } var generatedFilePath = Path.Combine(rootDirectory, rawFileSchema.OutputFileName); if (!string.IsNullOrWhiteSpace(rawFileSchema.OutputFileExtension)) { generatedFilePath += rawFileSchema.OutputFileExtension; } switch (fileFormat) { case FileSchemaType.Fixed: var fixedLengthFileSchemaBuilder = new FixedLengthSchemaBuilder(); var fixedFileSchema = fixedLengthFileSchemaBuilder.BuildSchema(rawFileSchema); _fileWriter.Write(generatedFilePath, dataSource, fixedFileSchema); break; case FileSchemaType.Separated: var separatedFileSchemaBuilder = new SeparatedSchemaBuilder(); var separatedFileSchema = separatedFileSchemaBuilder.BuildSchema(rawFileSchema); _fileWriter.Write(generatedFilePath, dataSource, separatedFileSchema); break; default: throw new ArgumentOutOfRangeException(); } }
public void GenerateReport(string source, string rootModule, IList <string> moduleNames, string destination) { _netlistDataBuilder.Build(source); var result = _physicalPathQuery.GetPhysicalPaths(source, rootModule, moduleNames); var content = _listPhysicalPathsFileContentDirector.Construct(moduleNames, result); _fileWriter.Write(destination, "List Phyisical Paths", content); }
public async Task MakeFiles(string fileKeyPath, string fileSavePath, int findNum, Encoding encoding) => await Task.Run(async() => { var tmp1 = await _fileReader.Read(fileKeyPath, encoding); foreach (var name in tmp1) { var tmp2 = _googleQuery.PageParser(GetQuery(name, findNum)); await _fileWriter.Write(fileSavePath, name, findNum, encoding, tmp2); } });
public void PortsToUpper(UpperCasePortsRequest request) { _netlistDataBuilder.Build(request.SourceNetlist); _netlistCloner.Clone(request.SourceNetlist, request.TargetNetlist); _libraryGatesPortsReplacer.PortsToUpper(request.TargetNetlist); var content = _netlistFileContentDirector.Construct(request.TargetNetlist); _fileWriter.Write(request.TargetNetlist, "Uppercase Library Gates Ports", content); }
public IEnumerable <string> PerformSort(IEnumerable <Record> records) { IEnumerable <string> listOfAddresses = records.Select(p => p.Address); //Sort Addresses by Street Name IOrderedEnumerable <string> sortedAddresses = listOfAddresses.OrderBy(s => s.Split(' ')[1]); _writer.Write(sortedAddresses, address => $"{address}", @"Result_2.txt"); return(sortedAddresses); }
private void serialPort_DataRecieved(object sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs) { var buffer = serialPort.ReadExisting(); foreach (char c in buffer) { fileWriter.Write(c.ToString().Trim()); BytesCounter++; } // fileWriter.WriteLine(Convert.ToChar(serialPort.ReadByte()).ToString()); }
public void Save(User user) { _synchronizer.Lock(() => { var allUsers = GetAll().ToList(); allUsers.Add(user); string serialized = _serializer.Serialize(allUsers); _writer.Write(_file, serialized); }); }
public void Remove(RemoveBufferRequest removeBufferRequest) { _netlistDataBuilder.Build(removeBufferRequest.SourceNetlist); _netlistCloner.Clone(removeBufferRequest.SourceNetlist, removeBufferRequest.TargetNetlist); _bufferRemover.Remove(removeBufferRequest.TargetNetlist, removeBufferRequest.BufferName, removeBufferRequest.InputPort, removeBufferRequest.OutputPort); var content = _netlistFileContentDirector.Construct(removeBufferRequest.TargetNetlist); _fileWriter.Write(removeBufferRequest.TargetNetlist, "Remove Buffers", content); }
public void Replace(LibraryGateReplaceRequest replaceRequest) { _netlistDataBuilder.Build(replaceRequest.SourceNetlist); _netlistCloner.Clone(replaceRequest.SourceNetlist, replaceRequest.TargetNetlist); _libraryGateReplacer.Replace(replaceRequest.TargetNetlist, replaceRequest.GateToReplace, replaceRequest.NewGate, replaceRequest.PortsMapping); var content = _netlistFileContentDirector.Construct(replaceRequest.TargetNetlist); _fileWriter.Write(replaceRequest.TargetNetlist, "Replace Library Gate", content); }
public void SaveReportFile(ReportBundle reportBundle, [NotNull] ReportFile reportFile, long userId) { if (reportFile == null) { throw new ArgumentNullException(nameof(reportFile)); } var reportFolderPath = _reportFolderPathProvider.GetReportFolderPath(reportBundle, userId); _fileWriter.Write(reportFolderPath, reportFile.FileName, reportFile.Content); }
async void DownloadImage(Uri uri) { var fileName = uri.Segments.Last(); if (!downloadedImages.TryAdd(fileName, null)) { return; } var imgBytes = await httpClient.GetByteArray(uri); fileWriter.Write(fileName, imgBytes); }
protected internal override void DoLog(LogCatagory catagory, string message) { if (catagory != LogCatagory.Debug) // TODO: Take this from configuration, rather than hard code. { _fileWriter.Write(_filePath, message); } if (_logger != null) { _logger.DoLog(catagory, message); } }
/// <summary> /// Lets outgoing requests pass through, to log requests and responses /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var response = await base.SendAsync(request, cancellationToken); // we do all the work AFTER the request is sent, so we have the response and if an exception is throw we don't need to run any logic var summary = await Summarize(request, response); FileWriter.Write(summary); return(response); }
public void Generate(IEnumerable <MetricResult> results) { addHtmlHeader(); foreach (var result in results) { convertResultToHtml(result); } addHtmlTail(); _fileWriter.Write(_filePath, Contents); }
private void WriteToAll(string message, LogLevel logLevel) { var logRecord = new LogRecord() { CreatedAt = DateTime.Now, LogLevel = logLevel, Message = message, NotSerializableField = "NotSerializableField" + DateTime.Now.ToString() }; FileRepository.Write(logRecord); DbRepository.Write(logRecord); ConsoleWriter.Write(logRecord); }
public void Generate(IEnumerable <MetricResult> results) { var root = _doc.Root; Debug.Assert(root != null); foreach (var metricResult in results) { var metricElement = ConvertResult(metricResult); root.Add(metricElement); } var contents = ToString(); _fileWriter.Write(_filePath, contents); }