小编and*_*eas的帖子

Powershell to Exchange 2013 - 受限制的语言模式错误

我正在开发一个将部署在Exchange 2013服务器上的C#Web服务.此服务将负责运行powershell命令以配置Exchange.

我通过这样创建的运行空间连接

const string shellUri = "http://schemas.microsoft.com/powershell/microsoft.exchange";
var uri = new Uri(_exchangeConnectionUri);
var credentials = (PSCredential)null; // Windows authentication
var connectionInfo = new WSManConnectionInfo(uri, shellUri, credentials);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
var runspace = RunspaceFactory.CreateRunspace(connectionInfo);
Run Code Online (Sandbox Code Playgroud)

使用此运行空间,我可以在服务器上运行基本的powershell命令.

get-mailbox -ResultSize unlimited
Run Code Online (Sandbox Code Playgroud)

但运行更复杂的命令会给我带来错误(如果直接通过powershell运行,这确实有效)

get-mailbox -ResultSize unlimited | where {$_.emailaddresses -like "*test.com"}

At line:1 char:43
+ get-mailbox -ResultSize unlimited | where {$_.emailaddresses -like "*test.com ...
+                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script block literals are not allowed in restricted language mode or a Data section.

At line:1 char:44
+ …
Run Code Online (Sandbox Code Playgroud)

powershell exchange-server

4
推荐指数
1
解决办法
9024
查看次数

EF选择性能 - Task.FromResult与ToListAsync

我试图找出使用异步等待通过实体框架选择数据的最佳方法.在以下代码中,我有两个选项.

第一个使用Task.FromResult.
第二个选项尝试使用async await关键字来优化代码.

1.

public Task<IEnumerable<DesignExample>> ExecuteAsync(GetAllExamplesQuery query)
{
    var designExamples = _copyDataDb.DesignExamples.OrderBy(dE => dE.Order).Select(DesignExample.MapFromEntity);

    return Task.FromResult(designExamples);
}
Run Code Online (Sandbox Code Playgroud)

2.

public async Task<IEnumerable<DesignExample>> ExecuteAsync(GetAllExamplesQuery query)
{
    var designExamples = await _copyDataDb.DesignExamples.OrderBy(dE => dE.Order).ToListAsync();

    return designExamples.Select(DesignExample.MapFromEntity);
}
Run Code Online (Sandbox Code Playgroud)
  • 第二种选择是否会提高与第一种选择相关的整体表现?
  • 第二个选项将等待对数据库的调用,但这会在这种情况下给我带来什么好处吗?

.net c# performance entity-framework async-await

2
推荐指数
1
解决办法
6060
查看次数