예제 #1
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);
            }
        }