コード例 #1
0
ファイル: Program.cs プロジェクト: mkasek/CodeMash2015-1
        private static async Task DoWork()
        {
            //var logAction = new Action<string>(t => File.AppendAllText(@"c:\temp\maml.log", t));
            //CloudContext.Configuration.Tracing.AddTracingInterceptor(new MyTraceInterceptor(logAction));


            // Step 1 - Authenticate
            string token = await GetAuthorizationHeader();
            TokenCloudCredentials tokenCloudCredentials = new TokenCloudCredentials(token);

            // Step 2 - Get a specific Azure subscription
            var subscription = await GetSubscription(tokenCloudCredentials, "MVP");
            tokenCloudCredentials = new TokenCloudCredentials(subscription.SubscriptionId, tokenCloudCredentials.Token);

            // Step 3 - Create a storage account
            var storageAccountName = await CreateStorageAccount(tokenCloudCredentials);

            // Step 4 - Create a web site
            var webSiteResponse = await CreateWebSite(tokenCloudCredentials);

            // Step 5 - Clean up
            Console.WriteLine("Time to clean up! Press any key to delete all previously created resources.");
            Console.ReadLine();

            var response = await RemoveStorageAccount(tokenCloudCredentials, storageAccountName);
            var deleteSiteResponse = await RemoveWebSite(tokenCloudCredentials, webSiteResponse.WebSite);

            Console.WriteLine("All done!");
            Console.ReadLine();
        }
コード例 #2
0
        public Program(ScheduledWebJobCreatorParameters parms)
        {
            // auth
            _credential = TokenCredentialHelper<MyPersonalConfiguration>.GetCredentials(
                new MyPersonalConfiguration(parms),
                parms.subscriptionId);

            // create the clients needed
            _cloudServiceManagementClient = CloudContext.Clients.CreateCloudServiceManagementClient(_credential);
            _webSiteMgmtClient = CloudContext.Clients.CreateWebSiteManagementClient(_credential);
            _schedulerMgmtClient = CloudContext.Clients.CreateSchedulerManagementClient(_credential);
        }
コード例 #3
0
        private async Task<string> GenerateResourceGroupName(string token, Repository repo, SubscriptionInfo[] subscriptions)
        {
            if (!string.IsNullOrEmpty(repo.RepositoryName))
            {
                bool isAvailable = false;
                var creds = new TokenCloudCredentials(subscriptions.First().subscriptionId, token);
                var rdfeBaseUri = new Uri(Utils.GetRDFEUrl(Request.RequestUri.Host));

                using (var webSiteMgmtClient = CloudContext.Clients.CreateWebSiteManagementClient(creds, rdfeBaseUri))
                {
                    // Make 3 attempts to get a random name (based on the repo name)
                    for (int i = 0; i < 3; i++)
                    {
                        string resourceGroupName = GenerateRandomResourceGroupName(repo.RepositoryName);
                        isAvailable = await IsSiteNameAvailable(webSiteMgmtClient, resourceGroupName);

                        if (isAvailable)
                        {
                            return resourceGroupName;
                        }
                    }
                }
            }

            return null;
        }
コード例 #4
0
 public void TestClientInitialization()
 {
     var tokenCredentials = new TokenCloudCredentials("123", "abc");
     var fakeClient = new WebSiteManagementClient(tokenCredentials);
     Assert.IsNotNull(fakeClient);
 }
コード例 #5
0
 void InitializeClients()
 {
     var rdfeToken = new TokenCloudCredentials(this.SubscriptionId, this.RdfeBearerToken);
     _computeClient = new Lazy<ComputeManagementClient>(() => new ComputeManagementClient(rdfeToken));
     _storageClient = new Lazy<StorageManagementClient>(() => new StorageManagementClient(rdfeToken));
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: JamborYao/basic
        public async static void CreateResources(
  TokenCloudCredentials credential)
        {

            Console.WriteLine(
              "Creating the storage account. This may take a few minutes...");
            var stResult =
              await CreateStorageAccount(credential);
            Console.WriteLine(stResult);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: JamborYao/basic
 public async static void CreateVM(TokenCloudCredentials credential)
 {
     Console.WriteLine("creating...");
     var stResult = await CreateVirtualMachine(credential);
     Console.WriteLine(stResult);
 }
コード例 #8
0
 public AzureActiveDirectoryHelper(AzureActiveDirectoryConfig configuration)
 {
     var token = GetAuthorizationHeader(configuration);
     var cred = new TokenCloudCredentials(configuration.azureSubscriptionID, token);
     client = new WebSiteManagementClient(cred, APIENDPOINT);
 }