Ejemplo n.º 1
0
        public override async Task <Task> ProcessInScope(IServiceProvider serviceProvider)
        {
            Console.WriteLine("Processing starts here");

            _context = serviceProvider.GetService <HavokContext>();
            Havok item = _context.Havoks.First();

            if (item.resourceGroupName != null)
            {
                AzureAppService apps = await GetAzureAppService();

                if (apps.properties.numberOfWorkers > 1)
                {
                    item.isScaledOut = true;
                }
                else
                {
                    item.isScaledOut = false;
                }
                _context.Entry(item).State = EntityState.Modified;
                _context.SaveChanges();
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public override async Task <Task> ProcessInScope(IServiceProvider serviceProvider)
        {
            Console.WriteLine("Processing starts here");

            _env = serviceProvider.GetService <IHostingEnvironment>();


            FileProcessor fp = new FileProcessor(_env);

            Havok item = JsonConvert.DeserializeObject <Havok>(fp.LoadJsonFromAppFolder("\\", "havok.json"));


            if (item.resourceGroupName != null)
            {
                AzureAppService apps = await GetAzureAppService();

                if (apps.properties.numberOfWorkers > 1)
                {
                    item.isScaledOut = true;
                }
                else
                {
                    item.isScaledOut = false;
                }
                string json = JsonConvert.SerializeObject(item);
                fp.SaveJsonToAppFolder("\\", "havok.json", json);
            }

            return(Task.CompletedTask);
        }
        private async void SignIntoAppService()
        {
            if (await AzureAppService.SignIn(TokenTwo))
            {
                AccountName.Text = await MicrosoftGraph.GetAccountDetails(TokenOne, "displayName");

                ApplicationData.Current.LocalSettings.Values.Remove(StoredNameKey);
                ApplicationData.Current.LocalSettings.Values[StoredNameKey] = AccountName.Text;

                using (var imageStream = await MicrosoftGraph.GetAccountPicture(TokenOne))
                {
                    using (var randomStream = imageStream.AsRandomAccessStream())
                    {
                        BitmapImage image = new BitmapImage();
                        await image.SetSourceAsync(randomStream);

                        ImageBrush imageBrush = new ImageBrush
                        {
                            ImageSource = image
                        };
                        AccountImage.Fill              = imageBrush;
                        SignInListViewItem.Visibility  = Visibility.Collapsed;
                        AccountListViewItem.Visibility = Visibility.Visible;
                    }
                }

                ApplicationData.Current.LocalSettings.Values.Remove(StoredEmailKey);
                ApplicationData.Current.LocalSettings.Values[StoredEmailKey] = await MicrosoftGraph.GetAccountDetails(TokenOne, "userPrincipalName");

                using (var imageStream = await MicrosoftGraph.GetAccountPicture(TokenOne))
                {
                    using (var randomStream = imageStream.AsRandomAccessStream())
                    {
                        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(randomStream);

                        SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                        StorageFile file_Save = await ApplicationData.Current.LocalFolder.CreateFileAsync("ProfilePicture.jpg", CreationCollisionOption.ReplaceExisting);

                        BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, await file_Save.OpenAsync(FileAccessMode.ReadWrite));

                        encoder.SetSoftwareBitmap(softwareBitmap);
                        await encoder.FlushAsync();
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        public static async Task <bool> SignIntoAppService()
        {
            provider = await GetProvider();

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebTokenRequest       webTokenRequest       = new WebTokenRequest(provider, LiveScope, AccountClientId);
            WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest, account);

            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                if (await AzureAppService.SignIn(webTokenRequestResult.ResponseData[0].Token))
                {
                    return(true);
                }
            }
            return(false);
        }
        private void PrepareResource(AzureAppService resource)
        {
            Init();
            PricingTier tier = PricingTier.FreeF1;

            switch (resource.PerformanceTier)
            {
            case "FreeF1":
                tier = PricingTier.FreeF1;
                break;

            case "BasicB1":
                tier = PricingTier.BasicB1;
                break;

            case "BasicB2":
                tier = PricingTier.BasicB2;
                break;

            case "BasicB3":
                tier = PricingTier.BasicB3;
                break;

            case "PremiumP1":
                tier = PricingTier.PremiumP1;
                break;

            case "PremiumP2":
                tier = PricingTier.PremiumP2;
                break;

            case "PremiumP3":
                tier = PricingTier.PremiumP3;
                break;

            case "SharedD1":
                tier = PricingTier.SharedD1;
                break;

            case "StandardS1":
                tier = PricingTier.StandardS1;
                break;

            case "StandardS2":
                tier = PricingTier.StandardS2;
                break;

            case "StandardS3":
                tier = PricingTier.StandardS3;
                break;
            }
            Console.WriteLine("Making app service: " + resource.Name);
            var app = _azure.WebApps
                      .Define(Guid.NewGuid().ToString("N").Substring(0, 8))
                      .WithRegion(ConfigProvider.GetValue("AzureRegion"))
                      .WithExistingResourceGroup(_resourceGroup.Name)
                      .WithNewWindowsPlan(tier)
                      .Create();

            PreparedResources.Add(resource);
            Console.WriteLine("Done: " + resource.Name);


            _webAppList.Add(resource, app);
        }