我已经创建了一个用于创建AppFabric区域的powershell Cmdlet,代码:
[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) {}
}
}
安装了import-module appfabriccmdlet.dll,代码在运行new-cacheregion时执行。
但这一行
DataCacheFactory factory = new DataCacheFactory();
抛出一个异常,即服务器集合为空,这意味着在app.config中找不到dataCacheClient节。所以我想要一个客户端,但我不知道在哪个配置文件中添加appfabric部分。我已经尝试找出cmdlet dll运行的可执行文件
Assembly a = Assembly.GetEntryAssembly();
但返回null。
那么我需要在哪里放置cmdlet dll可以访问的配置节?
答案 0 :(得分:0)
没关系。
通过以编程方式添加没有配置的服务器来修复它
DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
servers[0] = new DataCacheServerEndpoint("localhost", 22233);
DataCacheFactoryConfiguration conf = new DataCacheFactoryConfiguration();
conf.Servers = servers;
DataCacheFactory factory = new DataCacheFactory(conf);