C# 正在为Cmdlet添加配置文件
我制作了一个powershell Cmdlet,用于创建AppFabric a区域,代码为:C# 正在为Cmdlet添加配置文件,c#,powershell,appfabric,cmdlets,C#,Powershell,Appfabric,Cmdlets,我制作了一个powershell Cmdlet,用于创建AppFabric a区域,代码为: [Cmdlet(VerbsCommon.New, "CacheRegion")] public class NewCacheRegion : Cmdlet { [Parameter(Mandatory = true, Position = 1)] public string Cache { get; set; } [Parameter(Mandatory = true
[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(); // exception
DataCache cache = factory.GetCache(Cache);
try {
cache.CreateRegion(Region);
}
catch (DataCacheException ex) {}
}
}
它与导入模块appfabriccmdlet.dll一起安装,代码在运行新的cacheregion时执行
但是这条线
DataCacheFactory factory = new DataCacheFactory();
引发服务器集合为空的异常,这意味着在app.config中找不到dataCacheClient节。所以我想要一个客户端,但我不确定在哪个配置文件中添加appfabric部分。我已尝试从cmdlet dll运行的可执行文件中查找
Assembly a = Assembly.GetEntryAssembly();
但它返回空值
那么,我需要将cmdlet dll有权访问的配置部分放在哪里呢?没关系
通过编程方式添加不带配置的服务器修复了此问题
DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
servers[0] = new DataCacheServerEndpoint("localhost", 22233);
DataCacheFactoryConfiguration conf = new DataCacheFactoryConfiguration();
conf.Servers = servers;
DataCacheFactory factory = new DataCacheFactory(conf);