문제

나는 캐시 항목을 설정/가져오기/제거할 수 있는 간단한 Cmdlet을 작성하려고 했습니다.내가 가진 문제는 로컬 캐시 클러스터에 연결하는 방법을 알 수 없다는 것입니다.

일반적인 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 매개변수가 제공되지 않은 경우 로컬 클러스터에 연결

도움이 되었습니까?

해결책

방금 Reflector를 사용하여 AppFabric Powershell 코드에 대해 몇 가지 조사를 수행하여 내부적으로 어떻게 작동하는지 확인했습니다.전화하면 Use-CacheCluster 매개변수가 없습니다.로컬 클러스터의 경우 코드는 레지스트리 키에서 연결 문자열과 공급자 이름을 읽습니다. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\AppFabric\V1.0\Configuration.불행하게도 그런 다음 해당 값을 사용하여 일련의 클래스(ClusterConfigElement, CacheAdmin 그리고 ClusterHandler) 모두 내부로 표시되어 있으므로 이를 사용하여 Powershell이 ​​작업하는 현재 클러스터 컨텍스트(더 나은 단어를 원함)를 선택하는 데 사용할 수 없습니다.

그러면 Cmdlet이 작동하게 하려면 호스트 이름(클러스터의 서버 중 하나가 되며 기본값은 로컬 컴퓨터 이름이 될 수 있음)과 포트 번호(기본값으로 지정될 수 있음)를 전달해야 한다고 생각합니다. ~ 22233), 해당 값을 사용하여 DataCacheServerEndpoint 당신에게 전달하기 위해 DataCacheFactory 예를 들어

[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();

Cmdlet mothods 내부에서 "DataCacheFactoryConfiguration을 초기화할 수 없습니다"와 같은 오류가 발생합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top