/// <summary> /// Description : Removes a Rds Registration key 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> /// <returns></returns> public JObject DeleteRegistrationInfo(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName) { try { //call rest api to delete registration key -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).DeleteAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/RegistrationInfos/").Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { infoResult.Add("isSuccess", true); infoResult.Add("message", "Registration Key has been deleted successully."); } 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 deleted. Please try it later again."); } } } catch (Exception ex) { infoResult.Add("isSuccess", false); infoResult.Add("message", "Registration Key has been deleted." + ex.Message.ToString() + " Please try again later."); } return(infoResult); }
public JObject RestartHost(string deploymentUrl, string accessToken, string subscriptionId, string resourceGroupName, string sessionHostName) { try { JObject vmDetails = new JObject() { new JProperty("subscriptionId", subscriptionId), new JProperty("resourceGroupName", resourceGroupName), new JProperty("vmName", sessionHostName) }; var content = new StringContent(JsonConvert.SerializeObject(vmDetails), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("subscriptions/" + subscriptionId + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Compute/virtualMachines/" + sessionHostName + "/restart?api-version=2018-06-01", content).Result; string strJson = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { hostResult.Add("isSuccess", true); hostResult.Add("message", sessionHostName + " is restarted successfully"); } else { hostResult.Add("isSuccess", false); hostResult.Add("message", CommonBL.GetErrorMessage(strJson)); } } catch (Exception ex) { hostResult.Add("isSuccess", false); hostResult.Add("message", ex.Message.ToString()); } return(hostResult); }
public HttpResponseMessage GetAzureVMList(string deploymentUrl, string accessToken, string subscriptionId) { try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("subscriptions/" + subscriptionId + "/providers/Microsoft.Compute/virtualMachines?api-version=2018-04-01").Result; return(response); } catch { return(null); } }
/// <summary> /// Description - Gets a list of AppGroups within a Tenant and Hostpool /// </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="isAppGroupNameOnly">used to get Only App Group Name</param> /// // old parameters -- , bool isAppGroupNameOnly,bool isAll, int pageSize, string sortField, bool isDescending, int initialSkip, string lastEntry /// <returns></returns> public HttpResponseMessage GetAppGroupsList(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName) { try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups").Result; return(response); } catch { return(null); } }
/// <summary> /// Description - Gets a Rds HostPool associated with the Tenant 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> /// <returns></returns> public HttpResponseMessage GetHostPoolDetails(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName) { try { //call rest api to get host pool details -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName).Result; return(response); } catch { return(null); } }
/// <summary> /// Description-Gets a list of Rds tenants. /// </summary> /// <param name="deploymentUrl">RD Broker Url</param> /// <param name="accessToken"> Access token</param> /// //old parameters for pagination - int pageSize, string sortField, bool isDescending, int initialSkip, string lastEntry /// <returns></returns> public HttpResponseMessage GetTenantList(string tenantGroupName, string deploymenturl, string accessToken) { try { //call rest api to get all tenants HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymenturl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants").Result; return(response); } catch (Exception ex) { return(null); } }
/// <summary> /// Description- Creates a new Rds HostPool within a Tenant specified in the Rds context. /// </summary> /// <param name="deploymentUrl">RD Broker Url</param> /// <param name="accessToken">Access Token</param> /// <param name="rdMgmtHostPool">Hostpool class</param> /// <returns></returns> public JObject CreateHostPool(string deploymentUrl, string accessToken, JObject rdMgmtHostPool) { try { if (Convert.ToBoolean(rdMgmtHostPool["persistent"]) == false) { rdMgmtHostPool.Add("loadBalancerType", Convert.ToInt32(Enums.loadBalancer.BreadthFirst)); } else { rdMgmtHostPool.Add("loadBalancerType", Convert.ToInt32(Enums.loadBalancer.Persistent)); } //call rest api to create host pool -- july code bit var content = new StringContent(JsonConvert.SerializeObject(rdMgmtHostPool), Encoding.UTF8, "application/json"); HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("/RdsManagement/V1/TenantGroups/" + rdMgmtHostPool["tenantGroupName"].ToString() + "/Tenants/" + rdMgmtHostPool["tenantName"].ToString() + "/HostPools/" + rdMgmtHostPool["hostPoolName"].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) { poolResult.Add("isSuccess", true); poolResult.Add("message", "Hostpool '" + rdMgmtHostPool["hostPoolName"].ToString() + "' has been created successfully."); } } else if ((int)response.StatusCode == 429) { poolResult.Add("isSuccess", false); poolResult.Add("message", strJson + " Please try again later."); } else { if (!string.IsNullOrEmpty(strJson)) { poolResult.Add("isSuccess", false); poolResult.Add("message", CommonBL.GetErrorMessage(strJson)); } else { poolResult.Add("isSuccess", false); poolResult.Add("message", "Hostpool '" + rdMgmtHostPool["hostPoolName"].ToString() + "' has not been created. Please try again later. "); } } } catch (Exception ex) { poolResult.Add("isSuccess", false); poolResult.Add("message", "Hostpool '" + rdMgmtHostPool["hostPoolName"].ToString() + "' has not been created." + ex.Message.ToString() + " Please try again later. "); } return(poolResult); }
/// <summary> /// Description - Create a RemoteApp 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="rdMgmtRemoteApp">Remote App class</param> /// <returns></returns> public JObject CreateRemoteApp(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.InitializeHttpClient(deploymentUrl, accessToken).PostAsync("/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 || response.StatusCode == HttpStatusCode.Created) { appResult.Add("isSuccess", true); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has been published 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); ErrorResult objerrror = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResult>(strJson); if (objerrror.error.message == "RemoteAppAlreadyExists") { string errMessage = "'" + rdMgmtRemoteApp["remoteAppName"].ToString() + "'" + " is already published to " + "'" + rdMgmtRemoteApp["appGroupName"].ToString() + "'" + " and cannot be republished."; appResult.Add("message", errMessage); } else { appResult.Add("message", CommonBL.GetErrorMessage(strJson)); } } else { appResult.Add("isSuccess", false); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has not been published. Please try it later again."); } } } catch (Exception ex) { appResult.Add("isSuccess", false); appResult.Add("message", "Remote app '" + rdMgmtRemoteApp["remoteAppName"].ToString() + "' has not been published." + ex.Message.ToString() + " Please try it later again."); } return(appResult); }
// string tenantGroup = Constants.tenantGroupName; /// <summary> /// Description : Gets a user details from 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="userPrincipalName"> Login ID of AAD User</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 HttpResponseMessage GetUserDetails(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName, string appGroupName, string userPrincipalName) { //RdMgmtUser rdMgmtUser = new RdMgmtUser(); try { //call rest api to get app group user details -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/AssignedUsers/" + userPrincipalName).Result; return(response); } catch { return(null); } }
public async Task <List <JObject> > GetAzureVMs(string deploymentUrl, string accessToken, string subscriptionId) { string nextLink = ""; HttpResponseMessage responseNext = null; try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("subscriptions/" + subscriptionId + "/providers/Microsoft.Compute/virtualMachines?api-version=2018-04-01").Result; var azureData = response.Content.ReadAsStringAsync().Result; var arrAzure1 = (JObject)JsonConvert.DeserializeObject(azureData); var arrAzure = arrAzure1["value"]; var finalVmList = new List <JObject>(); var AzureResult = new List <JObject>(); nextLink = arrAzure1["nextLink"] != null ? arrAzure1["nextLink"].ToString() : null; AzureResult = ((JArray)arrAzure).Select(item => new JObject() { new JProperty("vmName", item["name"]), new JProperty("subscriptionId", item["id"] == null ? null: item["id"].ToString().Split('/')[2]), new JProperty("resourceGroupName", item["id"] == null ? null:item["id"].ToString().Split('/')[4]), }).ToList(); finalVmList.AddRange(AzureResult); while (!string.IsNullOrEmpty(nextLink)) { using (HttpClient client = new HttpClient()) { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, nextLink); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); responseNext = await client.SendAsync(request); // clientr.SendAsync(requestr); var azureData1 = responseNext.Content.ReadAsStringAsync().Result; var arrAzureNext = (JObject)JsonConvert.DeserializeObject(azureData1); var arrAzureData = arrAzureNext["value"]; nextLink = arrAzureNext["nextLink"] != null ? arrAzureNext["nextLink"].ToString():null; AzureResult = ((JArray)arrAzureData).Select(item => new JObject() { new JProperty("vmName", item["name"]), new JProperty("subscriptionId", item["id"] == null ? null: item["id"].ToString().Split('/')[2]), new JProperty("resourceGroupName", item["id"] == null ? null:item["id"].ToString().Split('/')[4]), }).ToList(); finalVmList.AddRange(AzureResult); } } return(finalVmList); } catch { return(null); } }
/// <summary> /// Description - Gets a list of RemoteApps within a TenantGroup, 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 App Group</param> /// <param name="remoteAppName">Name of Remote App</param> /// <param name="isRemoteAppNameOnly">To get Remote app Name only</param> /// //old parameters -- bool isRemoteAppNameOnly,bool isAll, int pageSize, string sortField, bool isDescending, int initialSkip, string lastEntry /// <returns></returns> public HttpResponseMessage GetRemoteAppList(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName, string appGroupName) { try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/RemoteApps").Result; return(response); //api call included pagination // response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/RemoteApps?PageSize=" + pageSize + "&LastEntry=" + lastEntry + "&SortField=" + sortField + "&IsDescending=" + isDescending + "&InitialSkip=" + initialSkip).Result; } catch { return(null); } }
public Task <HttpResponseMessage> GetRoleAssignments(string deploymentUrl, string accessToken, string upn) { try { HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/Rds.Authorization/roleAssignments?upn=" + upn).Result;//.Result; //.ConfigureAwait(true).GetAwaiter().GetResult(); return(Task.FromResult(response)); } catch (Exception ex) { HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.RequestTimeout) { Content = new StringContent(ex.InnerException.Message.ToString(), System.Text.Encoding.UTF8, "application/json") }; return(Task.FromResult(response)); } }
/// <summary> /// Description-Gets a list of StartMenuApps within a Teanat and Hostpool. /// </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> /// old parameters -- int pageSize, string sortField, bool isDescending, int initialSkip, string lastEntry /// <returns></returns> public HttpResponseMessage GetStartMenuAppsList(string tenantGroupName, string deploymentUrl, string accessToken, string tenantName, string hostPoolName, string appGroupName) { List <RdMgmtStartMenuApp> rdMgmtStartMenuApps = new List <RdMgmtStartMenuApp>(); try { //call rest api to get all startmenu apps in app group -- july code bit HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/StartMenuApps").Result; //folllowing api call is included pagination //HttpResponseMessage response = CommonBL.InitializeHttpClient(deploymentUrl, accessToken).GetAsync("/RdsManagement/V1/TenantGroups/" + tenantGroupName + "/Tenants/" + tenantName + "/HostPools/" + hostPoolName + "/AppGroups/" + appGroupName + "/StartMenuApps?PageSize=" + pageSize + "&LastEntry=" + lastEntry + "&SortField=" + sortField + "&IsDescending=" + isDescending + "&InitialSkip=" + initialSkip).Result; return(response); } catch { return(null); } }
/// <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); }
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); }