本文整理汇总了C#中System.IO.TextWriter.WriteLineAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TextWriter.WriteLineAsync方法的具体用法?C# TextWriter.WriteLineAsync怎么用?C# TextWriter.WriteLineAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextWriter
的用法示例。
在下文中一共展示了TextWriter.WriteLineAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplicateBlobAsync
internal static async Task ReplicateBlobAsync(PhotoModel model, TextWriter log)
{
//The source connection string needs to be in AppSettings using the
//storage account name.
var sourceConnectionString = ConfigurationManager.AppSettings[model.StorageAccountName];
//The target connection string is the local region's storage account
var targetConnectionString = SettingsHelper.LocalStorageConnectionString;
//Copy from the upload container to the photos container,
// potentially across storage accounts
await log.WriteLineAsync("sourceConnectionString: " + sourceConnectionString);
await log.WriteLineAsync("targetConnectionString: " + targetConnectionString);
var storageRepo = new StorageRepository(sourceConnectionString);
var container = await storageRepo.ReplicateBlobAsync(
targetConnectionString,
StorageConfig.UserUploadBlobContainerName,
StorageConfig.PhotosBlobContainerName,
model.ServerFileName, log);
//Monitor the copy operation and wait for it to finish
//before proceeding
await storageRepo.MonitorCopy(container, model.ServerFileName, log);
}
示例2: ProcessQueueMessage
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static async Task ProcessQueueMessage(
[QueueTrigger("uploadqueue")] string message,
TextWriter log)
{
log.WriteLineAsync(message).Wait();
var m = message.Split(',');
await log.WriteAsync("Message received: " + m);
var model = new PhotoModel
{
ID = m[0],
ServerFileName = m[1],
StorageAccountName = m[2],
Owner = m[3],
OwnerName = m[4],
BlobURL = m[5],
OriginRegion = m[6]
};
//Copy blob from source to destination
await log.WriteAsync("Replicating blob...");
await Helpers.ReplicateBlobAsync(model, log);
try
{
//Change the blob URL to point to the new location!
await log.WriteAsync("Getting blob URIs");
string storageConnectionString = SettingsHelper.LocalStorageConnectionString;
var repo = new StorageRepository(storageConnectionString);
model.BlobURL = repo.GetBlobURI(model.ServerFileName, StorageConfig.PhotosBlobContainerName).ToString();
model.ThumbnailURL = repo.GetBlobURI(model.ServerFileName, StorageConfig.ThumbnailsBlobContainerName).ToString();
//Create thumbnail
await log.WriteAsync("Creating thumbnail");
await Helpers.CreateThumbnailAsync(repo, model.ServerFileName, log);
//Store in table storage
await log.WriteAsync("Saving to table storage");
await Helpers.SaveToTableStorageAsync(model, log);
//Add to Redis cache
await log.WriteAsync("Saving to Redis");
await Helpers.SaveToRedisAsync(model, log);
}
catch (Exception oops)
{
await log.WriteLineAsync(oops.Message);
}
}
示例3: ProcessQueueMessageAsync
/// <summary>
/// This method is triggered when a message arrives on the 'listener' queue on the
/// the 'WebHookListener' Azure Storage Account.
/// </summary>
public static async Task ProcessQueueMessageAsync([QueueTrigger("listener")] string message, TextWriter logger)
{
await logger.WriteLineAsync(message);
// Send message to all subscribers as WebHooks. Use a predicate to filter
// which receivers should get a WebHook request.
await Program.Manager.NotifyAllAsync("event1", new { Message = message });
}
示例4: SaveToTableStorageAsync
internal static async Task SaveToTableStorageAsync(PhotoModel p, TextWriter log)
{
var storageConnectionString = SettingsHelper.LocalStorageConnectionString;
var repo = new StorageRepository(storageConnectionString);
var result = await repo.SaveToTableStorageAsync(DAL.Azure.StorageConfig.TableName, p);
await log.WriteLineAsync("Save to table HTTP result: " + result);
}
示例5: ComposeLabBlock
static async Task ComposeLabBlock(TextWriter writer, Func<int> lineNumberGetter, Action<int> lineNumberSetter, Lab lab)
{
var lineNumber = lineNumberGetter();
//Lijn 1: “Medidoc” identificatienummer van het laboratorium.
//formaat: 4 karakters en wordt als volgt gevormd: de eerste letter van de provincie (W,O,A,B,L) gevolgd door de eerste twee cijfers van de postkode, gevolgd door een volgnummer binnen de stad of gemeente. (vb. W841 voor een labo te Oostende)
lineNumber++;
await writer.WriteLineAsync(lab.Id);
//Lijn 2 6: Identificatiegegevens van het labo (naam, adres, tel ...)
//formaat: vrije tekst met maximaal 50 karakters per lijn .
lineNumber++;
await writer.WriteLineAsync(lab.Name?.TrimToMaxSize(50));
lineNumber++;
await writer.WriteLineAsync(lab.Address1?.TrimToMaxSize(50));
lineNumber++;
await writer.WriteLineAsync(lab.Address2?.TrimToMaxSize(50));
lineNumber++;
await writer.WriteLineAsync(lab.IdentificationData1?.TrimToMaxSize(50));
lineNumber++;
await writer.WriteLineAsync(lab.IdentificationData2?.TrimToMaxSize(50));
//Lijn 7: datum (+ eventueel tijdstip) aanmaak
//formaat: JJJJMMDD(+evtHHMM)
lineNumber++;
await writer.WriteLineAsync(lab.Date?.IsMidnight() ?? false ?
lab.Date?.ToString("yyyyMMdd") :
lab.Date?.ToString("yyyyMMddHHmm"));
//Lijn 8: RIZIV nummer aanvragende arts
//formaat: C/CCCCC/CC/CCC
lineNumber++;
await writer.WriteLineAsync(Regex.Replace(lab.RequestingDoctor?.RizivNr ?? string.Empty, @"(\w{1})(\w{5})(\w{2})(\w{3})", @"$1/$2/$3/$4"));
//lijn 9: Naam (positie 1-24) + Voornaam (positie 25-40) aanvragende arts
lineNumber++;
await writer.WriteLineAsync(string.Concat(lab.RequestingDoctor?.LastName?.TrimToMaxSize(24).PadRight(24) ?? string.Empty, lab.RequestingDoctor?.FirstName).TrimToMaxSize(40));
foreach (var patient in lab.Patients)
await ComposePatientBlock(writer, () => lineNumber, (ln) => lineNumber = ln, patient, true);
lineNumber++;
await writer.WriteLineAsync($"#/{lineNumber}");
lineNumberSetter(lineNumber);
}
示例6: WithReaderAndWriter
async Task WithReaderAndWriter(TextWriter writer, StreamReader reader)
{
string line;
while ((line = await reader.ReadLineAsync()) != null)
{
await writer.WriteLineAsync(line);
}
}
示例7: DisplayUsers
public void DisplayUsers(TextWriter writer)
{
foreach (var user in _users.All())
{
var userData = string.Format("{0}\t{1} {2}",
user.Id,
user.FirstName,
user.LastName);
writer.WriteLineAsync(userData);
}
}
示例8: GenerateCode
protected sealed override void GenerateCode(string inputFilePath, string inputFileContent, TextWriter writer)
{
Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async () =>
{
IComponentModel componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
VisualStudioWorkspace workspace = componentModel.GetService<VisualStudioWorkspace>();
if (workspace == null)
throw new InvalidOperationException($"Unable to get the service {nameof(VisualStudioWorkspace)} from the host application.");
Solution solution = workspace.CurrentSolution;
if (solution == null)
throw new InvalidOperationException($"No solution found in the current workspace.");
ImmutableArray<DocumentId> matchingDocuments = solution.GetDocumentIdsWithFilePath(inputFilePath);
DocumentId documentId = null;
// It's a shame we have to resort to using the EnvDTE API here, but it seems to be the only way to retrieve the
// actual project of the item that we are saving. (It is possible to have the same source file in several projects)
// Also, at the time of writing, it does not seem to be possible to retrieve the target framework version from the Roslyn API.
EnvDTE.ProjectItem dteProjectItem = GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem;
if (dteProjectItem == null)
throw new Exception($"Unable to uniquely determine which project item matches the input file \"{inputFilePath}\". Multiple matches was found and the ProjectItem was not available from EnvDTE.");
EnvDTE.Project dteProject = dteProjectItem.ContainingProject;
Project roslynProject = solution.Projects.FirstOrDefault(p => p.FilePath == dteProject.FullName);
if (roslynProject == null)
throw new Exception($"Unable to determine which project item matches the input file \"{inputFilePath}\". The project with the path \"{dteProject.FullName}\" could not be located.");
string targetFrameworkMoniker = dteProject.Properties?.Item("TargetFrameworkMoniker")?.Value as string;
if (targetFrameworkMoniker != null)
{
TargetFrameworkName = new FrameworkName(targetFrameworkMoniker);
}
else
{
TargetFrameworkName = null;
}
documentId = roslynProject.Documents.FirstOrDefault(doc => doc.FilePath == dteProjectItem.FileNames[0])?.Id;
if (documentId == null)
throw new CodeGeneratorException(String.Format("Unable to find a document matching the file path \"{0}\".", inputFilePath));
Document document = solution.GetDocument(documentId);
document = await GenerateCodeAsync(document);
await writer.WriteLineAsync((await document.GetTextAsync()).ToString());
});
}
示例9: Execute
public async Task Execute(TextWriter writer)
{
var routeContext = new RouteContext(_httpContext)
{
RouteData = new RouteData(_routeData)
};
// Save current context
var currentOutputStream = _httpContext.Response.Body;
var currentRouteData = routeContext.RouteData;
using (var outputStream = new MemoryStream())
{
// Setup context
_httpContext.Response.Body = outputStream;
routeContext.RouteData.Values["controller"] = _controller;
routeContext.RouteData.Values["action"] = _action;
var handler = new MvcRouteHandler();
try
{
// Invoke controller
await handler.RouteAsync(routeContext);
outputStream.Position = 0;
using (var reader = new StreamReader(outputStream))
{
var output = await reader.ReadToEndAsync();
await writer.WriteLineAsync(output);
}
routeContext.IsHandled = true;
}
finally
{
// Restore context
routeContext.RouteData = currentRouteData;
_httpContext.Response.Body = currentOutputStream;
}
}
}
示例10: Run
public static async Task Run(IMediator mediator, TextWriter writer)
{
await writer.WriteLineAsync("Sample mediator implementation using send, publish and post-request handlers in sync and async version.");
await writer.WriteLineAsync("---------------");
await writer.WriteLineAsync("Sending Ping...");
var pong = await mediator.Send(new Ping { Message = "Ping" });
await writer.WriteLineAsync("Received: " + pong.Message);
await writer.WriteLineAsync("Sending Ping async...");
var response = await mediator.Send(new PingAsync { Message = "Ping" });
await writer.WriteLineAsync("Received async: " + response.Message);
await writer.WriteLineAsync("Publishing Pinged...");
await mediator.Publish(new Pinged());
await writer.WriteLineAsync("Publishing Pinged async...");
await mediator.Publish(new PingedAsync());
}
示例11: RunCommandAsync
public async Task<CommandReturnCodes> RunCommandAsync(TextReader input, TextWriter output, string tenant, string[] args, IDictionary<string, string> switches)
{
try
{
tenant = tenant ?? ShellHelper.DefaultShellName;
using (var env = CreateStandaloneEnvironment(tenant))
{
var commandManager = env.ServiceProvider.GetService<ICommandManager>();
var parameters = new CommandParameters
{
Arguments = args,
Switches = switches,
Input = input,
Output = output
};
await commandManager.ExecuteAsync(parameters);
}
return CommandReturnCodes.Ok;
}
catch (OrchardCommandHostRetryException ex)
{
// Special "Retry" return code for our host
await output.WriteLineAsync(T($"{ex.Message} (Retrying...)"));
return CommandReturnCodes.Retry;
}
catch (Exception ex)
{
if (ex.IsFatal())
{
throw;
}
if (ex is TargetInvocationException &&
ex.InnerException != null)
{
// If this is an exception coming from reflection and there is an innerexception which is the actual one, redirect
ex = ex.InnerException;
}
await OutputExceptionAsync(output, T("Error executing command \"{0}\"", string.Join(" ", args)), ex);
return CommandReturnCodes.Fail;
}
}
示例12: ProcessEmailQueueMessage
public static async Task ProcessEmailQueueMessage([QueueTrigger("email-pending-deliveries")] string message, TextWriter log)
{
var emailMessage = JsonConvert.DeserializeObject<QueuedEmailMessage>(message);
// Create the email object first, then add the properties.
var from = GuardAgainstInvalidEmailAddress(EnvironmentHelper.TryGetEnvironmentVariable("Authentication:SendGrid:FromEmail"));
var email = new SendGridMessage();
email.AddTo(emailMessage.Recipient);
email.From = new MailAddress(from, "AllReady");
email.Subject = emailMessage.Subject;
email.Html = emailMessage.HtmlMessage;
email.Text = emailMessage.Message;
// Create credentials, specifying your user name and password.
var username = EnvironmentHelper.TryGetEnvironmentVariable("Authentication:SendGrid:UserName");
var password = EnvironmentHelper.TryGetEnvironmentVariable("Authentication:SendGrid:Password");
var credentials = new NetworkCredential(username, password);
// Create an Web transport for sending email, using credentials...
var transportWeb = new Web(credentials);
await transportWeb.DeliverAsync(email);
await log.WriteLineAsync($"Sent email with subject `{email.Subject}` to `{emailMessage.Recipient}`");
}
示例13: WriteToAsync
private static async Task WriteToAsync(TextWriter writer, IReadOnlyList<StopWords> stopWords)
{
await WriteToAsync(writer, Prefixes.StopWords, stopWords);
await writer.WriteLineAsync();
}
示例14: ComposePatientBlock
static async Task ComposePatientBlock(TextWriter writer, Func<int> lineNumberGetter, Action<int> lineNumberSetter, Patient patient, bool lab)
{
var lineNumber = lineNumberGetter();
//Lijn 1: aanduiding begin van een aanvraag formaat: #A (eventueel gevolgd het rijksregisternummer van de patient of bij gebrek hieraan het Medidoc dossiernummer van de patiënt zie appendix A voor de vorming van het Medidoc dossiernummer)
lineNumber++;
await writer.WriteLineAsync(string.Concat("#A", patient.Id));
//Lijn 2: naam en voornaam van de patiënt
lineNumber++;
await writer.WriteLineAsync(string.Concat(patient.LastName?.TrimToMaxSize(24).PadRight(24) ?? string.Empty, patient.FirstName).TrimToMaxSize(40));
//Lijn 3: geboortedatum patiënt
//formaat: JJJJMMDD
lineNumber++;
await writer.WriteLineAsync(patient.BirthDate?.ToString("yyyyMMdd"));
//Lijn 4: geslacht patiënt
//formaat: X, of Y, of Z
lineNumber++;
switch (patient.Sex)
{
case Sex.male:
await writer.WriteLineAsync("Y");
break;
case Sex.female:
await writer.WriteLineAsync("X");
break;
default:
await writer.WriteLineAsync("Z");
break;
}
//Lijn 5: datum van de aanvraag
//formaat: JJJJMMDD
lineNumber++;
await writer.WriteLineAsync(patient.RequestDate?.ToString("yyyyMMdd"));
//(Lijn 6: referentienummer aanvraag
//formaat: max 14 karakters.
lineNumber++;
await writer.WriteLineAsync(patient.ReferenceNumber?.TrimToMaxSize(14));
if (lab)
{
//Lijn 7: protocol code
//formaat: 1 karakter, zijnde: P indien partieel protocol; C indien volledig protocol; S indien aanvulling van een partieel; L indien het de laatste aanvulling is
lineNumber++;
switch (patient.ProtocolCode)
{
case ProtocolCode.Partial:
await writer.WriteLineAsync("P");
break;
case ProtocolCode.Full:
await writer.WriteLineAsync("C");
break;
case ProtocolCode.Adition:
await writer.WriteLineAsync("S");
break;
case ProtocolCode.LastAdition:
await writer.WriteLineAsync("L");
break;
default:
await writer.WriteLineAsync();
break;
}
}
else
{
//(lijn 7:)Episodenummer (positie 1-14); legt verband tussen meerdere onderzoeken
//mag blanco gelaten worden
lineNumber++;
await writer.WriteLineAsync(patient.EpisodeNumber?.TrimToMaxSize(14));
}
//(lijn 1-7 zijn obligaat, de volgende lijnen mogen weggelaten worden)
//(lijn 8:)Straat (positie 1-24) + nr (positie 25-31)
if (!string.IsNullOrEmpty(patient.Address?.Street))
{
lineNumber++;
await writer.WriteLineAsync(string.Concat(patient.Address?.Street?.TrimToMaxSize(24).PadRight(24) ?? string.Empty, patient.Address?.HouseNr).TrimToMaxSize(31));
}
//(lijn 9:)Postcode (positie 1-7)
if (!string.IsNullOrEmpty(patient.Address?.PostalCode))
{
lineNumber++;
await writer.WriteLineAsync(patient.Address?.PostalCode?.TrimToMaxSize(7));
}
//(lijn 10:)Gemeente (positie 1-24)
if (!string.IsNullOrEmpty(patient.Address?.Town))
{
lineNumber++;
await writer.WriteLineAsync(patient.Address?.Town?.TrimToMaxSize(24));
}
foreach (var result in patient.Results)
await ComposeResultBlock(writer, () => lineNumber, (ln) => lineNumber = ln, result);
//.........这里部分代码省略.........
示例15: ComposeTextReportDoctorBlock
static async Task ComposeTextReportDoctorBlock(TextWriter writer, Func<int> lineNumberGetter, Action<int> lineNumberSetter, ExecutingDoctor executingDoctor)
{
var lineNumber = lineNumberGetter();
//(lijn 1:)RIZIV-nummer uitvoerend arts of paramedicus (positie 1-14)
//formaat: C/CCCCC/CC/CCC
lineNumber++;
await writer.WriteLineAsync(Regex.Replace(executingDoctor.RizivNr ?? string.Empty, @"(\w{1})(\w{5})(\w{2})(\w{3})", @"$1/$2/$3/$4"));
//(lijn 2:)Naam (positie 1-24) + Voornaam (positie 25-40)
//uitvoerend arts of paramedicus
lineNumber++;
await writer.WriteLineAsync(string.Concat(executingDoctor.LastName?.TrimToMaxSize(24).PadRight(24) ?? string.Empty, executingDoctor.FirstName).TrimToMaxSize(40));
//(lijn 3:)Straat (positie 1-35) + nr (positie 36-45)
//uitvoerend arts of paramedicus
lineNumber++;
await writer.WriteLineAsync(string.Concat(executingDoctor.Address?.Street?.TrimToMaxSize(35).PadRight(35) ?? string.Empty, executingDoctor.Address?.HouseNr).TrimToMaxSize(45));
//(lijn 4:)Postcode (positie 1-10) + Gemeente (positie 11-45)
//uitvoerend arts of paramedicus
lineNumber++;
await writer.WriteLineAsync(string.Concat(executingDoctor.Address?.PostalCode?.TrimToMaxSize(10).PadRight(10) ?? string.Empty, executingDoctor.Address?.HouseNr).TrimToMaxSize(45));
//(lijn 5:)Telefoon- en faxnummer (vrije tekst) (positie 1-50)
//uitvoerend arts of paramedicus
lineNumber++;
await writer.WriteLineAsync(executingDoctor.Phone?.TrimToMaxSize(50));
//(lijn 6:)Boodschap (vrije tekst) (positie 1-50)
lineNumber++;
await writer.WriteLineAsync(executingDoctor.Message?.TrimToMaxSize(50));
//(lijn 7:)Datum(+eventueel tijdstip) aanmaak diskette (positie 1-10)
//formaat: JJJJMMDD(+evtHHMM)
lineNumber++;
await writer.WriteLineAsync(executingDoctor.Date?.IsMidnight() ?? false ?
executingDoctor.Date?.ToString("yyyyMMdd") :
executingDoctor.Date?.ToString("yyyyMMddHHmm"));
//(lijn 8:)RIZIV-nummer aanvragende arts (positie 1-14)
//formaat: C/CCCCC/CC/CCC
lineNumber++;
await writer.WriteLineAsync(Regex.Replace(executingDoctor.RequestingDoctor?.RizivNr ?? string.Empty, @"(\w{1})(\w{5})(\w{2})(\w{3})", @"$1/$2/$3/$4"));
//(lijn 9:)Naam (positie 1-24) + Voornaam (positie 25-40)
//aanvragende arts
lineNumber++;
await writer.WriteLineAsync(string.Concat(executingDoctor.RequestingDoctor?.LastName?.TrimToMaxSize(24).PadRight(24) ?? string.Empty, executingDoctor.RequestingDoctor?.FirstName).TrimToMaxSize(40));
foreach (var patient in executingDoctor.Patients)
await ComposePatientBlock(writer, () => lineNumber, (ln) => lineNumber = ln, patient, true);
lineNumber++;
await writer.WriteLineAsync($"#/{lineNumber}");
lineNumberSetter(lineNumber);
}