/// <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; } string partnerServerName = this.PartnerServer; string partnerDatabaseName = this.PartnerDatabase; if (this.ContinuousCopy.IsPresent) { // Default partnerDatabaseName to the only allowed value for continuous copies. partnerDatabaseName = partnerDatabaseName ?? databaseName; } else { // Default partnerServerName to the only allowed value for normal copies. partnerServerName = partnerServerName ?? this.ServerName; } // Do nothing if force is not specified and user cancelled the operation string actionDescription = string.Format( CultureInfo.InvariantCulture, Resources.StartAzureSqlDatabaseCopyDescription, this.ServerName, databaseName, partnerServerName, partnerDatabaseName); string actionWarning = string.Format( CultureInfo.InvariantCulture, Resources.StartAzureSqlDatabaseCopyWarning, this.ServerName, databaseName, partnerServerName, partnerDatabaseName); this.WriteVerbose(actionDescription); if (!this.Force.IsPresent && !this.ShouldProcess( actionDescription, actionWarning, Resources.ShouldProcessCaption)) { return; } // Use the provided ServerDataServiceContext or create one from the // provided ServerName and the active subscription. IServerDataServiceContext context = ServerDataServiceCertAuth.Create(this.ServerName, WindowsAzureProfile.Instance.CurrentSubscription); try { // Update the database with the specified name DatabaseCopyModel databaseCopy = context.StartDatabaseCopy( databaseName, partnerServerName, partnerDatabaseName, this.ContinuousCopy.IsPresent, this.OfflineSecondary.IsPresent); this.WriteObject(databaseCopy, true); } catch (Exception ex) { SqlDatabaseExceptionHandler.WriteErrorDetails( this, context.ClientRequestId, ex); } }