/// <summary>
        /// Terminate an ongoing database copy operation.
        /// </summary>
        /// <param name="copyModel">The database copy to terminate.</param>
        /// <param name="forcedTermination"><c>true</c> to forcefully terminate the copy.</param>
        public void StopDatabaseCopy(
            DatabaseCopyModel copyModel,
            bool forcedTermination)
        {
            DatabaseCopy databaseCopy = GetCopyForCopyModel(copyModel);

            // Create a new request Id for this operation
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            try
            {
                // Mark Forced/Friendly flag on the databaseCopy object first
                databaseCopy.IsForcedTerminate = forcedTermination;
                this.UpdateObject(databaseCopy);
                this.SaveChanges();

                // Mark the copy operation for delete
                this.DeleteObject(databaseCopy);
                this.SaveChanges();
            }
            catch
            {
                this.RevertChanges(databaseCopy);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Revert the changes made to the given object, detach it from the context.
        /// </summary>
        /// <param name="databaseCopy">The object that is being operated on.</param>
        protected void RevertChanges(DatabaseCopy databaseCopy)
        {
            // Revert the object by requerying for the object and clean up tracking
            if (databaseCopy != null)
            {
                this.RefreshEntity(databaseCopy);
            }

            this.ClearTrackedEntity(databaseCopy);
        }
        private DatabaseCopy GetCopyForCopyModel(DatabaseCopyModel model)
        {
            DatabaseCopy retval = this.DatabaseCopies.Where(copy => copy.EntityId == model.EntityId &&
                                                            model.IsLocalDatabaseReplicationTarget == copy.IsLocalDatabaseReplicationTarget)
                                  .SingleOrDefault();

            if (retval == null)
            {
                throw new ApplicationException(Resources.DatabaseCopyNotFoundGeneric);
            }

            return(retval);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Refresh the object by requerying for the object and merge changes.
        /// </summary>
        /// <param name="databaseCopy">The object to refresh.</param>
        /// <returns>The object with refreshed properties from the server.</returns>
        protected DatabaseCopy RefreshEntity(DatabaseCopy databaseCopy)
        {
            MergeOption tempOption = this.MergeOption;

            this.MergeOption = MergeOption.OverwriteChanges;
            databaseCopy     = this.DatabaseCopies
                               .Where(copy => copy.SourceServerName == databaseCopy.SourceServerName)
                               .Where(copy => copy.SourceDatabaseName == databaseCopy.SourceDatabaseName)
                               .Where(copy => copy.DestinationServerName == databaseCopy.DestinationServerName)
                               .Where(copy => copy.DestinationDatabaseName == databaseCopy.DestinationDatabaseName)
                               .SingleOrDefault();
            this.MergeOption = tempOption;

            return(databaseCopy);
        }
        /// <summary>
        /// Start database copy on the database with the name <paramref name="databaseName"/>.
        /// </summary>
        /// <param name="databaseName">The name of the database to copy.</param>
        /// <param name="partnerServer">The name for the partner server.</param>
        /// <param name="partnerDatabaseName">The name of the database on the partner server.</param>
        /// <param name="continuousCopy"><c>true</c> to make this a continuous copy.</param>
        /// <param name="isOfflineSecondary"><c>true</c> to make this an offline secondary copy.</param>
        /// <returns>The new instance of database copy operation.</returns>
        public DatabaseCopyModel StartDatabaseCopy(
            string databaseName,
            string partnerServer,
            string partnerDatabaseName,
            bool continuousCopy,
            bool isOfflineSecondary)
        {
            // Create a new request Id for this operation
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            // Create a new database copy object with all the required properties
            DatabaseCopy databaseCopy = new DatabaseCopy();

            databaseCopy.SourceServerName        = this.ServerName;
            databaseCopy.SourceDatabaseName      = databaseName;
            databaseCopy.DestinationServerName   = partnerServer;
            databaseCopy.DestinationDatabaseName = partnerDatabaseName;

            // Set the optional continuous copy flag
            databaseCopy.IsContinuous = continuousCopy;

            // Set the optional IsOfflineSecondary flag
            databaseCopy.IsOfflineSecondary = isOfflineSecondary;

            this.AddToDatabaseCopies(databaseCopy);
            DatabaseCopy trackedDatabaseCopy = databaseCopy;

            try
            {
                this.SaveChanges(SaveChangesOptions.None);

                // Requery for the entity to obtain updated linkid and state
                databaseCopy = this.RefreshEntity(databaseCopy);
                if (databaseCopy == null)
                {
                    throw new ApplicationException(Resources.ErrorRefreshingDatabaseCopy);
                }
            }
            catch
            {
                this.RevertChanges(trackedDatabaseCopy);
                throw;
            }

            return(CreateCopyModelFromCopy(databaseCopy));
        }
Exemplo n.º 6
0
 private static DatabaseCopyModel CreateCopyModelFromCopy(DatabaseCopy copy)
 {
     return(new DatabaseCopyModel()
     {
         EntityId = copy.EntityId,
         SourceServerName = copy.SourceServerName,
         SourceDatabaseName = copy.SourceDatabaseName,
         DestinationServerName = copy.DestinationServerName,
         DestinationDatabaseName = copy.DestinationDatabaseName,
         IsContinuous = copy.IsContinuous,
         ReplicationState = copy.ReplicationState,
         ReplicationStateDescription = copy.ReplicationStateDescription,
         LocalDatabaseId = copy.LocalDatabaseId,
         IsLocalDatabaseReplicationTarget = copy.IsLocalDatabaseReplicationTarget,
         IsInterlinkConnected = copy.IsInterlinkConnected,
         StartDate = DateTime.Parse(copy.TextStartDate),
         ModifyDate = DateTime.Parse(copy.TextModifyDate),
         PercentComplete = copy.PercentComplete.GetValueOrDefault()
     });
 }
Exemplo n.º 7
0
        /// <summary>
        /// Revert the changes made to the given object, detach it from the context.
        /// </summary>
        /// <param name="databaseCopy">The object that is being operated on.</param>
        protected void RevertChanges(DatabaseCopy databaseCopy)
        {
            // Revert the object by requerying for the object and clean up tracking
            if (databaseCopy != null)
            {
                this.RefreshEntity(databaseCopy);
            }

            this.ClearTrackedEntity(databaseCopy);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Refresh the object by requerying for the object and merge changes.
        /// </summary>
        /// <param name="databaseCopy">The object to refresh.</param>
        /// <returns>The object with refreshed properties from the server.</returns>
        protected DatabaseCopy RefreshEntity(DatabaseCopy databaseCopy)
        {
            MergeOption tempOption = this.MergeOption;
            this.MergeOption = MergeOption.OverwriteChanges;
            databaseCopy = this.DatabaseCopies
                .Where(copy => copy.SourceServerName == databaseCopy.SourceServerName)
                .Where(copy => copy.SourceDatabaseName == databaseCopy.SourceDatabaseName)
                .Where(copy => copy.DestinationServerName == databaseCopy.DestinationServerName)
                .Where(copy => copy.DestinationDatabaseName == databaseCopy.DestinationDatabaseName)
                .SingleOrDefault();
            this.MergeOption = tempOption;

            return databaseCopy;
        }
        /// <summary>
        /// Start database copy on the database with the name <paramref name="databaseName"/>.
        /// </summary>
        /// <param name="databaseName">The name of the database to copy.</param>
        /// <param name="partnerServer">The name for the partner server.</param>
        /// <param name="partnerDatabaseName">The name of the database on the partner server.</param>
        /// <param name="continuousCopy"><c>true</c> to make this a continuous copy.</param>
        /// <returns>The new instance of database copy operation.</returns>
        public DatabaseCopyModel StartDatabaseCopy(
            string databaseName,
            string partnerServer,
            string partnerDatabaseName,
            bool continuousCopy)
        {
            // Create a new request Id for this operation
            this.clientRequestId = SqlDatabaseCmdletBase.GenerateClientTracingId();

            // Create a new database copy object with all the required properties
            DatabaseCopy databaseCopy = new DatabaseCopy();
            databaseCopy.SourceServerName = this.ServerName;
            databaseCopy.SourceDatabaseName = databaseName;
            databaseCopy.DestinationServerName = partnerServer;
            databaseCopy.DestinationDatabaseName = partnerDatabaseName;

            // Set the optional continuous copy flag
            databaseCopy.IsContinuous = continuousCopy;

            this.AddToDatabaseCopies(databaseCopy);
            DatabaseCopy trackedDatabaseCopy = databaseCopy;
            try
            {
                this.SaveChanges(SaveChangesOptions.None);

                // Requery for the entity to obtain updated linkid and state
                databaseCopy = this.RefreshEntity(databaseCopy);
                if (databaseCopy == null)
                {
                    throw new ApplicationException(Resources.ErrorRefreshingDatabaseCopy);
                }
            }
            catch
            {
                this.RevertChanges(trackedDatabaseCopy);
                throw;
            }

            return CreateCopyModelFromCopy(databaseCopy);
        }
 private static DatabaseCopyModel CreateCopyModelFromCopy(DatabaseCopy copy)
 {
     return new DatabaseCopyModel()
     {
         EntityId = copy.EntityId,
         SourceServerName = copy.SourceServerName,
         SourceDatabaseName = copy.SourceDatabaseName,
         DestinationServerName = copy.DestinationServerName,
         DestinationDatabaseName = copy.DestinationDatabaseName,
         IsContinuous = copy.IsContinuous,
         ReplicationState = copy.ReplicationState,
         ReplicationStateDescription = copy.ReplicationStateDescription,
         LocalDatabaseId = copy.LocalDatabaseId,
         IsLocalDatabaseReplicationTarget = copy.IsLocalDatabaseReplicationTarget,
         IsInterlinkConnected = copy.IsInterlinkConnected,
         StartDate = DateTime.Parse(copy.TextStartDate),
         ModifyDate = DateTime.Parse(copy.TextModifyDate),
         PercentComplete = copy.PercentComplete.GetValueOrDefault()
     };
 }