/// <summary> /// Initializes a new instance of the AutoRestDurationTestService class. /// </summary> /// <param name='baseUri'> /// Optional. The base URI of the service. /// </param> /// <param name='credentials'> /// Required. Credentials needed for the client to connect to Azure. /// </param> /// <param name='handlers'> /// Optional. The delegating handlers to add to the http client pipeline. /// </param> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> public AutoRestDurationTestService(System.Uri baseUri, Microsoft.Rest.ServiceClientCredentials credentials, params System.Net.Http.DelegatingHandler[] handlers) : this(handlers) { if (baseUri == null) { throw new System.ArgumentNullException("baseUri"); } if (credentials == null) { throw new System.ArgumentNullException("credentials"); } this.BaseUri = baseUri; this.Credentials = credentials; if (this.Credentials != null) { this.Credentials.InitializeServiceClient(this); } }
public void Execute() { _log.LogInformation($"Execute:{++_executionCount}:\r\n\t{_tenantId}\r\n\t{_clientId}\r\n\t{_secret}\r\n\t{_subscriptionId}"); //_monitoredResources.Clear(); Microsoft.Rest.ServiceClientCredentials serviceCreds = ApplicationTokenProvider.LoginSilentAsync(_tenantId, _clientId, _secret).Result; _resourceClient = new ResourceManagementClient(serviceCreds); _resourceClient.SubscriptionId = _subscriptionId; GetAccessToken(); // load prior results if collection empty if (_monitoredResources.Count < 1) { MonitoredResourcesResult result = LoadResultsFromJson("all.json"); if (result.monitoredResources != null) { _monitoredResources.AddRange(result.monitoredResources); } } SyncResources(); _log.LogInformation("Listing resource groups:"); _resourceClient.ResourceGroups.List().ToList().ForEach(rg => { _log.LogInformation(string.Format("\tName: {0}, Id: {1}", rg.Name, rg.Id)); }); CheckVmPowerStates(); CheckVmssPowerStates(); CheckKustoPowerStates(); SaveResultsToJson("running.json", new MonitoredResourcesResult(_monitoredResources.Where(x => x.CurrentlyPoweredOn == true).ToArray())); SaveResultsToJson("all.json", new MonitoredResourcesResult(_monitoredResources.ToArray())); if (_msgBuilder.Length > 0) { SendGridEmail($"{_monitoredResources.Count(x => x.CurrentlyPoweredOn == true)} running resources in your subscription", _msgBuilder.ToString()); _msgBuilder.Clear(); } }
public AnalyticsJobsRestWrapper(Microsoft.Rest.ServiceClientCredentials creds) { this.RestClient = new MSADLA.DataLakeAnalyticsJobManagementClient(creds); }
public StoreFileSystemRestWrapper(Microsoft.Rest.ServiceClientCredentials creds) { this.RestClient = new ADL.Store.DataLakeStoreFileSystemManagementClient(creds); }
public AzureDNSViewModel() { AddZoneCommand = new Command(this.AddZone); AddRecordCommand = new Command(this.AddRecord); DeleteRecordCommand = new Command(this.DeleteRecord); CommitRecordCommand = new Command(this.CommitRecord); AddRecordEntryCommand = new Command(this.AddRecordEntry); DeleteRecordEntryCommand = new Command(this.DeleteRecordEntry); CopyRecordSetCommand = new Command(this.CopyRecordSet); PasteRecordSetCommand = new Command(this.PasteRecordSet); string tenant = "Common"; try { var azureEnv = AzureEnvironment.PublicEnvironments["AzureCloud"]; var azureAccount = new AzureAccount() { Id = null, Type = AzureAccount.AccountType.User, Properties = new Dictionary <AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, tenant } } }; var azureSub = new AzureSubscription() { Account = azureAccount.Id, Environment = azureEnv.Name, Properties = new Dictionary <AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, tenant } } }; _azureContext = new AzureContext(azureSub, azureAccount, azureEnv); } catch (Exception ex) { MessageBox.Show("Failed to setup azure account credentials!"); Debug.WriteLine(ex.Message); return; } try { IAccessToken token = AzureSession.AuthenticationFactory.Authenticate(_azureContext.Account, _azureContext.Environment, tenant, null, Microsoft.Azure.Common.Authentication.ShowDialog.Always); switch (token.LoginType) { case LoginType.OrgId: Debug.WriteLine("Connecting with 'OrgId' account"); break; case LoginType.LiveId: Debug.WriteLine("Connecting with 'LiveId' account"); break; default: Debug.WriteLine("Connecting with unknown account type"); break; } //_azureContext.Subscription.Account = _azureContext.Account.Id; } catch (Exception ex) { MessageBox.Show("Failed to authenticate with Azure!"); Debug.WriteLine(ex.Message); return; } try { var token = AzureSession.AuthenticationFactory.Authenticate(_azureContext.Account, _azureContext.Environment, tenant, null, Microsoft.Azure.Common.Authentication.ShowDialog.Auto, AzureEnvironment.Endpoint.ResourceManager); _tokenCreds = new Microsoft.Rest.TokenCredentials(token.AccessToken); _subscriptionClient = new SubscriptionClient(_tokenCreds); _subscriptions = _subscriptionClient.Subscriptions.List().ToList(); if (_subscriptions?.Count >= 1) { ActiveSubscription = _subscriptions[0].SubscriptionId; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
public StoreManagementRestWrapper(string sub, Microsoft.Rest.ServiceClientCredentials creds) { this.RestClient = new DataLakeStoreAccountManagementClient(creds); this.RestClient.SubscriptionId = sub; }
public CachedKeyVaultClient(Microsoft.Rest.ServiceClientCredentials credentials, System.Net.Http.HttpClientHandler rootHandler, params System.Net.Http.DelegatingHandler[] handlers) : base(credentials, rootHandler, handlers) { }
public AzureDNSViewModel() { AddZoneCommand = new Command(this.AddZone); AddRecordCommand = new Command(this.AddRecord); DeleteRecordCommand = new Command(this.DeleteRecord); CommitRecordCommand = new Command(this.CommitRecord); AddRecordEntryCommand = new Command(this.AddRecordEntry); DeleteRecordEntryCommand = new Command(this.DeleteRecordEntry); CopyRecordSetCommand = new Command(this.CopyRecordSet); PasteRecordSetCommand = new Command(this.PasteRecordSet); string tenant = "Common"; try { var azureEnv = AzureEnvironment.PublicEnvironments["AzureCloud"]; var azureAccount = new AzureAccount() { Id = null, Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, tenant } } }; var azureSub = new AzureSubscription() { Account = azureAccount.Id, Environment = azureEnv.Name, Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, tenant }} }; _azureContext = new AzureContext(azureSub, azureAccount, azureEnv); } catch (Exception ex) { MessageBox.Show("Failed to setup azure account credentials!"); Debug.WriteLine(ex.Message); return; } try { IAccessToken token = AzureSession.AuthenticationFactory.Authenticate(_azureContext.Account, _azureContext.Environment, tenant, null, Microsoft.Azure.Common.Authentication.ShowDialog.Always); switch(token.LoginType) { case LoginType.OrgId: Debug.WriteLine("Connecting with 'OrgId' account"); break; case LoginType.LiveId: Debug.WriteLine("Connecting with 'LiveId' account"); break; default: Debug.WriteLine("Connecting with unknown account type"); break; } //_azureContext.Subscription.Account = _azureContext.Account.Id; } catch (Exception ex) { MessageBox.Show("Failed to authenticate with Azure!"); Debug.WriteLine(ex.Message); return; } try { var token = AzureSession.AuthenticationFactory.Authenticate(_azureContext.Account, _azureContext.Environment, tenant, null, Microsoft.Azure.Common.Authentication.ShowDialog.Auto, AzureEnvironment.Endpoint.ResourceManager); _tokenCreds = new Microsoft.Rest.TokenCredentials(token.AccessToken); _subscriptionClient = new SubscriptionClient(_tokenCreds); _subscriptions = _subscriptionClient.Subscriptions.List().ToList(); if (_subscriptions?.Count >= 1) { ActiveSubscription = _subscriptions[0].SubscriptionId; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
public AnalyticsAccountManagmentRestWrapper(string sub, Microsoft.Rest.ServiceClientCredentials creds) { this.RestClient = new MSADL.Analytics.DataLakeAnalyticsAccountManagementClient(creds); this.RestClient.SubscriptionId = sub; }