private static async Task WriteAsync(AdminProject project, Stream stream, CancellationToken cancellationToken) { var stringWriter = new StringWriter(); await stringWriter.WriteLineAsync(string.Format("{0},{1},{2},{3},{4},{5},{6}", project.Id.ToCsvValue(), project.Name.ToCsvValue(), project.Created.ToCsvValue(), project.UserId.ToCsvValue(), project.UserName.ToCsvValue(), project.ProductType.ToCsvValue(), project.Product.ToCsvValue())); byte[] bytes = Encoding.UTF8.GetBytes(stringWriter.ToString()); await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken); await stream.FlushAsync(cancellationToken); }
public static void TestWriteLineAsyncCharArray() { StringWriter sw = new StringWriter(); sw.WriteLineAsync(new char[] { 'H', 'e', 'l', 'l', 'o' }); Assert.Equal("Hello" + Environment.NewLine, sw.ToString()); }
public static async Task MiscWriteLineAsync() { var sw = new StringWriter(); await sw.WriteLineAsync('H'); await sw.WriteLineAsync(new char[] { 'e', 'l', 'l', 'o' }); await sw.WriteLineAsync("World!"); Assert.Equal( string.Format("H{0}ello{0}World!{0}", Environment.NewLine), sw.ToString()); }
private static async Task WriteAsync(AdminClient client, Stream stream, CancellationToken cancellationToken) { var stringWriter = new StringWriter(); await stringWriter.WriteLineAsync(string.Format("{0},{1},{2},{3},{4},{5}", client.Id.ToCsvValue(), client.Email.ToCsvValue(), client.Name.ToCsvValue(), client.Created.ToCsvValue(), (client.Balance/100).ToCsvValue(), client.State.ToCsvValue())); byte[] bytes = Encoding.UTF8.GetBytes(stringWriter.ToString()); await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken); await stream.FlushAsync(cancellationToken); }
protected override async Task PublishFileToDestinationAsync(FileInfo sourceFile, DirectoryInfo destinationRoot, DocFile page) { this.LogMessage(new ValidationMessage(sourceFile.Name, "Publishing file to HTML")); var destinationPath = this.GetPublishedFilePath(sourceFile, destinationRoot, HtmlOutputExtension); StringWriter writer = new StringWriter(); StreamReader reader = new StreamReader(sourceFile.OpenRead()); long lineNumber = 0; string nextLine; while ((nextLine = await reader.ReadLineAsync()) != null) { lineNumber++; if (this.IsDoubleBlockQuote(nextLine)) { this.LogMessage(new ValidationMessage(string.Concat(sourceFile.Name, ":", lineNumber), "Removing DoubleBlockQuote")); continue; } await writer.WriteLineAsync(nextLine); } var converter = this.GetMarkdownConverter(); var html = converter.Transform(writer.ToString()); var pageData = page.Annotation ?? new PageAnnotation(); if (string.IsNullOrEmpty(pageData.Title)) { pageData.Title = (from b in converter.Blocks where b.BlockType == BlockType.h1 select b.Content).FirstOrDefault(); } page.Annotation = pageData; await this.WriteHtmlDocumentAsync(html, page, destinationPath, destinationRoot.FullName); }
private static async Task WriteAsync(AdminUser user, Stream stream, CancellationToken cancellationToken) { var stringWriter = new StringWriter(); // Memberships var membershipsBuilder = new StringBuilder(); var memberships = user.Memberships; if (!string.IsNullOrEmpty(user.Email)) { memberships.Insert(0, new DomainUserMembershipForAdmin { Identity = user.Email, Provider = ProviderType.Email.ToString() }); } foreach (DomainUserMembershipForAdmin membership in memberships) { membershipsBuilder.AppendFormat("{0}: {1};", membership.Provider, membership.Identity); } // Storage space var usedStorageSpaceMegabytes = (int)Math.Round((double)user.UsedStorageSpace/1024/1024); var maximumStorageSpaceMegabytes = (int)Math.Round((double)user.MaximumStorageSpace/1024/1024); await stringWriter.WriteLineAsync(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", user.AppName.ToCsvValue(), user.Id.ToCsvValue(), user.UserName.ToCsvValue(), user.Created.ToCsvValue(), membershipsBuilder.ToCsvValue(), usedStorageSpaceMegabytes.ToCsvValue(), maximumStorageSpaceMegabytes.ToCsvValue(), user.VideosCount.ToCsvValue(), user.ProductName.ToCsvValue())); byte[] bytes = Encoding.UTF8.GetBytes(stringWriter.ToString()); await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken); await stream.FlushAsync(cancellationToken); }