/// <summary>
        /// Description : Removes a Rds SessionHost associated with the Tenant and HostPool specified in the Rds context.
        /// </summary>
        /// <param name="tenantName">Name of Tenant</param>
        /// <param name="hostPoolName">Name of hostpool</param>
        /// <param name="sessionHostName">Name of Session Host</param>
        /// <param name="refresh_token">refresh token to get access token</param>
        /// <returns></returns>
        public IHttpActionResult DeleteSessionHost([FromUri] string tenantGroup, string tenantName, string hostPoolName, string sessionHostName, string refresh_token)
        {
            //get deployment url
            deploymentUrl = configurations.rdBrokerUrl;
            SessionHostResult sessionHostResult = new SessionHostResult();

            try
            {
                if (!string.IsNullOrEmpty(refresh_token))
                {
                    string accessToken = "";
                    //get token value
                    accessToken = common.GetTokenValue(refresh_token);
                    if (!string.IsNullOrEmpty(accessToken) && accessToken.ToString().ToLower() != invalidToken && accessToken.ToString().ToLower() != invalidCode)
                    {
                        sessionHostResult = sessionHostBL.DeletesessionHost(deploymentUrl, accessToken, tenantGroup, tenantName, hostPoolName, sessionHostName);
                    }
                    else
                    {
                        sessionHostResult.message   = Constants.invalidToken;
                        sessionHostResult.isSuccess = false;
                    }
                }
            }
            catch (Exception ex)
            {
                sessionHostResult.message   = "Session Host '" + sessionHostName + "' has not neen deleted." + ex.Message.ToString() + " Please try it later again.";
                sessionHostResult.isSuccess = false;
            }
            return(Ok(sessionHostResult));
        }
示例#2
0
        /// <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);
        }