當前位置: 首頁>>代碼示例>>C#>>正文


C# Models.AzureContext類代碼示例

本文整理匯總了C#中Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext的典型用法代碼示例。如果您正苦於以下問題:C# AzureContext類的具體用法?C# AzureContext怎麽用?C# AzureContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AzureContext類屬於Microsoft.Azure.Commands.Common.Authentication.Models命名空間,在下文中一共展示了AzureContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetToken

        private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
        {
            if (context.Account == null)
                throw new ArgumentException(KeyVaultProperties.Resources.ArmAccountNotFound);

            if (context.Account.Type != AzureAccount.AccountType.User &&
                context.Account.Type != AzureAccount.AccountType.ServicePrincipal)
                throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));

            if (context.Subscription != null && context.Account != null)
                TenantId = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                       .Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
                       .FirstOrDefault();

            if (string.IsNullOrWhiteSpace(TenantId) && context.Tenant != null && context.Tenant.Id != Guid.Empty)
                TenantId = context.Tenant.Id.ToString();

            if (string.IsNullOrWhiteSpace(TenantId))
                throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);

            try
            {
                var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Auto,
                    resourceIdEndpoint);

                return Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
            }
        }
開發者ID:FrankSiegemund,項目名稱:azure-powershell,代碼行數:32,代碼來源:DataServiceCredential.cs

示例2: ActiveDirectoryClient

        /// <summary>
        /// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
        /// </summary>
        /// <param name="context"></param>
        public ActiveDirectoryClient(AzureContext context)
        {
            GraphClient = AzureSession.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
                context, AzureEnvironment.Endpoint.Graph);

            GraphClient.TenantID = context.Tenant.Id.ToString();
        }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:11,代碼來源:ActiveDirectoryClient.cs

示例3: SetupTestEnvironment

 private static RMProfileClient SetupTestEnvironment(List<string> tenants, params List<string>[] subscriptionLists)
 {
     AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(DefaultAccount,
         Guid.NewGuid().ToString(), DefaultTenant.ToString());
     var subscriptionList = new Queue<List<string>>(subscriptionLists);
     var clientFactory = new MockSubscriptionClientFactory(tenants, subscriptionList);
     var mock = new MockClientFactory(new List<object>
     {
         clientFactory.GetSubscriptionClient()
     }, true);
     mock.MoqClients = true;
     AzureSession.ClientFactory = mock;
     Context = new AzureContext(new AzureSubscription()
         {
             Account = DefaultAccount,
             Environment = EnvironmentName.AzureCloud,
             Id = DefaultSubscription,
             Name = DefaultSubscriptionName
         },
         new AzureAccount() { Id = DefaultAccount, Type = AzureAccount.AccountType.User },
         AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud],
         new AzureTenant() { Domain = DefaultDomain, Id = DefaultTenant });
     var profile = new AzureRMProfile();
     profile.Context = Context;
     return new RMProfileClient(profile);
 }
開發者ID:singhkays,項目名稱:azure-powershell,代碼行數:26,代碼來源:AzureRMProfileTests.cs

示例4: AzureSqlDatabaseAdapter

 /// <summary>
 /// Constructs a database adapter
 /// </summary>
 /// <param name="profile">The current azure profile</param>
 /// <param name="subscription">The current azure subscription</param>
 public AzureSqlDatabaseAdapter(AzureContext context)
 {
     Context = context;
     _subscription = context.Subscription;
     Communicator = new AzureSqlDatabaseCommunicator(Context);
     ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Context);
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:12,代碼來源:AzureSqlDatabaseAdapter.cs

示例5: DelegatingHandlersAreCloned

        public void DelegatingHandlersAreCloned()
        {
            string userAccount = "[email protected]";
            Guid subscriptionId = Guid.NewGuid();
             AzureContext context = new AzureContext
            (
                new AzureSubscription()
                {
                    Account = userAccount,
                    Environment = "AzureCloud",
                    Id = subscriptionId,
                    Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } }
                }, 
                new AzureAccount()
                {
                    Id = userAccount,
                    Type = AzureAccount.AccountType.User,
                    Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } }
                },
                AzureEnvironment.PublicEnvironments["AzureCloud"]
            );

            AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString());
            var mockHandler = new MockDelegatingHandler();
            var factory = new ClientFactory();
            factory.AddHandler(mockHandler);
            var client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
            client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
            client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
            client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
            client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
            Assert.Equal(5, MockDelegatingHandler.cloneCount); 
        }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:33,代碼來源:ClientFactoryHandlerTests.cs

示例6: DetermineApiVersion

        /// <summary>
        /// Determines the API version.
        /// </summary>
        /// <param name="context">The azure profile.</param>
        /// <param name="providerNamespace">The provider namespace.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
        internal static Task<string> DetermineApiVersion(AzureContext context, string providerNamespace, string resourceType, CancellationToken cancellationToken, bool? pre = null, Dictionary<string, string> cmdletHeaderValues = null)
        {
            var cacheKey = ApiVersionCache.GetCacheKey(providerNamespace: providerNamespace, resourceType: resourceType);
            var apiVersions = ApiVersionCache.Instance
                .AddOrGetExisting(cacheKey: cacheKey, getFreshData: () => ApiVersionHelper.GetApiVersionsForResourceType(
                    context,
                    providerNamespace: providerNamespace,
                    resourceType: resourceType,
                    cancellationToken: cancellationToken,
                    cmdletHeaderValues: cmdletHeaderValues));

            apiVersions = apiVersions.CoalesceEnumerable().ToArray();
            var apiVersionsToSelectFrom = apiVersions;
            if (pre == null || pre  == false)
            {
                apiVersionsToSelectFrom = apiVersions
                    .Where(apiVersion => apiVersion.IsDecimal(NumberStyles.AllowDecimalPoint) || apiVersion.IsDateTime("yyyy-mm-dd", DateTimeStyles.None))
                    .ToArray();
            }

            var selectedApiVersion = apiVersionsToSelectFrom.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
            if (string.IsNullOrWhiteSpace(selectedApiVersion) && apiVersions.Any())
            {
                // fall back on pre-release APIs if they're the only ones available.
                selectedApiVersion = apiVersions.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
            }

            var result = string.IsNullOrWhiteSpace(selectedApiVersion) 
                ? Constants.DefaultApiVersion
                : selectedApiVersion;

            return Task.FromResult(result);
        }
開發者ID:rohmano,項目名稱:azure-powershell,代碼行數:41,代碼來源:ApiVersionHelper.cs

示例7: ActiveDirectoryClient

 /// <summary>
 /// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
 /// </summary>
 /// <param name="context"></param>
 public ActiveDirectoryClient(AzureContext context)
 {
     AccessTokenCredential creds = (AccessTokenCredential)AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(context, AzureEnvironment.Endpoint.Graph);
     GraphClient = AzureSession.ClientFactory.CreateCustomClient<GraphRbacManagementClient>(
         creds.TenantID,
         creds,
         context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.Graph));
 }
開發者ID:rohmano,項目名稱:azure-powershell,代碼行數:12,代碼來源:ActiveDirectoryClient.cs

示例8: ResourcesClient

        /// <summary>
        /// Creates new ResourceManagementClient
        /// </summary>
        /// <param name="context">Profile containing resources to manipulate</param>
        public ResourcesClient(AzureContext context)
            : this(
                AzureSession.ClientFactory.CreateClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager),
                new GalleryTemplatesClient(context),
                AzureSession.ClientFactory.CreateClient<AuthorizationManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
        {

        }
開發者ID:singhkays,項目名稱:azure-powershell,代碼行數:12,代碼來源:ResourceClient.cs

示例9: SqlThreatDetectionAdapter

 public SqlThreatDetectionAdapter(AzureContext context)
 {
     Context = context;
     Subscription = context.Subscription;
     ThreatDetectionCommunicator = new ThreatDetectionEndpointsCommunicator(Context);
     AzureCommunicator = new AzureEndpointsCommunicator(Context);
     AuditingAdapter = new SqlAuditAdapter(context);
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:8,代碼來源:SqlThreatDetectionAdapter.cs

示例10: SqlAuditAdapter

 public SqlAuditAdapter(AzureContext context)
 {
     Context = context;
     Subscription = context.Subscription;
     Communicator = new AuditingEndpointsCommunicator(Context);
     AzureCommunicator = new AzureEndpointsCommunicator(Context);
     IgnoreStorage = false;
 }
開發者ID:rohmano,項目名稱:azure-powershell,代碼行數:8,代碼來源:SqlAuditAdapter.cs

示例11: AzureSqlDatabaseReplicationAdapter

 /// <summary>
 /// Constructs a database adapter
 /// </summary>
 /// <param name="profile">The current azure profile</param>
 /// <param name="subscription">The current azure subscription</param>
 public AzureSqlDatabaseReplicationAdapter(AzureContext context)
 {
     Context = context;
     _subscription = context.Subscription;
     ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Context);
     DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Context);
     ServerCommunicator = new AzureSqlServerCommunicator(Context);
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:13,代碼來源:AzureSqlDatabaseReplicationAdapter.cs

示例12: DataMaskingEndpointsCommunicator

 public DataMaskingEndpointsCommunicator(AzureContext context)
 {
     Context = context;
     if (context.Subscription != Subscription)
     {
         Subscription = context.Subscription;
         SqlClient = null;
     }
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:9,代碼來源:DataMaskingEndpointsCommunicator.cs

示例13: AzureSqlDatabaseIndexRecommendationCommunicator

 /// <summary>
 /// Creates a communicator for Azure Sql Databases
 /// </summary>
 /// <param name="profile"></param>
 /// <param name="subscription"></param>
 public AzureSqlDatabaseIndexRecommendationCommunicator(AzureContext context)
 {
     Context = context;
     if (context.Subscription != Subscription)
     {
         Subscription = context.Subscription;
         SqlClient = null;
     }
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:14,代碼來源:AzureSqlDatabaseIndexRecommendationCommunicator.cs

示例14: WebServicesClient

 public WebServicesClient(AzureContext context)
 {
     this.apiClient = AzureSession.ClientFactory.
                                     CreateArmClient<APIClient>(
                                         context,
                                         AzureEnvironment.Endpoint.ResourceManager);
     this.apiClient.LongRunningOperationRetryTimeout =
             WebServicesClient.AsyncOperationPollingIntervalSeconds;
 }
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:9,代碼來源:WebServicesClient.cs

示例15: AzureSqlDatabaseBackupCommunicator

 /// <summary>
 /// Creates a communicator for Azure Sql Database backup REST endpoints.
 /// </summary>
 /// <param name="profile">Azure profile</param>
 /// <param name="subscription">Associated subscription</param>
 public AzureSqlDatabaseBackupCommunicator(AzureContext context)
 {
     Context = context;
     if (context.Subscription != Subscription)
     {
         Subscription = context.Subscription;
         SqlClient = null;
     }
 }
開發者ID:devigned,項目名稱:azure-powershell,代碼行數:14,代碼來源:AzureSqlDatabaseBackupCommunicator.cs


注:本文中的Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。