【问题标题】:Is there any way to programmatically check whether AppFabric cache host is active?有没有办法以编程方式检查 AppFabric 缓存主机是否处于活动状态?
【发布时间】:2012-12-26 10:43:06
【问题描述】:

我想通过c#编程获取AppFabric缓存主机的运行状态。有没有办法做到这一点?

【问题讨论】:

    标签: c# .net status appfabric host


    【解决方案1】:

    您可以按照以下步骤使用Powershell 命令进行操作;

    var initialSessionState = InitialSessionState.CreateDefault();
    initialSessionState.ThrowOnRunspaceOpenError = true;
    runspace = RunspaceFactory.CreateRunspace(initialSessionState);
    runspace.Open();
    
    • 让我们创建一个管道。

    var pipeline = runspace.CreatePipeline();

    • 将命令行传递到在缓存中运行的 Powershell 中的管道。
    pipeline.Commands.Add(new Command("Use-CacheCluster"));
    pipeline.Commands.Add(new Command("Get-CacheHost"));
    

    Get-CacheHost 为我们提供缓存服务器信息。并使用Invoke() 方法运行。

    var result = pipeline.Invoke();

    • 带有result对象,
    var initialSessionState = InitialSessionState.CreateDefault();
    initialSessionState.ImportPSModule(new[] { "DistributedCacheAdministration" });
    initialSessionState.ThrowOnRunspaceOpenError = true;
    
    runspace = RunspaceFactory.CreateRunspace(initialSessionState);
    
    runspace.Open();
    
    var pipeline = runspace.CreatePipeline();
    pipeline.Commands.Add(new Command("Use-CacheCluster"));
    pipeline.Commands.Add(new Command("Get-CacheHost"));
    var result = pipeline.Invoke();
    
    var hostInfo = (HostInfo)result[0].BaseObject;
    
    Console.Out.WriteLine("Server Name        : " + hostInfo.HostName);
    Console.Out.WriteLine("Server Port      : " + hostInfo.PortNo);
    Console.Out.WriteLine("Server Service Name : " + hostInfo.ServiceName);
    Console.Out.WriteLine("Server Status    : " + hostInfo.Status);
    Console.Out.WriteLine("Server Version     : " + hostInfo.VersionInfo);
    

    另外,不要忘记添加这些程序集引用;

    • Microsoft.ApplicationServer.Caching.Client
    • Microsoft.ApplicationServer.Caching.Core
    • Microsoft.ApplicationServer.Caching.Management
    • System.Management.Automation

    【讨论】:

    • 我知道 Powershell 命令。是否有任何 AppFabric API 可以帮助我们实现这一目标?
    • 其实我不知道有什么appfabric api可以做这个。
    猜你喜欢
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多