我想通过c#编程获取AppFabric
缓存主机的运行状态。有什么办法可以做到这一点吗?
最佳答案
您可以按照以下步骤使用 Powershell
命令来完成此操作;
- 下载
PowerShell v2 SDK
- 创建一个用于运行 Powershell 命令的环境。
var initialSessionState = InitialSessionState.CreateDefault(); initialSessionState.ThrowOnRunspaceOpenError = true; runspace = RunspaceFactory.CreateRunspace(initialSessionState); runspace.Open();
- 让我们创建一个 PipeLine。
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();
- 使用
结果
对象,
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
系统.管理.自动化
关于c# - 有没有办法以编程方式检查 AppFabric 缓存主机是否处于事件状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039453/