/// <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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
        public void SetAzureSqlDatabaseNameWithCertAuth()
        {
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();

            // This is needed because UpdateDatabases calls GetDatabases in order to
            // get the necessary database information for the delete.
            channel.GetDatabaseThunk = ar =>
            {
                Assert.AreEqual(
                    ar.Values["databaseName"],
                    "testdb1",
                    "The input databaseName (for get) did not match the expected");

                SqlDatabaseResponse db1 = new SqlDatabaseResponse();
                db1.CollationName    = "Japanese_CI_AS";
                db1.Edition          = "Web";
                db1.Id               = "1";
                db1.MaxSizeGB        = "1";
                db1.Name             = "testdb1";
                db1.CreationDate     = DateTime.Now.ToString();
                db1.IsFederationRoot = true.ToString();
                db1.IsSystemObject   = true.ToString();
                db1.MaxSizeBytes     = "1073741824";

                return(db1);
            };

            channel.UpdateDatabaseThunk = ar =>
            {
                Assert.AreEqual(
                    "testdb1",
                    ar.Values["databaseName"],
                    "The input databaseName (for update) did not match the expected");

                Assert.AreEqual(
                    "newTestDb1",
                    ((SqlDatabaseInput)ar.Values["input"]).Name,
                    "The database Name input parameter does not match");
                Assert.AreEqual(
                    "1",
                    ((SqlDatabaseInput)ar.Values["input"]).MaxSizeGB,
                    "The database MaxSizeGB input parameter does not match");
                Assert.AreEqual(
                    "Japanese_CI_AS",
                    ((SqlDatabaseInput)ar.Values["input"]).CollationName,
                    "The database CollationName input parameter does not match");
                Assert.AreEqual(
                    "Web",
                    ((SqlDatabaseInput)ar.Values["input"]).Edition,
                    "The database Edition input parameter does not match");

                SqlDatabaseResponse response = new SqlDatabaseResponse();
                response.CollationName    = ((SqlDatabaseInput)ar.Values["input"]).CollationName;
                response.CreationDate     = DateTime.Now.ToString();
                response.MaxSizeBytes     = "1073741824";
                response.Edition          = ((SqlDatabaseInput)ar.Values["input"]).Edition.ToString();
                response.Id               = ((SqlDatabaseInput)ar.Values["input"]).Id;
                response.IsFederationRoot = true.ToString();
                response.IsSystemObject   = true.ToString();
                response.MaxSizeGB        = ((SqlDatabaseInput)ar.Values["input"]).MaxSizeGB.ToString();
                response.Name             = ((SqlDatabaseInput)ar.Values["input"]).Name;

                return(response);
            };

            SubscriptionData subscriptionData = UnitTestHelper.CreateUnitTestSubscription();

            subscriptionData.ServiceEndpoint = MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri;

            NewAzureSqlDatabaseServerContext contextCmdlet = new NewAzureSqlDatabaseServerContext();

            ServerDataServiceCertAuth service =
                contextCmdlet.GetServerDataServiceByCertAuth("TestServer", subscriptionData);

            service.Channel = channel;

            Database database = service.UpdateDatabase("testdb1", "newTestDb1", null, null, null);

            Assert.AreEqual(
                database.CollationName,
                "Japanese_CI_AS",
                "The updated database collation name is wrong");
            Assert.AreEqual(
                database.Edition,
                "Web",
                "The updated database Edition is wrong");
            Assert.AreEqual(
                database.MaxSizeGB,
                1,
                "The updated database Edition is wrong");
            Assert.AreEqual(
                database.Name,
                "newTestDb1",
                "The updated database Edition is wrong");
        }