希望是一个非常简单的。我将一个应用程序.net-core
从.net
使用EWS
. 除了进行大量交互异步之外,所有似乎都可以正常工作而无需任何更改。除了从电子邮件下载附件。在调试和使用对象检查器时,FileAttachment
对象存在并且对象属性/大小看起来正是我所期望的。的FileAttachment
。Load
(string outputPath) 创建一个文件,但是,该文件的内容大小为 0KB。所以外壳已经创建,但没有数据流入其中。可能我错过了一些明显的东西,但明显的东西正在逃避我。尝试使用流和输出路径方法,结果相同。该功能在.net
框架版本中仍然可以正常工作。任何想法非常感谢?
foreach (EmailMessage email in orderedList)
{
EmailMessage message = await EmailMessage.Bind(_service, email.Id, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
if (email.HasAttachments)
{
foreach (Attachment attachment in message.Attachments)
{
bool getFile = false;
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
if (!string.IsNullOrEmpty(filename) && fileAttachment.Name.StartsWith(filename))
{
getFile = true;
}
else if (string.IsNullOrEmpty(filename))
{
getFile = true;
}
if (getFile)
{
//var response …
Run Code Online (Sandbox Code Playgroud) 目前尚不清楚为什么C#不允许调用将文字与in
参数修饰符一起传递的方法。同时,当将文字传递给不带in
参数修饰符的方法时,代码将进行编译。
这是一个演示此行为的代码示例(C#7.3):
class Program
{
static void Main(string[] args)
{
string s = string.Empty;
//These two lines compile
WriteStringToConsole(in s);
WriteStringToConsole("my string");
//Error CS8156 An expression cannot be used in this context because it may not be passed or returned by reference
WriteStringToConsole(in "my string");
}
public static void WriteStringToConsole (in string s)
{
Console.WriteLine(s);
}
}
Run Code Online (Sandbox Code Playgroud) 我的目标是编写一个中间件,负责记录对我的 API 的请求以及 API 对数据库中这些请求的响应。我已经制作了一个以类似方式处理异常的中间件,但我对此感到困惑。当你阅读有关中间件的 MSDN 时,你可以看到这张漂亮的图片:
这让您认为中间件 2 接收请求,对其进行某些操作并将其传递到中间件 3,然后一旦中间件 3 完成所有处理,它将控制权传递回中间件 2 进行其他处理。
我唯一不明白的是,如果 Middleware 2 Invoke() 方法仅在请求期间调用一次并且在响应期间不调用,如何记录响应?
启动.cs:
app.UseMiddleware<RequestLoggingMiddleware>();
Run Code Online (Sandbox Code Playgroud)
中间件:
public class RequestLoggingMiddleware
{
private readonly RequestDelegate nextMiddleware;
public RequestLoggingMiddleware(RequestDelegate nextMiddleware)
{
this.nextMiddleware = nextMiddleware;
this.options = options;
}
public async Task Invoke(HttpContext context)
{
System.Diagnostics.Debug.WriteLine("Middleware runs");
await nextMiddleware(context);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我仅在初始请求期间但在做出响应之前在控制台中看到“中间件运行”一次。如何让它在响应周期内运行?