Example #1
0
        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);
        }
 /// <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);
 }
        /// <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);
 }
        /// <summary>
        /// Description : Update hostpool details associated with tenant
        /// </summary>
        /// <param name="deploymenturl">RD Broker Url</param>
        /// <param name="accessToken"> Access Token</param>
        /// <param name="rdMgmtHostPool">Hostpool Class</param>
        /// <returns></returns>
        public JObject UpdateHostPool(string deploymentUrl, string accessToken, JObject rdMgmtHostPool)
        {
            try
            {
                //call rest api to update hostpool -- july code bit

                if (rdMgmtHostPool["loadBalancerType"] != null)
                {
                    rdMgmtHostPool["loadBalancerType"] = Convert.ToInt32(rdMgmtHostPool["loadBalancerType"]);
                }
                if (rdMgmtHostPool["assignmentType"] != null)
                {
                    rdMgmtHostPool["assignmentType"] = Convert.ToInt32(rdMgmtHostPool["assignmentType"]);
                }


                var content = new StringContent(JsonConvert.SerializeObject(rdMgmtHostPool), Encoding.UTF8, "application/json");
                HttpResponseMessage response = CommonBL.PatchAsync(deploymentUrl, accessToken, "/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)
                {
                    poolResult.Add("isSuccess", true);
                    poolResult.Add("message", "Hostpool '" + rdMgmtHostPool["hostPoolName"] + "' has been updated 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 updated. Please try it later again.");
                    }
                }
            }
            catch (Exception ex)
            {
                poolResult.Add("isSuccess", false);
                poolResult.Add("message", "Hostpool '" + rdMgmtHostPool["hostPoolName"].ToString() + "' has not been updated." + ex.Message.ToString() + " Please try it later again.");
            }
            return(poolResult);
        }
 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);
 }
Example #8
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);
        }
Example #9
0
 /// <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);
 }
Example #11
0
 /// <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);
 }
Example #13
0
 /// <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);
        }