static void SampleNewCacheAndRemove() { var commandRunner = new AppFabricPowershellCommandRunner(); var cmd2 = new Command("New-Cache"); var cacheName = "MyTestCache123"; cmd2.Parameters.Add("CacheName", cacheName); try { Console.WriteLine("Attempting to create a new cache: " + cacheName); commandRunner.Run(new Command("Use-CacheCluster"), cmd2); } catch (CmdletInvocationException ex) { Console.WriteLine(ex.ErrorRecord.ErrorDetails + " Error ID: " + ex.ErrorRecord.FullyQualifiedErrorId); var removeCmd = new Command("Remove-Cache"); removeCmd.Parameters.Add("CacheName", cacheName); commandRunner.Run(new Command("Use-CacheCluster"), removeCmd); } }
static void SampleGetCacheInfo() { var commandRunner = new AppFabricPowershellCommandRunner(); var output = commandRunner.Run(new Command("Use-CacheCluster"), new Command("Get-Cache")); Console.WriteLine("Caches in cluster:"); output.ToList().ForEach(o => { CacheInfo ci = (CacheInfo)o.BaseObject; Console.WriteLine(ci.CacheName); }); var cmd = new Command("Get-CacheHost"); cmd.Parameters.Add(new CommandParameter("HostName", "localhost")); cmd.Parameters.Add(new CommandParameter("CachePort", 22233)); var hostOutput = commandRunner.Run(new Command("Use-CacheCluster"), cmd); hostOutput.ToList().ForEach(h => { HostInfo hi = (HostInfo)h.BaseObject; Console.WriteLine(hi.HostName + " | " + hi.PortNo + " | " + hi.ServiceName + " | " + hi.Status + " | " + hi.VersionInfo); }); }