public static async Task SaveAsync(this IFileWriter writer, string fileName, IContentContainer container) { using (var stream = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { await writer.WriteAsync(stream, container); } }
public async Task Run() { var grid = await generator.GenerateGridAsync(); var gridAsJson = serialiser.Serialise(grid); await writer.WriteAsync(gridAsJson); }
public Task LogAsync(LogLevel level, string logMessage) { string path = _filePathProvider.GetFilePath(); var logInfo = GetLogInfo(level); string message = GetMessage(logInfo.Item1, logMessage, _dateTimeProvider.UtcNow); return(_fileWriter.WriteAsync(path, message)); }
public async Task Async_WriteFile_Should_Write_The_ExpectedMessage_To_Expected_Path() { const string path = "Path"; const string message = "Message"; await _fileWriter.WriteAsync(path, message).ConfigureAwait(false); await _fileWriterWrapperMock.Received().WriteAsync(Arg.Is(path), Arg.Is(message)).ConfigureAwait(false); }
public static async Task <long> WriteAsync([NotNull] this IFileWriter writer, [NotNull] string sqlStatement, int timeout, Action <string> reportProgress, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(sqlStatement)) { return(0); } if (FunctionalDI.SQLDataReader == null) { throw new ArgumentException("No SQL Reader set"); } using (var sqlReader = await FunctionalDI .SQLDataReader(sqlStatement, (sender, s) => reportProgress?.Invoke(s.Text), timeout, cancellationToken) .ConfigureAwait(false)) { await sqlReader.OpenAsync(cancellationToken).ConfigureAwait(false); return(await writer.WriteAsync(sqlReader, cancellationToken).ConfigureAwait(false)); } }
public MetaList GenerateMetadataFor(Type type, int version = 1, IEnumerable <MetaList> data = null) { int newVersion = version; if (data == null) { data = new List <MetaList>(); } var meta = new MetaList() { Version = newVersion, Created = DateTimeOffset.Now }; var properties = type.GetProperties().ToArray(); for (int i = 0; i < properties.Length; i++) { meta.Metas.Add(new Metadata() { FieldName = properties[i].Name, Type = properties[i].PropertyType.Name, Order = i }); } var dataList = data.ToList(); dataList.Add(meta); string filepath = IOHelper.CreateFileIfNotExists($"{type.Namespace}_meta", false); _writer.WriteAsync(filepath, new List <string>() { JsonConvert.SerializeObject(dataList) }); return(meta); }