示例#1
0
            public IAzure GetSdkClient()
            {
                if (!File.Exists(CLI.fileName))
                {
                    CLI.CreateServicePrincipalFile();
                }

                var credentials = SdkContext.AzureCredentialsFactory.FromFile(CLI.fileName);

                return(Azure
                       .Configure()
                       .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                       .Authenticate(credentials)
                       .WithDefaultSubscription());
            }
示例#2
0
            public async Task CreateWebApp(string regionName = "southcentralus")
            {
                var appName = Guid.NewGuid().ToString();
                var nm      = string.Format($"aspnetcoreapp{appName}");

                Console.WriteLine($"Creating web app {nm}");

                try
                {
                    var webApp = await GetSdkClient()
                                 .WebApps
                                 .Define(nm)
                                 .WithRegion(
                        Region.Create(regionName)
                        )
                                 .WithNewResourceGroup(nm)
                                 .WithNewWindowsPlan(pricingTier: PricingTier.BasicB1)
                                 .CreateAsync();

                    Console.WriteLine($"Created web app {nm}");

                    GroupName  = nm;
                    AppName    = nm;
                    RegionName = regionName;

                    // run dotnet publish on application
                    ShellHelper.Bash($"dotnet publish {AppPath} -c Release -o {AppPath}/publish");
                    //zip publish folder
                    var zipFile = ZipContents();
                    // Push to WebApp
                    CLI.UploadFiles(zipFile, GroupName, AppName);
                    // browse to site
                    CLI.BrowseSite(GroupName, AppName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error creating web app {nm} - " + ex.Message);
                    throw ex; // throwing so caller can handle
                }
            }