DD.WellWorkover.Cloud/AsbCloudInfrastructure/AssemblyExtensions.cs
Olga Nemt b7ce104e4e - Экспорт отчета Drill test
- Добавлен новый extension метод AssemblyExtensions.GetTemplateCopyStreamAsync
- IAutoGeneratedDailyReportMakerService переименован в IReportMakerService и стал более универсальным
2023-10-20 11:24:04 +05:00

31 lines
916 B
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure
{
public static class AssemblyExtensions
{
public static async Task<Stream> GetTemplateCopyStreamAsync(this Assembly assembly, string templateName, CancellationToken cancellationToken)
{
var resourceName = assembly
.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith(templateName))!;
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourceName)!;
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream, cancellationToken);
memoryStream.Position = 0;
return memoryStream;
}
}
}