質問

キャッシュアイテムを設定/取得/削除することを可能にするために単純な小さなコマンドレットを書いてみました。私が持っている問題は、ローカルキャッシュクラスタへの接続方法を理解できないことです。

私はいつものapp.configのものを追加しようとしましたが、それは拾われるようには思われません...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>
  <dataCacheClient>
    <hosts>
      <host name="localhost" cachePort="22233" />
    </hosts>
  </dataCacheClient>
</configuration>
.

その設定はまったくありません。だから私が本当に尋ねているのは、次のPowerShellのためのC#コードが何であるかということです...

Use-CacheCluster
. パラメータが指定されていない場合は、Use-CacheClusterを収集できるものから、

役に立ちましたか?

解決

リフレクターを使ってAppFabric PowerShellコードに綴りをして、カバーの下でどのように機能するかを確認しました。パラメータなしでUse-CacheClusterを呼び出すと。ローカルクラスタの場合、コードはレジストリキーGeneraCoditagCodeから接続文字列とプロバイダ名を読み取ります。残念ながら、これらの値を使用して一連のクラス(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\ConfigurationClusterConfigElementおよびCacheAdmin)を構築します。PowerShellは一緒に取り組んでいます。

あなたのコマンドレットを作業するために、それから私はあなたがホスト名(あなたのクラスタ内のサーバーの1つになるでしょう、そしてそれはあなたがローカルマシン名にデフォルトである)とポート番号を渡すことができると思います。デフォルトは22233に設定でき、それらの値を使用してClusterHandlerを作成するために

[Cmdlet(VerbsCommon.Set,"Value")]
public class SetValueCommand : Cmdlet
{
    [Parameter]
    public string Hostname { get; set; }
    [Parameter]
    public int PortNumber { get; set; }
    [Parameter(Mandatory = true)]
    public string CacheName { get; set; }

    protected override void ProcessRecord()
    {
        base.ProcessRecord();

        // Read the incoming parameters and default to the local machine and port 22233
        string host = string.IsNullOrWhiteSpace(Hostname) ? Environment.MachineName : Hostname;
        int port = PortNumber == 0 ? 22233 : PortNumber;

        // Create an endpoint based on the parameters
        DataCacheServerEndpoint endpoint = new DataCacheServerEndpoint(host, port);

        // Create a config using the endpoint
        DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration();
        config.Servers = new List<DataCacheServerEndpoint> { endpoint };

        // Create a factory using the config
        DataCacheFactory factory = new DataCacheFactory(config);

        // Get a reference to the cache so we can now start doing useful work...
        DataCache cache = factory.GetCache(CacheName);
        ...
    }
}
.

他のヒント

問題は、コールが次のとおりです。 DataCacheFactoryConfiguration config= new DataCacheFactoryConfiguration();

内部コマンドレットMothodsは "DataCachefactoryConfigurationを初期化できません"のようなエラーが発生します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top