private static List <Machines> PresentMachinesInAReadableWay(string responseFromGetMachines) { try { Console.WriteLine("\nPlease select the identifier "); string text = responseFromGetMachines; List <Machines> Machines = new List <Machines>(); var machineDetails = JObject.Parse(text)["value"] .ToList(); int i = 1; Console.WriteLine("Identifier\t\tMachine Name\t\t\t MachineId"); foreach (var token in machineDetails) { Machines mm = new Machines(); mm.Identifier = i++; mm.MachineName = token.Value <string>("Name"); mm.MachineId = token.Value <long>("Id"); Console.WriteLine("{0}\t\t{1}\t\t\t{2}", mm.Identifier, mm.MachineName, mm.MachineId); Machines.Add(mm); } return(Machines); } catch (Exception ex) { Console.WriteLine("Exception : " + ex.Message); Console.WriteLine("Stack Trace : " + ex.StackTrace); throw; } }
static void Main(string[] args) { string tenantName = string.Empty; Console.WriteLine("Enter Tenant name : "); tenantName = Console.ReadLine(); string emailId = string.Empty; Console.WriteLine("Enter EmailID to login to Orchestrator : "); emailId = Console.ReadLine(); string pwd = string.Empty; Console.WriteLine("Enter password to login to orchestrator : "); pwd = Console.ReadLine(); //api call to get auth token var jsonResponse = PostAuthenticateToUiPathPlatform(tenantName, emailId, pwd); // Console.WriteLine("Authentication from Orchestrator "); dynamic parsedJson = JsonConvert.DeserializeObject(jsonResponse); //Console.Write(JsonConvert.SerializeObject(parsedJson, Formatting.Indented)); //Console.WriteLine("\n\n\n "); var token = ExtractAuthenticationKey(jsonResponse); /****************************/ // api to get machines //Console.WriteLine("\n\n\n "); var responseFromGetMachines = GetMachines(token); // Console.WriteLine("Response from Get Machines Call "); parsedJson = JsonConvert.DeserializeObject(responseFromGetMachines.Result); // Console.Write(JsonConvert.SerializeObject(parsedJson, Formatting.Indented)); var machinesInReadableWay = PresentMachinesInAReadableWay(responseFromGetMachines.Result); if (machinesInReadableWay.Count <= 0) { return; } string oldMachineName = string.Empty; long oldMachineId = 0; string NewMachineName = string.Empty; long NewMachineId = 0; var OldMachineDetails = SelectOldMachineDetails(); var oldM = new Machines(); foreach (var i in machinesInReadableWay) { if (i.Identifier == OldMachineDetails) { oldM.MachineName = i.MachineName; oldM.MachineId = i.MachineId; oldMachineName = i.MachineName; oldMachineId = i.MachineId; break; } } var NewMachineDetails = SelectNewMachineDetails(); var newM = new Machines(); foreach (var i in machinesInReadableWay) { if (i.Identifier == NewMachineDetails) { newM.MachineName = i.MachineName; newM.MachineId = i.MachineId; NewMachineName = i.MachineName; NewMachineId = i.MachineId; break; } } /****************/ Console.WriteLine("\nOld Machine Name {0} , Old Machine Id {1} ", oldMachineName, oldMachineId); Console.WriteLine("\nNew Machine Name {0} , New Machine Id {1} ", NewMachineName, NewMachineId); /******************/ //Console.WriteLine("\n\n\n "); var responseFromGetRobots = GetRobots(token); //Console.WriteLine("Response from Get Robots Call "); //parsedJson = JsonConvert.DeserializeObject(responseFromGetRobots.Result); //Console.Write(JsonConvert.SerializeObject(parsedJson, Formatting.Indented)); Console.WriteLine("\nExtracting robots information from GetRobots response"); var robotsToBeUpdated = GetRobotsDetails(responseFromGetRobots.Result, oldMachineName, oldMachineId); if (robotsToBeUpdated.Count > 0) { Console.WriteLine("\n"); //UpdateRobotsWithNewMachineInfo(robotsToBeUpdated, token, newMachineName, newMachineId); UpdateRobotsWithNewMachineInfo(robotsToBeUpdated, token, NewMachineName, NewMachineId); } else { Console.WriteLine("\nNo robots are associated with your selection of Old Machine "); } Console.WriteLine("Press any key to exit ...."); Console.ReadLine(); }