public UCD_Data.APIOutput ListResources(string parentResource) { RestRequest request = new RestRequest { Method = Method.GET, Resource = "cli/resource" }; request.AddParameter("parent", parentResource, ParameterType.QueryString); request.AddHeader("Accept", "application/json"); UCD_Data.APIOutput result = new UCD_Data.APIOutput(); IRestResponse <List <UCD_Data.Resources.RootObject> > output = client.Execute <List <UCD_Data.Resources.RootObject> >(request); if (output.IsSuccessful) { // DataTable DataTable DT = new DataTable(); DT = new DataTable(); // Adding Columns DT.Columns.Add("No"); DT.Columns.Add("Hostname"); DT.Columns.Add("IP Address"); DT.Columns.Add("OS Type"); DT.Columns.Add("Status"); DT.Columns.Add("RID"); // Adding Rows int index = 1; foreach (UCD_Data.Resources.RootObject resouce in output.Data) { DataRow DR = DT.NewRow(); DR[0] = index; //DR[1] = resouce.name.Split('|')[1]; //DR[2] = resouce.name.Split('|')[2]; //DR[3] = resouce.name.Split('|')[0]; DR[1] = resouce.name; DR[2] = resouce.name; DR[3] = resouce.name; DR[4] = resouce.status; DR[5] = resouce.id; DT.Rows.Add(DR); index++; } // Updating the output class with data result.APIData = output.Data; result.Table = DT; } else { ErrorHandler(output.Content, MethodBase.GetCurrentMethod()); } return(result); }
// Method to create team private void CreateTeam() { try { APICall.CreateTeam("UrbanCoder", "The team used by the UrbanCoder application."); // Updating teamInfo with newly created team details. teamInfo = APICall.GetTeamInfo("UrbanCoder").APIData; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public UCD_Data.APIOutput GetTeamInfo(string teamName) { RestRequest request = new RestRequest { Method = Method.GET, Resource = "cli/team/info" }; request.AddParameter("team", teamName, ParameterType.QueryString); request.AddHeader("Accept", "application/json"); UCD_Data.APIOutput result = new UCD_Data.APIOutput(); IRestResponse <UCD_Data.TeamInfo.RootObject> output = client.Execute <UCD_Data.TeamInfo.RootObject>(request); if (output.IsSuccessful) { // DataTable DataTable DT = new DataTable(); DT = new DataTable(); // Adding Columns DT.Columns.Add("No"); DT.Columns.Add("Name"); DT.Columns.Add("Display Name"); DT.Columns.Add("Actual Name"); DT.Columns.Add("Role"); DT.Columns.Add("Last Login Date"); DT.Columns.Add("Locked Out ?"); // Adding Rows int index = 1; foreach (UCD_Data.TeamInfo.RoleMapping roles in output.Data.roleMappings) { DataRow DR = DT.NewRow(); DR[0] = index; DR[1] = roles.user.name; DR[2] = roles.user.displayName; DR[3] = roles.user.actualName; DR[4] = roles.role.name; DR[5] = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(Convert.ToDouble(roles.user.lastLoginDate)); DR[6] = roles.user.isLockedOut; DT.Rows.Add(DR); index++; } // Updating the output class with data result.APIData = output.Data; result.Table = DT; } else { ErrorHandler(output.Content, MethodBase.GetCurrentMethod()); } return(result); }
// Method to update user data private void FillUsers() { teamInfo = APICall.GetTeamInfo("UrbanCoder"); // Listing Users if (SP_DGVHolder.Children.Count == 1 && teamInfo.Table != null) { userDataGrid = new PaginatedDataGrid(teamInfo.Table); userDataGrid.Name = "userData"; userDataGrid.DGV.MouseDoubleClick += DataGrid_DoubleClick; userDataGrid.B_Refresh.Click += Refresh_Click; SP_DGVHolder.Children.Add(userDataGrid); } else if (teamInfo.Table != null) { userDataGrid.UpdateData(teamInfo.Table); } }
private void Login() { try { ShowErrorMessage(); // Validating Login Prerequisites if (string.IsNullOrEmpty(T_URI.Text) || string.IsNullOrEmpty(T_Username.Text) || string.IsNullOrEmpty(T_Password.Password)) { ShowErrorMessage("Enter the URL, Username and Password !"); return; } // Creating API Client APICall = new UCD_Client(T_URI.Text, T_Username.Text, T_Password.Password, CB_Cert.IsChecked.Value); // Fetching UrbanCoder team information teamInfo = APICall.GetTeamInfo("UrbanCoder"); // Checking if user is part of UrbanCoder team bool addToTeam = true; foreach (UCD_Data.TeamInfo.RoleMapping userData in teamInfo.APIData.roleMappings) { if (userData.user.name == T_Username.Text) { addToTeam = false; break; } } // Adding user to Team if (addToTeam) { APICall.AddUserToTeam("UrbanCoder", T_Username.Text, "Administrator"); } // Successfully Logged In IsLoggedIn(true); ShowErrorMessage(); FillUsers(); // Checking if UrbanCoder pre-requisites are met.(Resource data etc) resourceInfo = APICall.ListResources("UrbanCoder"); } catch (UC_LoginFailed) { ShowErrorMessage("Invalid Username or Password !"); } catch (UC_TeamNotFound) { // First Login detected, trying to create a Team CreateTeam(); } catch (UC_UnknownUser) { ShowErrorMessage("You do not belong to the UrbanCoder Team in UCD !"); } catch (UC_ResourceNotFound) { // Enabling create data options as the resource is not there. SP_CreateDataHolder.IsEnabled = true; CreateParentResource(); } catch (Exception ex) { ShowErrorMessage("Error in Login: " + ex.Message); } }