Ejemplo n.º 1
0
        public async Task <SharingUrl> GetSharing(UserCreateDto user, string enviro)
        {
            //SkytapDataSharingModel skytapDataSharingModel;
            SharingUrl sharingUrl = new SharingUrl();

            using (var httpClient = new HttpClient())
            {
                var authString = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{user.Email}:{user.Password}"));
                httpClient.DefaultRequestHeaders.Clear();
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authString);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                using (var response = await httpClient.GetAsync($"https://cloud.skytap.com/configurations/{enviro}/publish_sets.json"))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    var list = JsonConvert.DeserializeObject <List <SkytapDataSharingModel> >(apiResponse);

                    foreach (var sha in list)
                    {
                        sharingUrl.id = sha.id;
                        Console.WriteLine("VM SHARING : " + sharingUrl.id);
                        foreach (var lis in sha.vms)
                        {
                            sharingUrl.url = lis.desktop_url;
                            break;
                        }
                        break;
                    }
                }
            }
            return(sharingUrl);
        }
Ejemplo n.º 2
0
        public async Task <string> UserSignIn(UserCreateDto user)
        {
            //SkytapModelToken skytapModelToken = await GetTokenDb(user.Email);
            user.Email = user.Email + "addvals";
            user.Login = user.Email;

            try
            {
                /* récupère l'enviro si il existe, le supprime et en crée un nouveau */

                EnviroVmUrl enviroEtVm1 = await GetEnviroSkytap(user);


                await DeleteEnviroSkytap(user, enviroEtVm1.enviro);


                SkytapDataEnviroModel skytapDataEnviroModel = await CreateEnviroSkytap(user);


                Console.WriteLine("GET/DELETE/CREATE");
            }
            catch (System.Exception)
            {
                /* création d'environnement */
                SkytapDataEnviroModel skytapDataEnviroModel = await CreateEnviroSkytap(user);
            }

            /* récupère les informations de l'environnement */
            EnviroVmUrl enviroVmUrl = await GetEnviroSkytap(user);

            /* arret automatique (BETA) */
            await shutdown_on_idle(user, enviroVmUrl.enviro);

            /* Lancement de la machine */
            //Console.WriteLine("/UpdateStatsSkytap");
            await UpdateStatsSkytap(user, enviroVmUrl.enviro);

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("USER : "******"TOKEN : " + skytapModelToken.api_token);
            Console.WriteLine("ENVIRO : " + enviroVmUrl.enviro);
            Console.WriteLine("VM : " + enviroVmUrl.vm);

            /* Création de la machine partagé */
            string ok = await CreateSharingSkytap(user, enviroVmUrl.enviro);

            /* Récupère l'URL de la machine partagé */
            SharingUrl sharingUrl = await GetSharing(user, enviroVmUrl.enviro);

            /* récupère les informations de l'environnement */
            EnviroVmUrl urlFinal = await GetEnviroSkytap(user);

            /* Maj des access de la machine partagé*/
            await UpdateAccesSharingSkytap(user, enviroVmUrl.enviro, enviroVmUrl.vm, sharingUrl.id);

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("URL : " + urlFinal.url);
            Console.WriteLine("-----------------------------------------");

            return(urlFinal.url);

            // return Ok();
        }