我认为标题很清楚,我上网冲浪了大约一个小时,但每个页面都讨论使用 .net 动态创建区域。我确信我们有一个可以在 powershell 上执行的命令。你知道吗?
提前致谢,
最佳答案
没有现成的 Powershell commandlet 用于创建/管理区域。
解决方案 - 写一个!
正如 Daniel Richnak 在评论中所说,Powershell 本质上是 .NET,这意味着您可以编写额外的 Powershell commandlet 来填补空白。
命令行开关是一个继承自System.Management.Automation.Cmdlet
的常规类,并且它也使用System.Management.Automation.Cmdlet
属性进行修饰。使其工作只需重写 ProcessRecord 方法即可。命令行参数作为类的属性实现,并用 System.Management.Automation.Parameter 属性修饰。因此,用于创建区域的命令行开关将类似于:
using System.Management.Automation;
using Microsoft.ApplicationServer.Caching;
[Cmdlet(VerbsCommon.New, "CacheRegion")]
public class NewCacheRegion : Cmdlet
{
[Parameter(Mandatory = true, Position = 1)]
public string Cache { get; set; }
[Parameter(Mandatory = true, Position = 2)]
public string Region { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
DataCacheFactory factory = new DataCacheFactory();
DataCache cache = factory.GetCache(Cache);
try
{
cache.CreateRegion(Region);
}
catch (DataCacheException ex)
{
if (ex.ErrorCode == DataCacheErrorCode.RegionAlreadyExists)
{
Console.WriteLine(string.Format("There is already a region named {0} in the cache {1}.", Region, Cache));
}
}
}
}
关于.net - 如何通过 Powershell 在 App Fabric 上创建区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9593193/