public JObject EditRemoteApp(string deploymentUrl, string accessToken, JObject rdMgmtRemoteApp) { try { //call rest api to publish remote appgroup app var content = new StringContent(JsonConvert.SerializeObject(rdMgmtRemoteApp), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.PatchAsync(deploymentUrl, accessToken, "/RdsManagement/V1/TenantGroups/" + rdMgmtRemoteApp["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtRemoteApp["tenantName"].ToString() + "/HostPools/" + rdMgmtRemoteApp["hostPoolName"].ToString() + "/AppGroups/" + rdMgmtRemoteApp["appGroupName"].ToString() + "/RemoteApps/" + rdMgmtRemoteApp["remoteAppName"].ToString(), content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.OK) { appResult.Add("isSuccess", true); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has been updated successfully."); } } else if ((int)response.StatusCode == 429) { appResult.Add("isSuccess", false); appResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { appResult.Add("isSuccess", false); appResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { appResult.Add("isSuccess", false); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has not been updated. Please try it later again."); } } } catch (Exception ex) { appResult.Add("isSuccess", false); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has not been updated." + ex.Message.ToString() + " Please try it later again."); } return(appResult); }
/// <summary> /// Description : create a RDs tenant /// </summary> /// <param name="deploymenturl">RD Broker Url</param> /// <param name="accessToken">Aaccess Token</param> /// <param name="rdMgmtTenant">Tenant Class</param> /// <returns></returns> public JObject CreateTenant(string deploymenturl, string accessToken, JObject tenantDataDTO) { try { //call rest api to create tenant-- july code bit var content = new StringContent(JsonConvert.SerializeObject(tenantDataDTO), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymenturl, accessToken).PostAsync("/RdsManagement/V1/TenantGroups/" + tenantDataDTO["tenantGroupName"].ToString() + "/Tenants/" + tenantDataDTO["tenantName"].ToString(), content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { if (response.StatusCode == System.Net.HttpStatusCode.Created || response.StatusCode == System.Net.HttpStatusCode.OK) { tenantResult.Add("isSuccess", true); tenantResult.Add("message", "Tenant '" + tenantDataDTO["tenantName"] + "' has been created successfully."); } } else if ((int)response.StatusCode == 429) { tenantResult.Add("isSuccess", false); tenantResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { tenantResult.Add("message", CommonBL.GetErrorMessage(strJson)); tenantResult.Add("isSuccess", false); } else { tenantResult.Add("isSuccess", false); tenantResult.Add("message", "Tenant '" + tenantDataDTO["tenantName"] + "' has not been created. Please try it again later."); } } } catch (Exception ex) { tenantResult.Add("isSuccess", false); tenantResult.Add("message", "Tenant '" + tenantDataDTO["tenantName"] + "' has not been created." + ex.Message.ToString() + " and please try again later."); } return(tenantResult); }
/// <summary> /// Description - get list of user session /// </summary> /// <param name="deploymentUrl"></param> /// <param name="accessToken"></param> /// <param name="tenantName"></param> /// <param name="hostPoolName"></param> /// old parameters-- , bool isAll, int pageSize, string sortField, bool isDescending, int initialSkip, string lastEntry /// <returns></returns> public HttpResponseMessage GetListOfUserSessioons(string deploymentUrl, string accessToken, string tenantGroup, string tenantName, string hostPoolName, string hostName = null) { try { HttpResponseMessage response; response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroup + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/Sessions").Result; if (hostName != null) { var data = response.Content.ReadAsStringAsync().Result; var arr = (JArray)JsonConvert.DeserializeObject(data); var result = ((JArray)arr).Select(item => new JObject() { new JProperty("tenantGroupName", item["tenantGroupName"]), new JProperty("tenantName", item["tenantName"]), new JProperty("hostPoolName", item["hostPoolName"]), new JProperty("sessionHostName", item["sessionHostName"]), new JProperty("userPrincipalName", item["userPrincipalName"]), new JProperty("sessionId", item["sessionId"]), new JProperty("applicationType", item["applicationType"]), new JProperty("adUserName", item["adUserName"]), new JProperty("createTime", item["createTime"]), new JProperty("sessionState", item["sessionState"]) }).ToList().Where(x => x["sessionHostName"].ToString() == hostName).ToList(); return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(result)), StatusCode = System.Net.HttpStatusCode.OK }); } return(response); //api call included pagination //response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroup + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/Sessions?PageSize=" + pageSize + "&LastEntry=" + lastEntry + "&SortField=" + sortField + "&IsDescending=" + isDescending + "&InitialSkip=" + initialSkip).Result; } catch { return(null); } }
/// <summary> /// Description-Gets the published desktop for host pool's application group /// </summary> /// <param name="deploymentUrl">RD Broker url</param> /// <param name="accessToken">Access Token</param> /// <param name="tenantName">Name of Tenant</param> /// <param name="hostPoolName">Name of Hostpool</param> /// <param name="appGroupName">Name of App Group</param> /// <returns></returns> public RdMgmtPublishedDesktop GetPublishedDesktop(string deploymentUrl, string accessToken, string tenantGroup, string tenantName, string hostPoolName, string appGroupName) { RdMgmtPublishedDesktop rdMgmtPublishedDesktop = new RdMgmtPublishedDesktop(); try { //call rest api to get all published desktop apps in app groups -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroup + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/Desktop").Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { //Deserialize the string to JSON object rdMgmtPublishedDesktop = JsonConvert.DeserializeObject <RdMgmtPublishedDesktop>(strJson); } } catch { return(null); } return(rdMgmtPublishedDesktop); }
/// <summary> /// Description : Removes a Rds SessionHost associated with the Tenant and HostPool specified in the Rds context. /// </summary> /// <param name="deploymenturl">RD Broker Url</param> /// <param name="accessToken"> Access Token</param> /// <param name="tenantName">Name of Tenant</param> /// <param name="hostPoolName">Name of Hostpool</param> /// <param name="sessionHostName">Name of Session Host</param> /// <returns></returns> public SessionHostResult DeletesessionHost(string deploymentUrl, string accessToken, string tenantGroup, string tenantName, string hostPoolName, string sessionHostName) { SessionHostResult sessionHostResult = new SessionHostResult(); try { //call rest service to delete session host -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).DeleteAsync("/RdsManagement/V1/TenantGroups/" + tenantGroup + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/SessionHosts/" + sessionHostName + "?Force=True").Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { sessionHostResult.isSuccess = true; sessionHostResult.message = "Session host '" + sessionHostName + "' has been deleted successfully."; } else if ((int)response.StatusCode == 429) { sessionHostResult.isSuccess = false; sessionHostResult.message = strJson + " Please try again later."; } else { if (!string.IsNullOrEmpty(strJson)) { sessionHostResult.isSuccess = false; sessionHostResult.message = CommonBL.GetErrorMessage(strJson); } else { sessionHostResult.isSuccess = false; sessionHostResult.message = "Session host " + sessionHostName + " has not been deleted. Please try it later again."; } } } catch (Exception ex) { sessionHostResult.isSuccess = false; sessionHostResult.message = "Session host " + sessionHostName + " has not been deleted." + ex.Message.ToString() + " Please try it later again."; } return(sessionHostResult); }
/// <summary> /// Description : Adds a user to an AppGroup within Tenant and HostPool associated with the specified Rds context. /// </summary> /// <param name="deploymentUrl">RD Broker Url</param> /// <param name="accessToken"> Access Token</param> /// <param name="rdMgmtUser"> App Group user claass</param> /// <returns></returns> public JObject CreateAppGroupUser(string deploymentUrl, string accessToken, JObject rdMgmtUser) { try { //call rest service to add user to app group - july code bit var content = new StringContent(JsonConvert.SerializeObject(rdMgmtUser), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("/RdsManagement/V1/TenantGroups/" + rdMgmtUser["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtUser["tenantName"].ToString() + "/HostPools/" + rdMgmtUser["hostPoolName"].ToString() + "/AppGroups/" + rdMgmtUser["appGroupName"].ToString() + "/AssignedUsers/" + rdMgmtUser["userPrincipalName"].ToString(), content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { groupResult.Add("isSuccess", true); groupResult.Add("message", "User '" + rdMgmtUser["userPrincipalName"].ToString() + "' has been added to app group " + rdMgmtUser["appGroupName"].ToString() + " successfully."); } else if ((int)response.StatusCode == 429) { groupResult.Add("isSuccess", false); groupResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { groupResult.Add("isSuccess", false); groupResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { groupResult.Add("isSuccess", false); groupResult.Add("message", "User '" + rdMgmtUser["userPrincipalName"].ToString() + "' has not been added to app group. Please try it later again. "); } } } catch (Exception ex) { groupResult.Add("isSuccess", false); groupResult.Add("message", "User '" + rdMgmtUser["userPrincipalName"].ToString() + "' has not been added to app group " + ex.Message.ToString() + " Please try again later."); } return(groupResult); }
/// <summary> /// Description : Update tenant information /// </summary> /// <param name="deploymenturl">RD Broker Url</param> /// <param name="accessToken">Access Token</param> /// <param name="rdMgmtTenant">Tenant Class</param> /// <returns></returns> public JObject UpdateTenant(string deploymenturl, string accessToken, JObject rdMgmtTenant) { try { //call rest api to update tenant -- july code bit var content = new StringContent(JsonConvert.SerializeObject(rdMgmtTenant), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.PatchAsync(deploymenturl, accessToken, "/RdsManagement/V1/TenantGroups/" + rdMgmtTenant["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtTenant["tenantName"].ToString(), content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { tenantResult.Add("isSuccess", true); tenantResult.Add("message", "Tenant '" + rdMgmtTenant["tenantName"] + "' has been updated successfully."); } else if ((int)response.StatusCode == 429) { tenantResult.Add("isSuccess", false); tenantResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { tenantResult.Add("isSuccess", false); tenantResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { tenantResult.Add("isSuccess", false); tenantResult.Add("message", "Tenant '" + rdMgmtTenant["tenantName"] + "' has not been updated. Please try again later."); } } } catch (Exception ex) { tenantResult.Add("isSuccess", false); tenantResult.Add("message", "Tenant " + rdMgmtTenant["tenantName"] + " has not been updated." + ex.Message.ToString() + " Please try again later."); } return(tenantResult); }
/// <summary> /// /// </summary> /// <param name="deploymentUrl"></param> /// <param name="accessToken"></param> /// <param name="rdMgmtSessionHost"></param> /// <returns></returns> public JObject ChangeDrainMode(string deploymentUrl, string accessToken, JObject rdMgmtSessionHost) { try { //call rest service to update Sesssion host -- july code bit var content = new StringContent(JsonConvert.SerializeObject(rdMgmtSessionHost), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.PatchAsync(deploymentUrl, accessToken, "/RdsManagement/V1/TenantGroups/" + rdMgmtSessionHost["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtSessionHost["tenantName"].ToString() + "/HostPools/" + rdMgmtSessionHost["hostPoolName"].ToString() + "/SessionHosts/" + rdMgmtSessionHost["sessionHostName"].ToString(), content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { hostResult.Add("isSuccess", true); hostResult.Add("message", "'Allow new Session' is set to " + rdMgmtSessionHost["allowNewSession"] + " for " + rdMgmtSessionHost["sessionHostName"].ToString() + "'."); } else if ((int)response.StatusCode == 429) { hostResult.Add("isSuccess", false); hostResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { hostResult.Add("isSuccess", false); hostResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { hostResult.Add("isSuccess", false); hostResult.Add("message", "Failed to set 'Allow new Session' for '" + rdMgmtSessionHost["sessionHostName"].ToString() + "'. Please try it again later."); } } } catch (Exception ex) { hostResult.Add("isSuccess", false); hostResult.Add("message", "Failed to set 'Allow new Session' for '" + rdMgmtSessionHost["sessionHostName"].ToString() + "'. " + ex.Message.ToString() + " Please try it again later."); } return(hostResult); }
public JObject LogOffUserSesion(string deploymentUrl, string accessToken, JObject userSession) { try { //call rest service to log off user sessions var content = new StringContent(JsonConvert.SerializeObject(userSession), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("/RdsManagement/V1/TenantGroups/" + userSession["tenantGroupName"] + "/Tenants/" + userSession["tenantName"] + "/HostPools/" + userSession["hostPoolName"] + "/SessionHosts/" + userSession["sessionHostName"] + "/Sessions/" + userSession["sessionId"] + "/actions/logoff-user", content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { userSessionResult.Add("isSuccess", true); userSessionResult.Add("message", "Log off successfully for '" + userSession["adUserName"].ToString() + "'"); } else if ((int)response.StatusCode == 429) { userSessionResult.Add("isSuccess", false); userSessionResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { userSessionResult.Add("isSuccess", false); userSessionResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { userSessionResult.Add("isSuccess", false); userSessionResult.Add("message", "Failed to log off '" + userSession["adUserName"].ToString() + "'. Please try it again later."); } } } catch (Exception ex) { userSessionResult.Add("isSuccess", false); userSessionResult.Add("message", "Failed to log off '" + userSession["adUserName"].ToString() + "'." + ex.Message.ToString() + " Please try it again later."); } return(userSessionResult); }
/// <summary> /// Description Description : Removes an user from an AppGroup within a Tenant, HostPool and AppGroup associated with the specified Rds context /// </summary> /// <param name="deploymentURL">RD Broker Url</param> /// <param name="accessToken">Access Token</param> /// <param name="tenantName">Name of tenant</param> /// <param name="hostpoolName">Name of Hostpool</param> /// <param name="appGroupName">Name of AppGroup</param> /// <returns></returns> public JObject DeleteAppGroup(string tenantGroupName, string deploymentURL, string accessToken, string tenantName, string hostpoolName, string appGroupName) { try { //call rest service to delete app group - july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentURL, accessToken).DeleteAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostpoolName + "/AppGroups/" + appGroupName).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { groupResult.Add("isSuccess", true); groupResult.Add("message", "App group '" + appGroupName + "' has been deleted successfully."); } else if ((int)response.StatusCode == 429) { groupResult.Add("isSuccess", false); groupResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { groupResult.Add("isSuccess", false); groupResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { groupResult.Add("isSuccess", false); groupResult.Add("message", "AppGroup '" + appGroupName + "' has not been deleted . Please try it again later."); } } } catch (Exception ex) { groupResult.Add("isSuccess", false); groupResult.Add("message", "AppGroup '" + appGroupName + "' has not been deleted." + ex.Message.ToString() + "Please try it again later."); } return(groupResult); }
/// <summary> /// Description : Generate registration key to create host /// </summary> /// <param name="deploymentUrl"></param> /// <param name="accessToken"></param> /// <param name="rdMgmtRegistrationInfo"></param> /// <returns></returns> public JObject CreateRegistrationInfo(string deploymentUrl, string accessToken, JObject rdMgmtRegistrationInfo) { try { //call rest api to generate registration key -- july code bit var content = new StringContent(JsonConvert.SerializeObject(rdMgmtRegistrationInfo), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("/RdsManagement/V1/TenantGroups/" + rdMgmtRegistrationInfo["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtRegistrationInfo["tenantName"].ToString() + "/HostPools/" + rdMgmtRegistrationInfo["hostPoolName"].ToString() + "/RegistrationInfos/", content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { if (response.StatusCode == System.Net.HttpStatusCode.Created || response.StatusCode == System.Net.HttpStatusCode.OK) { infoResult.Add("isSuccess", true); infoResult.Add("message", "Registration Key has been generated for hostpool '" + rdMgmtRegistrationInfo["hostPoolName"].ToString() + "' successfully."); } } else { if (!string.IsNullOrEmpty(strJson)) { infoResult.Add("isSuccess", false); infoResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { infoResult.Add("isSuccess", false); infoResult.Add("message", "Registration Key has not been generated. Please try again later."); } } } catch (Exception ex) { infoResult.Add("isSuccess", false); infoResult.Add("message", "Registration Key has not been generated." + ex.Message.ToString() + " Please try it later again."); } return(infoResult); }
public List <RdMgmtRoleAssignment> GetRoleAssignmentsByUser(string deploymentUrl, string accessToken, string loginUserName) { List <RdMgmtRoleAssignment> rdMgmtRoleAssignments = new List <RdMgmtRoleAssignment>(); try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("RdsManagement/V1/Rds.Authorization/roleAssignments").Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { //Deserialize the string to JSON object var jObj = (JArray)JsonConvert.DeserializeObject(strJson); if (jObj.Count > 0 && jObj.Select(x => (string)x["signInName"] == loginUserName).Count() > 0) { rdMgmtRoleAssignments = jObj.Select(item => new RdMgmtRoleAssignment { roleAssignmentId = (string)item["roleAssignmentId"], scope = (string)item["scope"], displayName = (string)item["displayName"], signInName = (string)item["signInName"], roleDefinitionName = (string)item["roleDefinitionName"], roleDefinitionId = (string)item["roleDefinitionId"], objectId = (string)item["objectId"], objectType = (string)item["objectType"] }).ToList(); } } } catch (Exception ex) { return(null); } return(rdMgmtRoleAssignments); }