Пример #1
0
        public ManagementController(ManagementControllerParameters parameters)
        {
            _parameters = parameters;

            // To authenticate against the Microsoft Azure service management API we require management certificate
            // load this from a publish settings file and later use it with the Service Management Libraries
            var credential = GetSubscriptionCloudCredentials(parameters.PublishSettingsFilePath);

            _webSiteManagementClient = CloudContext.Clients.CreateWebSiteManagementClient(credential);

            _webSpaceDetails = CreateWebSpaceDetails(_parameters.GeoRegion);
        }
Пример #2
0
        //***********************************************************************************************
        // The Microsoft Azure Management Libraries are intended for developers who want to automate 
        // the management, provisioning, deprovisioning and test of cloud infrastructure with ease.            
        // These services support Microsoft Azure Virtual Machines, Cloud Services, Storage, Virtual Networks, 
        // Web Sites and core data center infrastructure management. For more information on the Management
        // Libraries for .NET, see https://msdn.microsoft.com/en-us/library/azure/dn722415.aspx. 
        //
        // If you don't have a Microsoft Azure subscription you can get a FREE trial account here:
        // http://go.microsoft.com/fwlink/?LinkId=330212
        //
        // This sample demonstates the following scenarios:
        //  1. Creating a Web App
        //  2. Listing all Web Apps
        //  3. Configuring a Web App
        //  4. Publishing a Web App using Git
        //  5. Launching a Web App in a browser
        //  6. Upgrading a Web App
        //  7. Deleting a Web App
        //
        // TODO: Perform the following steps before running the sample 
        //  1. Download your *.publishsettings file from the Microsoft Azure management portal and save to
        //      to your local dive http://go.microsoft.com/fwlink/?LinkID=276844
        //  2. Set the PublishSettingsFilePath
        //  3. Install git (e.g. http://msysgit.github.io/) and add the directory to the PATH variable 
        //  4. Run
        //***********************************************************************************************

        static void Main(string[] args)
        {
            var webSiteParameters = new ManagementControllerParameters
            {
                PublishSettingsFilePath = @"C:\Your.publishsettings",
                WebSiteName = string.Format("MgmtLibWebSiteDemo{0}", DateTime.Now.Ticks),
                GeoRegion = GeoRegionNames.WestUS,
                UpgradePlan = WebSitePlans.Free,
                // WorkerSize and NumberOfWorkers are only used in Standard mode 
                // Depending on your subscription type certain capacity restrictions may apply
                // UpgradePlan = WebSitePlans.Standard,
                // WorkerSize = WorkerSizeOptions.Small,
                // NumberOfWorkers = 1
            };

            if (!VerifyConfiguration(webSiteParameters))
            {
                Console.ReadLine();
                return;
            }

            try
            {
                Task.WaitAll(SetupAndTearDownWebsite(webSiteParameters));
            }
            catch (WebSiteCloudException cloudException)
            {
                Console.WriteLine(cloudException.ErrorMessage);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            Console.WriteLine("Done");
            Console.ReadLine();
        }
Пример #3
0
 private static bool VerifyConfiguration(ManagementControllerParameters serviceParameters)
 {
     bool configOK = true;
     if (!File.Exists(serviceParameters.PublishSettingsFilePath))
     {
         configOK = false;
         Console.WriteLine("Please download your .publishsettings file and specify the location in the Main method.");
     }
     return configOK;
 }
Пример #4
0
        private static async Task SetupAndTearDownWebsite(ManagementControllerParameters managementControllerParameters)
        {
            using (ManagementController controller = new ManagementController(managementControllerParameters))
            {

                Console.WriteLine("1. Create WebSite named {0} in GeoRegion {1}", managementControllerParameters.WebSiteName, managementControllerParameters.GeoRegion);
                ConsoleContinuePrompt("CREATE WebSite");

                await controller.CreateWebSite();

                Console.WriteLine("...Complete");
                Console.WriteLine("2. List WebSites");
                ConsoleContinuePrompt("LIST WebSites", false);

                LogWebsites(controller.GetWebSites());

                Console.WriteLine("...Complete");
                Console.WriteLine("3. Configure WebSite");
                ConsoleContinuePrompt("CONFIGURE WebSite");

                await controller.ConfigureWebSite();

                Console.WriteLine("...Complete");
                Console.WriteLine("4. Publish WebSite");
                ConsoleContinuePrompt("PUBLISH WebSite", false);

                await controller.PublishWebSite();

                var webSiteUrl = @"http://" + managementControllerParameters.WebSiteName + ".azurewebsites.net";
                Console.WriteLine("...git publishing to {0} in progress. Site will be ready when git commands executed in opened command window", webSiteUrl);
                Console.WriteLine("5. Open WebSite in browser");
                ConsoleContinuePrompt("OPEN in browser", false);

                Process.Start(webSiteUrl);

                Console.WriteLine("...Complete");
                Console.WriteLine("6. Upgrade WebSite");
                ConsoleContinuePrompt("UPGRADE WebSite");

                await controller.UpgradeWebSite();

                Console.WriteLine("...Complete");
                Console.WriteLine("7. Delete WebSite");
                ConsoleContinuePrompt("DELETE WebSite");

                await controller.TearDownWebSite();
            }
        }