コード例 #1
0
        /// <summary>
        /// Process the request using a temporary connection context.
        /// </summary>
        /// <param name="databaseName">The name of the database to remove</param>
        private void ProcessWithServerName(string databaseName)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                WindowsAzureSubscription subscription = WindowsAzureProfile.Instance.CurrentSubscription;

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                // Remove the database with the specified name
                context.RemoveDatabase(databaseName);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
コード例 #2
0
        private void ProcessWithContext(IServerDataServiceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", "The ServerDataServiceContext cannot be null.");
            }

            try
            {
                if (this.ServiceObjectiveName != null)
                {
                    // Retrieve the service objective with the specified name
                    this.WriteObject(context.GetServiceObjective(this.ServiceObjectiveName));
                }
                else if (this.ServiceObjective != null)
                {
                    // Retrieve the latest service objective with the specified service objective
                    this.WriteObject(context.GetServiceObjective(this.ServiceObjective));
                }
                else
                {
                    // No name specified, retrieve all service objectives in the server
                    this.WriteObject(context.GetServiceObjectives(), true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    context.ClientRequestId,
                    ex);
            }
        }
コード例 #3
0
 /// <summary>
 /// Process the request using the provided connection context
 /// </summary>
 /// <param name="context"></param>
 private void ProcessWithContext(IServerDataServiceContext context)
 {
     try
     {
         if (this.DatabaseName != null)
         {
             // Retrieve the operations with the specified database name
             this.WriteObject(context.GetDatabaseOperations(this.DatabaseName), true);
         }
         else if (this.Database != null)
         {
             // Retrieve the operations with the database name specified by the database object
             this.WriteObject(context.GetDatabaseOperations(this.Database.Name), true);
         }
         else if (this.OperationGuid != Guid.Empty)
         {
             // Retrieve the operation with the operation Guid
             this.WriteObject(context.GetDatabaseOperation(this.OperationGuid), true);
         }
         else
         {
             // No name specified, retrieve all database's operations in the server
             this.WriteObject(context.GetDatabasesOperations(), true);
         }
     }
     catch (Exception ex)
     {
         SqlDatabaseExceptionHandler.WriteErrorDetails(
             this,
             context.ClientRequestId,
             ex);
     }
 }
コード例 #4
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Obtain the quota name from the given parameters.
            string quotaName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("QuotaName"))
            {
                quotaName = this.QuotaName;
            }

            try
            {
                if (!string.IsNullOrEmpty(quotaName))
                {
                    // Retrieve the quota with the specified name
                    this.WriteObject(this.ConnectionContext.GetQuota(quotaName));
                }
                else
                {
                    // No name specified, retrieve all quotas in the server
                    this.WriteObject(this.ConnectionContext.GetQuotas(), true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #5
0
        /// <summary>
        /// process the request using the connection context.
        /// </summary>
        /// <param name="databaseName">the name of the database to alter</param>
        /// <param name="maxSizeGb">the new maximum size for the database</param>
        /// <param name="edition">the new edition for the database</param>
        private void ProcessWithConnectionContext(string databaseName, int?maxSizeGb, DatabaseEdition?edition)
        {
            try
            {
                // Update the database with the specified name
                Database database = this.ConnectionContext.UpdateDatabase(
                    databaseName,
                    this.NewDatabaseName,
                    maxSizeGb,
                    edition,
                    this.ServiceObjective);

                // If PassThru was specified, write back the updated object to the pipeline
                if (this.PassThru.IsPresent)
                {
                    this.WriteObject(database);
                }

                if (this.ConnectionContext.GetType() == typeof(ServerDataServiceCertAuth))
                {
                    if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
                    {
                        this.Database.CopyFields(database);
                    }
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Process the record with the provided server name
        /// </summary>
        /// <param name="databaseName">The name of the database to retrieve</param>
        private void ProcessWithServerName(string databaseName)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                WindowsAzureSubscription subscription = WindowsAzureProfile.Instance.CurrentSubscription;

                // create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(context.GetDatabase(databaseName));
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(context.GetDatabases());
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
コード例 #7
0
        /// <summary>
        /// Connect to a Azure SQL Server with the given ManagementService Uri using
        /// SQL authentication credentials.
        /// </summary>
        /// <param name="serverName">The server name.</param>
        /// <param name="managementServiceUri">The server's ManagementService Uri.</param>
        /// <param name="credentials">The SQL Authentication credentials for the server.</param>
        /// <returns>A new <see cref="ServerDataServiceSqlAuth"/> context,
        /// or <c>null</c> if an error occurred.</returns>
        internal IServerDataServiceContext GetServerDataServiceBySqlAuth(
            string serverName,
            Uri managementServiceUri,
            SqlAuthenticationCredentials credentials,
            Uri manageUrl)
        {
            IServerDataServiceContext context = null;
            Guid sessionActivityId            = Guid.NewGuid();

            try
            {
                context = SqlAuthContextFactory.GetContext(this, serverName, manageUrl, credentials, sessionActivityId, managementServiceUri);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    sessionActivityId.ToString(),
                    ex);

                // The context is not in an valid state because of the error, set the context
                // back to null.
                context = null;
            }

            return(context);
        }
コード例 #8
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!this.Force.IsPresent &&
                !this.ShouldProcess(
                    Resources.NewAzureSqlDatabaseDescription,
                    Resources.NewAzureSqlDatabaseWarning,
                    Resources.ShouldProcessCaption))
            {
                return;
            }

            try
            {
                int?maxSizeGb = this.MyInvocation.BoundParameters.ContainsKey("MaxSizeGB") ?
                                (int?)this.MaxSizeGB : null;

                Database database = this.ConnectionContext.CreateNewDatabase(
                    this.DatabaseName,
                    maxSizeGb,
                    this.Collation,
                    this.Edition);

                this.WriteObject(database, true);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #9
0
        /// <summary>
        /// Process the request using a temporary connection context.
        /// </summary>
        /// <param name="databaseName">The name of the database to remove</param>
        private void ProcessWithServerName(string databaseName)
        {
            string clientRequestId = string.Empty;

            try
            {
                // Get the current subscription data.
                SubscriptionData subscriptionData = this.GetCurrentSubscription();

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscriptionData);

                clientRequestId = context.ClientRequestId;

                // Remove the database with the specified name
                context.RemoveDatabase(databaseName);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #10
0
        /// <summary>
        /// Process the request using the provided connection context
        /// </summary>
        /// <param name="databaseName">the name of the database to retrieve</param>
        private void ProcessWithContext(IServerDataServiceContext context)
        {
            string databaseName = GetDatabaseName();

            try
            {
                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(context.GetDatabase(databaseName), true);
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(context.GetDatabases(), true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    context.ClientRequestId,
                    ex);
            }
        }
コード例 #11
0
        /// <summary>
        /// Performs the call to import database using the server data service context channel.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to.</param>
        /// <param name="input">The <see cref="ImportInput"/> object that contains
        /// all the connection information</param>
        /// <returns>The result of the import request.  Upon success the <see cref="ImportExportRequest"/>
        /// for the request</returns>
        internal ImportExportRequest ImportSqlAzureDatabaseProcess(string serverName, ImportInput input)
        {
            ImportExportRequest result = null;

            try
            {
                XmlElement requestId = RetryCall(subscription =>
                                                 this.Channel.ImportDatabase(subscription, serverName, input));
                Microsoft.WindowsAzure.ServiceManagement.Operation operation = WaitForSqlDatabaseOperation();

                if (requestId != null)
                {
                    result             = new ImportExportRequest();
                    result.RequestGuid = requestId.InnerText;
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.SqlConnectionContext.ClientRequestId,
                    ex);
            }

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Process the record with the provided server name
        /// </summary>
        /// <param name="databaseName">The name of the database to retrieve</param>
        private void ProcessWithServerName(string databaseName)
        {
            string clientRequestId = string.Empty;

            try
            {
                // Get the current subscription data.
                SubscriptionData subscriptionData = this.GetCurrentSubscription();

                // create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscriptionData);

                clientRequestId = context.ClientRequestId;

                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(context.GetDatabase(databaseName));
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(context.GetDatabases());
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #13
0
        /// <summary>
        /// Process the request using the server name
        /// </summary>
        /// <param name="maxSizeGb">the maximum size of the database</param>
        private void ProcessWithServerName(int?maxSizeGb)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                WindowsAzureSubscription subscription = WindowsAzureProfile.Instance.CurrentSubscription;

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                // Retrieve the database with the specified name
                this.WriteObject(context.CreateNewDatabase(
                                     this.DatabaseName,
                                     maxSizeGb,
                                     this.Collation,
                                     this.Edition,
                                     this.ServiceObjective));
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
コード例 #14
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Obtain the database name from the given parameters.
            string databaseName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
            {
                databaseName = this.Database.Name;
            }
            else if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseName"))
            {
                databaseName = this.DatabaseName;
            }

            try
            {
                if (databaseName != null)
                {
                    // Retrieve the database with the specified name
                    this.WriteObject(this.ConnectionContext.GetDatabase(databaseName));
                }
                else
                {
                    // No name specified, retrieve all databases in the server
                    this.WriteObject(this.ConnectionContext.GetDatabases(), true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #15
0
        /// <summary>
        /// Process the request using the server name
        /// </summary>
        /// <param name="maxSizeGb">the maximum size of the database</param>
        private void ProcessWithServerName(int?maxSizeGb)
        {
            string clientRequestId = string.Empty;

            try
            {
                // Get the current subscription data.
                SubscriptionData subscriptionData = this.GetCurrentSubscription();

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscriptionData);

                clientRequestId = context.ClientRequestId;

                // Retrieve the database with the specified name
                this.WriteObject(context.CreateNewDatabase(
                                     this.DatabaseName,
                                     maxSizeGb,
                                     this.Collation,
                                     this.Edition));
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #16
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Do nothing if force is not specified and user cancelled the operation
            string actionDescription = string.Format(
                CultureInfo.InvariantCulture,
                Resources.NewAzureSqlDatabaseWithCopyDescription,
                this.ConnectionContext.ServerName,
                DatabaseName,
                this.PartnerServer);
            string actionWarning = string.Format(
                CultureInfo.InvariantCulture,
                Resources.NewAzureSqlDatabaseWithCopyWarning,
                this.ConnectionContext.ServerName,
                DatabaseName,
                this.PartnerServer);

            this.WriteVerbose(actionDescription);
            if (!this.Force.IsPresent &&
                !this.ShouldProcess(
                    actionDescription,
                    actionWarning,
                    Resources.ShouldProcessCaption))
            {
                return;
            }

            try
            {
                int?maxSizeGb = this.MyInvocation.BoundParameters.ContainsKey("MaxSizeGB") ?
                                (int?)this.MaxSizeGB : null;

                int?maxLagInMinutes = this.MyInvocation.BoundParameters.ContainsKey("MaxLagInMinutes") ?
                                      (int?)this.MaxLagInMinutes : null;

                Database database = this.ConnectionContext.CreateNewDatabaseWithCopy(
                    this.DatabaseName,
                    this.PartnerServer,
                    maxSizeGb,
                    this.Collation,
                    this.Edition,
                    maxLagInMinutes);

                this.WriteObject(database);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #17
0
        /// <summary>
        /// Process the request using a temporary connection context using certificate authentication
        /// </summary>
        /// <param name="databaseName">The name of the database to update</param>
        /// <param name="maxSizeGb">the new size for the database or null</param>
        /// <param name="maxSizeBytes"></param>
        /// <param name="edition">the new edition for the database or null</param>
        private void ProcessWithServerName(string databaseName, int?maxSizeGb, long?maxSizeBytes, DatabaseEdition?edition)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                AzureSubscription subscription = Profile.Context.Subscription;

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, Profile, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                // Remove the database with the specified name
                Services.Server.Database database = context.UpdateDatabase(
                    databaseName,
                    this.NewDatabaseName,
                    maxSizeGb,
                    maxSizeBytes,
                    edition,
                    this.ServiceObjective);

                if (this.Sync.IsPresent)
                {
                    // Wait for the operation to complete on the server.
                    database = CmdletCommon.WaitForDatabaseOperation(this, context, database, this.DatabaseName, false);
                }

                // Update the passed in database object
                if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
                {
                    this.Database.CopyFields(database);
                    database = this.Database;
                }

                // If PassThru was specified, write back the updated object to the pipeline
                if (this.PassThru.IsPresent)
                {
                    this.WriteObject(database);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
コード例 #18
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Obtain the database name from the given parameters.
            string databaseName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
            {
                databaseName = this.Database.Name;
            }
            else if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseName"))
            {
                databaseName = this.DatabaseName;
            }

            // Do nothing if force is not specified and user cancelled the operation
            string actionDescription = string.Format(
                CultureInfo.InvariantCulture,
                Resources.RemoveAzureSqlDatabaseDescription,
                this.ConnectionContext.ServerName,
                databaseName);
            string actionWarning = string.Format(
                CultureInfo.InvariantCulture,
                Resources.RemoveAzureSqlDatabaseWarning,
                this.ConnectionContext.ServerName,
                databaseName);

            this.WriteVerbose(actionDescription);
            if (!this.Force.IsPresent &&
                !this.ShouldProcess(
                    actionDescription,
                    actionWarning,
                    Resources.ShouldProcessCaption))
            {
                return;
            }

            try
            {
                // Remove the database with the specified name
                this.ConnectionContext.RemoveDatabase(databaseName);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #19
0
 /// <summary>
 /// Process the request with the connection context
 /// </summary>
 /// <param name="databaseName">The name of the database to remove</param>
 private void ProcessWithConnectionContext(string databaseName)
 {
     try
     {
         // Remove the database with the specified name
         this.ConnectionContext.RemoveDatabase(databaseName);
     }
     catch (Exception ex)
     {
         SqlDatabaseExceptionHandler.WriteErrorDetails(
             this,
             this.ConnectionContext.ClientRequestId,
             ex);
     }
 }
コード例 #20
0
        /// <summary>
        /// Process the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            // Obtain the source server and database name from the given parameters.
            var sourceServerName =
                this.SourceDatabase != null ? this.SourceDatabase.ServerName :
                this.SourceServerName ??
                this.TargetServerName;

            var sourceDatabaseName =
                this.SourceDatabase != null ? this.SourceDatabase.Name :
                this.SourceDatabaseName;

            IServerDataServiceContext connectionContext = null;

            // If a database object was piped in, use its connection context...
            if (this.SourceDatabase != null)
            {
                connectionContext = this.SourceDatabase.Context;
            }
            else
            {
                // ... else create a temporary context
                connectionContext = ServerDataServiceCertAuth.Create(this.TargetServerName, WindowsAzureProfile.Instance.CurrentSubscription);
            }

            string clientRequestId = connectionContext.ClientRequestId;

            try
            {
                if (sourceDatabaseName != null)
                {
                    // Retrieve the database with the specified name and deletion date
                    this.WriteObject(connectionContext.GetRecoverableDatabase(sourceServerName, sourceDatabaseName));
                }
                else
                {
                    // No name specified, retrieve all restorable dropped databases in the server
                    this.WriteObject(connectionContext.GetRecoverableDatabases(sourceServerName), true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #21
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            this.SourceDatabaseName =
                this.SourceDatabase != null ? this.SourceDatabase.Name :
                this.SourceDatabaseName;

            this.SourceServerName =
                this.SourceDatabase != null ? this.SourceDatabase.ServerName :
                this.SourceServerName;

            this.TargetDatabaseName = this.TargetDatabaseName ?? this.SourceDatabaseName;

            // Get the current subscription data
            var subscription = WindowsAzureProfile.Instance.CurrentSubscription;

            IServerDataServiceContext connectionContext = null;

            // If a database object was piped in, use its connection context...
            if (this.SourceDatabase != null)
            {
                connectionContext = this.SourceDatabase.Context;
            }
            else
            {
                // ... else create a temporary context
                connectionContext = ServerDataServiceCertAuth.Create(this.TargetServerName, subscription);
            }

            string clientRequestId = connectionContext.ClientRequestId;

            try
            {
                RecoverDatabaseOperation operation = connectionContext.RecoverDatabase(
                    this.SourceServerName,
                    this.SourceDatabaseName,
                    this.TargetDatabaseName);

                this.WriteObject(operation);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #22
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            // Obtain the database name from the given parameters.
            string databaseName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
            {
                databaseName = this.Database.Name;
            }
            else if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseName"))
            {
                databaseName = this.DatabaseName;
            }

            // Use the provided ServerDataServiceContext or create one from the
            // provided ServerName and the active subscription.
            IServerDataServiceContext context = ServerDataServiceCertAuth.Create(this.ServerName,
                                                                                 Profile,
                                                                                 Profile.Context.Subscription);

            try
            {
                if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseCopy"))
                {
                    // Refresh the specified database copy object
                    this.WriteObject(context.GetDatabaseCopy(this.DatabaseCopy), true);
                }
                else
                {
                    // Retrieve all database copy object with matching parameters
                    DatabaseCopyModel[] copies = context.GetDatabaseCopy(
                        databaseName,
                        this.PartnerServer,
                        this.PartnerDatabase);
                    this.WriteObject(copies, true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    context.ClientRequestId,
                    ex);
            }
        }
コード例 #23
0
        /// <summary>
        /// Process the request using a temporary connection context using certificate authentication
        /// </summary>
        /// <param name="databaseName">The name of the database to update</param>
        /// <param name="maxSizeGb">the new size for the database or null</param>
        /// <param name="edition">the new edition for the database or null</param>
        private void ProcessWithServerName(string databaseName, int?maxSizeGb, DatabaseEdition?edition)
        {
            Func <string> GetClientRequestId = () => string.Empty;

            try
            {
                // Get the current subscription data.
                WindowsAzureSubscription subscription = WindowsAzureProfile.Instance.CurrentSubscription;

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscription);

                GetClientRequestId = () => context.ClientRequestId;

                // Remove the database with the specified name
                Database database = context.UpdateDatabase(
                    databaseName,
                    this.NewDatabaseName,
                    maxSizeGb,
                    edition,
                    this.ServiceObjective);

                // Update the passed in database object
                if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
                {
                    this.Database.CopyFields(database);
                    database = this.Database;
                }

                // If PassThru was specified, write back the updated object to the pipeline
                if (this.PassThru.IsPresent)
                {
                    this.WriteObject(database);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    GetClientRequestId(),
                    ex);
            }
        }
コード例 #24
0
        /// <summary>
        /// Connect to Azure SQL Server using certificate authentication.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to</param>
        /// <param name="subscriptionData">The subscription data to use for authentication</param>
        /// <returns>A new <see cref="ServerDataServiceCertAuth"/> context,
        /// or <c>null</c> if an error occurred.</returns>
        internal ServerDataServiceCertAuth GetServerDataServiceByCertAuth(
            string serverName,
            SubscriptionData subscriptionData)
        {
            ServerDataServiceCertAuth context = null;

            try
            {
                context = ServerDataServiceCertAuth.Create(serverName, subscriptionData);
            }
            catch (ArgumentException e)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(this, string.Empty, e);

                context = null;
            }

            return(context);
        }
コード例 #25
0
        /// <summary>
        /// Process the request using a temporary connection context using certificate authentication
        /// </summary>
        /// <param name="databaseName">The name of the database to update</param>
        /// <param name="maxSizeGb">the new size for the database or null</param>
        /// <param name="edition">the new edition for the database or null</param>
        private void ProcessWithServerName(string databaseName, int?maxSizeGb, DatabaseEdition?edition)
        {
            string clientRequestId = null;

            try
            {
                // Get the current subscription data.
                SubscriptionData subscriptionData = this.GetCurrentSubscription();

                // Create a temporary context
                ServerDataServiceCertAuth context =
                    ServerDataServiceCertAuth.Create(this.ServerName, subscriptionData);

                clientRequestId = context.ClientRequestId;

                // Remove the database with the specified name
                Database database = context.UpdateDatabase(
                    databaseName,
                    this.NewDatabaseName,
                    maxSizeGb,
                    edition,
                    this.ServiceObjective);

                // If PassThru was specified, write back the updated object to the pipeline
                if (this.PassThru.IsPresent)
                {
                    this.WriteObject(database);
                }

                if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
                {
                    this.Database.CopyFields(database);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    clientRequestId,
                    ex);
            }
        }
コード例 #26
0
        /// <summary>
        /// Connect to a Azure Sql Server with the given ManagementService Uri using
        /// Sql Authentication credentials.
        /// </summary>
        /// <param name="serverName">The server name.</param>
        /// <param name="managementServiceUri">The server's ManagementService Uri.</param>
        /// <param name="credentials">The Sql Authentication credentials for the server.</param>
        /// <returns>A new <see cref="ServerDataServiceSqlAuth"/> context,
        /// or <c>null</c> if an error occurred.</returns>
        internal ServerDataServiceSqlAuth GetServerDataServiceBySqlAuth(
            string serverName,
            Uri managementServiceUri,
            SqlAuthenticationCredentials credentials)
        {
            ServerDataServiceSqlAuth context = null;

            Guid sessionActivityId = Guid.NewGuid();

            try
            {
                context = ServerDataServiceSqlAuth.Create(
                    managementServiceUri,
                    sessionActivityId,
                    credentials,
                    serverName);

                // Retrieve $metadata to verify model version compativility
                XDocument metadata         = context.RetrieveMetadata();
                XDocument filteredMetadata = DataConnectionUtility.FilterMetadataDocument(metadata);
                string    metadataHash     = DataConnectionUtility.GetDocumentHash(filteredMetadata);
                if (!context.metadataHashes.Any(knownHash => metadataHash == knownHash))
                {
                    this.WriteWarning(Resources.WarningModelOutOfDate);
                }

                context.MergeOption = MergeOption.PreserveChanges;
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    sessionActivityId.ToString(),
                    ex);

                // The context is not in an valid state because of the error, set the context
                // back to null.
                context = null;
            }

            return(context);
        }
コード例 #27
0
        /// <summary>
        /// Process the request using the connection context.
        /// </summary>
        /// <param name="maxSizeGb">the maximum size for the new database</param>
        private void ProcessWithConnectionContext(int?maxSizeGb)
        {
            try
            {
                Database database = this.ConnectionContext.CreateNewDatabase(
                    this.DatabaseName,
                    maxSizeGb,
                    this.Collation,
                    this.Edition);

                this.WriteObject(database, true);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #28
0
        /// <summary>
        /// Connect to Azure SQL Server using certificate authentication.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to</param>
        /// <param name="subscription">The subscription data to use for authentication</param>
        /// <returns>A new <see cref="ServerDataServiceCertAuth"/> context,
        /// or <c>null</c> if an error occurred.</returns>
        internal ServerDataServiceCertAuth GetServerDataServiceByCertAuth(
            string serverName,
            IAzureSubscription subscription)
        {
            ServerDataServiceCertAuth context = null;

            SqlDatabaseCmdletBase.ValidateSubscription(subscription);

            try
            {
                context = ServerDataServiceCertAuth.Create(serverName, Profile, subscription);
            }
            catch (ArgumentException e)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(this, string.Empty, e);

                context = null;
            }

            return(context);
        }
コード例 #29
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Obtain the database name from the given parameters.
            string databaseName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
            {
                databaseName = this.Database.Name;
            }
            else if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseName"))
            {
                databaseName = this.DatabaseName;
            }

            try
            {
                if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseCopy"))
                {
                    // Refresh the specified database copy object
                    this.WriteObject(this.ConnectionContext.GetDatabaseCopy(this.DatabaseCopy), true);
                }
                else
                {
                    // Retrieve all database copy object with matching parameters
                    DatabaseCopy[] copies = this.ConnectionContext.GetDatabaseCopy(
                        databaseName,
                        this.PartnerServer,
                        this.PartnerDatabase);
                    this.WriteObject(copies, true);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #30
0
 /// <summary>
 /// Process the get quota request using the supplied connection context.  This can be a connection
 /// context that was created using Sql Authentication or Certificate authentication.
 /// </summary>
 /// <param name="quotaName"></param>
 private void ProcessWithConnectionContext(string quotaName)
 {
     try
     {
         if (!string.IsNullOrEmpty(quotaName))
         {
             // Retrieve the quota with the specified name
             this.WriteObject(this.ConnectionContext.GetQuota(quotaName));
         }
         else
         {
             // No name specified, retrieve all quotas in the server
             this.WriteObject(this.ConnectionContext.GetQuotas(), true);
         }
     }
     catch (Exception ex)
     {
         SqlDatabaseExceptionHandler.WriteErrorDetails(
             this,
             this.ConnectionContext.ClientRequestId,
             ex);
     }
 }