Beispiel #1
0
        public async Task <IActionResult> MoveInstallation([FromBody] InstJsonDocument content)
        {
            var subscription = await cc.GetSubscription(content.subscriptionId);

            var client = await cc.GetClient("1"); // Client is not part of the Json document

            HttpResponseMessage SDDResponse = null;

            var installation = new Installation(content.installation.name, "20.52.46.188:3389", subscription, client, content.installation.state);

            try
            {
                await cc.CreateInstallationAsync(installation);
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            try
            {
                SDDResponse = await pc.MoveInstallation(content);
            }
            catch (Exception) when(!SDDResponse.IsSuccessStatusCode)
            {
                await cc.DeleteInstallation(installation);

                return(BadRequest("{\"status\": 500, \"message\": \"Error.\"}"));
            }

            string      body   = SDDResponse.Content.ReadAsStringAsync().Result;
            SDDResponse sddres = Newtonsoft.Json.JsonConvert.DeserializeObject <SDDResponse>(body);

            return(Ok("{\"status\": 200, \"message\": \"Success.\", \"installation_status\": \"" + sddres.installation_status + "\"}"));
        }
Beispiel #2
0
        public async Task <IActionResult> stopInstallation([FromQuery] string name)
        {
            try
            {
                HttpResponseMessage res = await pc.StopInstallation(name);

                string      body   = res.Content.ReadAsStringAsync().Result;
                SDDResponse sddres = Newtonsoft.Json.JsonConvert.DeserializeObject <SDDResponse>(body);

                if (res.IsSuccessStatusCode)
                {
                    bool success = await cc.StopInstallation(name);

                    if (success)
                    {
                        return(Ok("{\"status\": 200, \"message\": \"Success.\", \"installation_status\": \"" + sddres.installation_status + "\"}"));
                    }
                    else
                    {
                        return(BadRequest("{\"status\": 400, \"message\": \"Failed to find installation.\", \"installation_status\": \"STATUS_STOP_FAILED\"}"));
                    }
                }
                else
                {
                    return(BadRequest("{\"status\": 400, \"message\": \"Failed to stop installation.\", \"installation_status\": \"" + sddres.installation_status + "\"}"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.StackTrace));
            }
        }