| OLD | NEW |
| (Empty) |
| 1 // DTM machine deletion tool | |
| 2 // Author: Michael Goldish <mgoldish@redhat.com> | |
| 3 // Based on sample code by Microsoft. | |
| 4 | |
| 5 using System; | |
| 6 using System.Collections.Generic; | |
| 7 using System.Text.RegularExpressions; | |
| 8 using Microsoft.DistributedAutomation.DeviceSelection; | |
| 9 using Microsoft.DistributedAutomation.SqlDataStore; | |
| 10 | |
| 11 namespace automate0 | |
| 12 { | |
| 13 class AutoJob | |
| 14 { | |
| 15 static int Main(string[] args) | |
| 16 { | |
| 17 if (args.Length != 2) | |
| 18 { | |
| 19 Console.WriteLine("Error: incorrect number of command line argum
ents"); | |
| 20 Console.WriteLine("Usage: {0} serverName clientName", | |
| 21 System.Environment.GetCommandLineArgs()[0]); | |
| 22 return 1; | |
| 23 } | |
| 24 string serverName = args[0]; | |
| 25 string clientName = args[1]; | |
| 26 | |
| 27 try | |
| 28 { | |
| 29 // Initialize DeviceScript and connect to data store | |
| 30 Console.WriteLine("Initializing DeviceScript object"); | |
| 31 DeviceScript script = new DeviceScript(); | |
| 32 Console.WriteLine("Connecting to data store"); | |
| 33 script.ConnectToNamedDataStore(serverName); | |
| 34 | |
| 35 // Find the client machine | |
| 36 IResourcePool rootPool = script.GetResourcePoolByName("$"); | |
| 37 Console.WriteLine("Looking for client machine '{0}'", clientName
); | |
| 38 IResource machine = rootPool.GetResourceByName(clientName); | |
| 39 if (machine == null) | |
| 40 { | |
| 41 Console.WriteLine("Client machine not found"); | |
| 42 return 0; | |
| 43 } | |
| 44 Console.WriteLine("Client machine '{0}' found ({1}, {2})", | |
| 45 clientName, machine.OperatingSystem, machine.ProcessorArchit
ecture); | |
| 46 | |
| 47 // Change the client machine's status to 'unsafe' | |
| 48 Console.WriteLine("Changing the client machine's status to 'Unsa
fe'"); | |
| 49 try | |
| 50 { | |
| 51 machine.ChangeResourceStatus("Unsafe"); | |
| 52 } | |
| 53 catch (Exception e) | |
| 54 { | |
| 55 Console.WriteLine("Warning: " + e.Message); | |
| 56 } | |
| 57 while (machine.Status != "Unsafe") | |
| 58 { | |
| 59 try | |
| 60 { | |
| 61 machine = rootPool.GetResourceByName(clientName); | |
| 62 } | |
| 63 catch (Exception e) | |
| 64 { | |
| 65 Console.WriteLine("Warning: " + e.Message); | |
| 66 } | |
| 67 System.Threading.Thread.Sleep(1000); | |
| 68 } | |
| 69 | |
| 70 // Delete the client machine from datastore | |
| 71 Console.WriteLine("Deleting client machine from data store"); | |
| 72 script.DeleteResource(machine.Id); | |
| 73 return 0; | |
| 74 } | |
| 75 catch (Exception e) | |
| 76 { | |
| 77 Console.WriteLine("Error: " + e.Message); | |
| 78 return 1; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 } | |
| OLD | NEW |