【问题标题】:Adding config file for Cmdlet为 Cmdlet 添加配置文件
【发布时间】:2014-05-20 07:50:38
【问题描述】:

我已经制作了一个用于创建 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 可以访问的配置部分放在哪里?

【问题讨论】:

    标签: c# powershell appfabric powershell-cmdlet


    【解决方案1】:

    没关系。

    通过在没有配置的情况下以编程方式添加服务器来修复它

            DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
            servers[0] = new DataCacheServerEndpoint("localhost", 22233);
    
            DataCacheFactoryConfiguration conf = new DataCacheFactoryConfiguration();
    
            conf.Servers = servers;
    
            DataCacheFactory factory = new DataCacheFactory(conf);
    

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 2014-02-12
      • 2018-02-02
      相关资源
      最近更新 更多