/// <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); } }
/// <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, WindowsAzureProfile.Instance.CurrentSubscription); DatabaseCopyModel databaseCopy; if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseCopy")) { // Refreshes the given copy object databaseCopy = context.GetDatabaseCopy(this.DatabaseCopy); } else { // Retrieve all database copy object with matching parameters DatabaseCopyModel[] copies = context.GetDatabaseCopy( databaseName, this.PartnerServer, this.PartnerDatabase); if (copies.Length == 0) { throw new ApplicationException(Resources.DatabaseCopyNotFoundGeneric); } else if (copies.Length > 1) { throw new ApplicationException(Resources.MoreThanOneDatabaseCopyFound); } databaseCopy = copies.Single(); } // Do nothing if force is not specified and user cancelled the operation string actionDescription = string.Format( CultureInfo.InvariantCulture, Resources.StopAzureSqlDatabaseCopyDescription, databaseCopy.SourceServerName, databaseCopy.SourceDatabaseName, databaseCopy.DestinationServerName, databaseCopy.DestinationDatabaseName); string actionWarning = string.Format( CultureInfo.InvariantCulture, Resources.StopAzureSqlDatabaseCopyWarning, databaseCopy.SourceServerName, databaseCopy.SourceDatabaseName, databaseCopy.DestinationServerName, databaseCopy.DestinationDatabaseName); this.WriteVerbose(actionDescription); if (!this.Force.IsPresent && !this.ShouldProcess( actionDescription, actionWarning, Resources.ShouldProcessCaption)) { return; } try { // Stop the specified database copy context.StopDatabaseCopy( databaseCopy, this.ForcedTermination.IsPresent); } catch (Exception ex) { SqlDatabaseExceptionHandler.WriteErrorDetails( this, context.ClientRequestId, ex); } }