Ejemplo n.º 1
0
 protected override void InternalProcessRecord()
 {
     this.SupportsCutover = false;
     if (this.Imap || this.ExchangeOutlookAnywhere)
     {
         this.SupportsCutover = MigrationSession.SupportsCutover(base.DataProvider);
     }
     if (this.ExchangeOutlookAnywhere)
     {
         this.InternalProcessExchangeOutlookAnywhere(base.DataProvider);
         return;
     }
     if (this.ExchangeRemoteMove && this.Autodiscover)
     {
         this.InternalProcessExchangeRemoteMoveAutoDiscover();
         return;
     }
     if (this.PSTImport)
     {
         this.InternalProcessPSTImport();
         return;
     }
     if (this.PublicFolder)
     {
         this.InternalProcessPublicFolder();
         return;
     }
     if (this.endpoint != null)
     {
         this.InternalProcessEndpoint(false);
         return;
     }
     MigrationLogger.Log(MigrationEventType.Error, "TestMigrationServerAvailability.InternalProcessRecord: Wrong protocol", new object[0]);
     this.WriteError(new TestMigrationServerAvailabilityProtocolArgumentException());
 }
Ejemplo n.º 2
0
        internal static void RegisterMigrationBatch(Task task, MailboxSession mailboxSession, OrganizationId organizationId, bool failIfNotConnected, bool refresh = false)
        {
            string     serverFqdn           = mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn;
            Guid       mdbGuid              = mailboxSession.MdbGuid;
            string     mailboxOwnerLegacyDN = mailboxSession.MailboxOwnerLegacyDN;
            ADObjectId organizationName     = organizationId.OrganizationalUnit ?? new ADObjectId();
            int        num = 2;

            for (int i = 1; i <= num; i++)
            {
                try
                {
                    MigrationNotificationRpcStub migrationNotificationRpcStub = new MigrationNotificationRpcStub(serverFqdn);
                    migrationNotificationRpcStub.RegisterMigrationBatch(new RegisterMigrationBatchArgs(mdbGuid, mailboxOwnerLegacyDN, organizationName, refresh));
                    break;
                }
                catch (MigrationServiceRpcException ex)
                {
                    ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_MigrationServiceConnectionError, new string[]
                    {
                        serverFqdn,
                        ex.Message
                    });
                    if (i == num && failIfNotConnected)
                    {
                        MigrationLogger.Log(MigrationEventType.Warning, MigrationLogger.GetDiagnosticInfo(ex, null), new object[0]);
                        task.WriteError(new LocalizedException(Strings.MigrationOperationFailed, null), ExchangeErrorCategory.Client, null);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        internal static MigrationJob GetMigrationJobByBatchId(Task task, MigrationBatchDataProvider batchProvider, MigrationBatchId migrationBatchId, bool skipCorrupt, bool failIfNotFound = true)
        {
            MigrationJob migrationJob = null;
            Exception    ex           = null;

            try
            {
                migrationJob = batchProvider.JobCache.GetJob(migrationBatchId);
            }
            catch (PropertyErrorException ex2)
            {
                ex = ex2;
            }
            catch (InvalidDataException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                MigrationLogger.Log(MigrationEventType.Warning, MigrationLogger.GetDiagnosticInfo(ex, null), new object[0]);
                task.WriteError(new MigrationPermanentException(Strings.MigrationJobCorrupted, ex), ExchangeErrorCategory.Client, null);
            }
            if (migrationJob != null && migrationJob.Status == MigrationJobStatus.Corrupted && skipCorrupt)
            {
                migrationJob = null;
            }
            if (migrationJob == null && failIfNotFound)
            {
                MigrationObjectTaskBase <TIdentityParameter> .WriteJobNotFoundError(task, migrationBatchId.ToString());
            }
            return(migrationJob);
        }
Ejemplo n.º 4
0
 private void InternalProcessExchangeRemoteMoveAutoDiscover()
 {
     try
     {
         ExchangeRemoteMoveEndpoint exchangeRemoteMoveEndpoint = new ExchangeRemoteMoveEndpoint();
         exchangeRemoteMoveEndpoint.InitializeFromAutoDiscover(this.EmailAddress, this.Credentials);
         this.endpoint = exchangeRemoteMoveEndpoint;
     }
     catch (LocalizedException ex)
     {
         MigrationLogger.Log(MigrationEventType.Error, ex, "Failed to determine remote endpoint via auto-discover.", new object[0]);
         base.WriteObject(TestMigrationServerAvailabilityOutcome.Create(TestMigrationServerAvailabilityResult.Failed, this.SupportsCutover, ex.LocalizedString, ex.ToString()));
         return;
     }
     this.InternalProcessEndpoint(true);
 }
Ejemplo n.º 5
0
 private void WriteError(LocalizedException exception)
 {
     MigrationLogger.Log(MigrationEventType.Warning, MigrationLogger.GetDiagnosticInfo(exception, null), new object[0]);
     base.WriteError(exception, (ErrorCategory)1000, null);
 }
Ejemplo n.º 6
0
        private void InternalProcessExchangeOutlookAnywhere(IMigrationDataProvider dataProvider)
        {
            ExchangeOutlookAnywhereEndpoint exchangeOutlookAnywhereEndpoint = new ExchangeOutlookAnywhereEndpoint();

            try
            {
                if (this.Autodiscover)
                {
                    TestMigrationServerAvailabilityOutcome testMigrationServerAvailabilityOutcome = null;
                    try
                    {
                        exchangeOutlookAnywhereEndpoint.InitializeFromAutoDiscover(this.EmailAddress, this.Credentials);
                    }
                    catch (AutoDiscoverFailedConfigurationErrorException exception)
                    {
                        testMigrationServerAvailabilityOutcome = this.CreateAutodsicoverFailedOutcome(exception);
                    }
                    catch (AutoDiscoverFailedInternalErrorException exception2)
                    {
                        testMigrationServerAvailabilityOutcome = this.CreateAutodsicoverFailedOutcome(exception2);
                    }
                    if (testMigrationServerAvailabilityOutcome != null)
                    {
                        MigrationLogger.Log(MigrationEventType.Information, testMigrationServerAvailabilityOutcome.ToString(), new object[0]);
                        base.WriteObject(testMigrationServerAvailabilityOutcome);
                        return;
                    }
                }
                else
                {
                    exchangeOutlookAnywhereEndpoint.RpcProxyServer       = this.RPCProxyServer;
                    exchangeOutlookAnywhereEndpoint.Credentials          = this.Credentials;
                    exchangeOutlookAnywhereEndpoint.ExchangeServer       = this.ExchangeServer;
                    exchangeOutlookAnywhereEndpoint.AuthenticationMethod = this.Authentication;
                }
                IMigrationNspiClient nspiClient = MigrationServiceFactory.Instance.GetNspiClient(null);
                exchangeOutlookAnywhereEndpoint.NspiServer        = nspiClient.GetNewDSA(exchangeOutlookAnywhereEndpoint);
                exchangeOutlookAnywhereEndpoint.MailboxPermission = this.MailboxPermission;
                NspiMigrationDataReader nspiDataReader = exchangeOutlookAnywhereEndpoint.GetNspiDataReader(null);
                nspiDataReader.Ping();
                ExchangeOutlookAnywhereEndpoint.ValidateEndpoint(exchangeOutlookAnywhereEndpoint);
            }
            catch (MigrationTransientException ex)
            {
                MigrationLogger.Log(MigrationEventType.Warning, MigrationLogger.GetDiagnosticInfo(ex, null), new object[0]);
                base.WriteObject(TestMigrationServerAvailabilityOutcome.Create(TestMigrationServerAvailabilityResult.Failed, this.SupportsCutover, ex.LocalizedString, ex.InternalError));
                return;
            }
            catch (MigrationPermanentException ex2)
            {
                MigrationLogger.Log(MigrationEventType.Error, MigrationLogger.GetDiagnosticInfo(ex2, null), new object[0]);
                base.WriteObject(TestMigrationServerAvailabilityOutcome.Create(TestMigrationServerAvailabilityResult.Failed, this.SupportsCutover, ex2.LocalizedString, ex2.InternalError));
                return;
            }
            TestMigrationServerAvailabilityOutcome testMigrationServerAvailabilityOutcome2;

            try
            {
                TestMigrationServerAvailability.VerifyExchangeOutlookAnywhereConnection(dataProvider, exchangeOutlookAnywhereEndpoint, (string)this.EmailAddress, this.SourceMailboxLegacyDN, this.targetMailbox, !this.IsFieldSet("MailboxPermission"));
                testMigrationServerAvailabilityOutcome2 = TestMigrationServerAvailabilityOutcome.Create(TestMigrationServerAvailabilityResult.Success, this.SupportsCutover, (ExchangeConnectionSettings)exchangeOutlookAnywhereEndpoint.ConnectionSettings);
            }
            catch (LocalizedException ex3)
            {
                string diagnosticInfo = MigrationLogger.GetDiagnosticInfo(ex3, null);
                MigrationLogger.Log(MigrationEventType.Error, diagnosticInfo, new object[0]);
                testMigrationServerAvailabilityOutcome2 = TestMigrationServerAvailabilityOutcome.Create(TestMigrationServerAvailabilityResult.Failed, this.SupportsCutover, ex3.LocalizedString, diagnosticInfo);
                testMigrationServerAvailabilityOutcome2.ConnectionSettings = (ExchangeConnectionSettings)exchangeOutlookAnywhereEndpoint.ConnectionSettings;
            }
            base.WriteObject(testMigrationServerAvailabilityOutcome2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Executes the migration's down function to downgrade the database
        /// based on it's current changelog
        /// </summary>
        /// <returns></returns>
        public string Execute()
        {
            var    fileInfo   = new FileInfo(_projectFile);
            var    isMigrated = false;
            string logPath    = string.Empty;

            // check changelog for the latest migration run
            var changeLogCollection = new ChangelogCollection(_mongoDbContext);

            var changeLog    = changeLogCollection.All();
            var latestChange = changeLog.GetLatestChange();

            if (latestChange == null)
            {
                return("No changes to downgrade");
            }

            // get all classes in a namespace from project assembly
            var workingDirectory = fileInfo.Directory.FullName;

            // create build command for project where migrations are created
            var runner = CLI.DotNet(x => x.WorkingDirectory = workingDirectory)
                         .Build(x => x.BuildConfiguration = BuildConfiguration.Debug)
                         .Create();
            // run cli command
            var results = runner.Run();

            if (!results.IsSuccessful)
            {
                return($"Error: {fileInfo.Name} failed to build with the following errors: {results.Message}");
            }

            var migration = MigrationExtensions.GetMigration(latestChange.FileName, fileInfo);

            if (migration == null)
            {
                return($"Error: Unable to locate migration {latestChange.FileName}");
            }

            try
            {
                var instance = Activator.CreateInstance(migration);
                isMigrated = (bool)migration.GetMethod("Down")
                             .Invoke(instance, new[] { _mongoDbContext.Db });
            }
            catch (Exception e)
            {
                logPath = _logger.Log(migration.Name, e.ToString());
            }

            if (!isMigrated)
            {
                return($"Error: {migration.Name} was not migrated successfully. See {logPath} for more details.");
            }

            var deleteResult = changeLogCollection.Delete(latestChange);

            if (deleteResult == 0)
            {
                return($"Error: {migration.Name} was not downgraded");
            }

            return($"Downgraded: {migration.Name}");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Executes the migration's up function to upgrade the database
        /// based on it's current changelog
        /// </summary>
        /// <returns></returns>
        public string Execute()
        {
            var fileInfo = new FileInfo(_projectFile);

            // check changelog for the latest migration run
            var changeLogCollection = new ChangelogCollection(_mongoDbContext);

            var changeLog    = changeLogCollection.All();
            var latestChange = changeLog.GetLatestChange();

            // get all classes in a namespace from project assembly
            var workingDirectory = fileInfo.Directory.FullName;

            // create build command for project where migrations are created
            var runner = CLI.DotNet(x => x.WorkingDirectory = workingDirectory)
                         .Build(x => x.BuildConfiguration = BuildConfiguration.Debug)
                         .Create();
            // run command
            var results = runner.Run();

            if (!results.IsSuccessful)
            {
                return($"Error: {fileInfo.Name} failed to build with the following errors: {results.Message}");
            }

            var migrations = MigrationExtensions.GetMigrationTypes(fileInfo);

            if (migrations.Count == 0)
            {
                return("Error: No migration files found in project");
            }

            var remainingMigrations = migrations.GetRange(0, migrations.Count);

            // grab the latest changes if any migrations were previously executed
            if (latestChange != null)
            {
                remainingMigrations = migrations.GetRemainingMigrations(latestChange.FileName);
            }

            if (remainingMigrations.Count == 0)
            {
                return("The database is already up to date");
            }

            // string build result for multiple migrations
            var migrationResult = new StringBuilder();

            foreach (var migration in remainingMigrations)
            {
                var    isMigrated = false;
                string logPath    = string.Empty;

                try
                {
                    var instance = Activator.CreateInstance(migration);
                    isMigrated = (bool)migration.GetMethod("Up")
                                 .Invoke(instance, new[] { _mongoDbContext.Db });
                }
                catch (Exception e)
                {
                    logPath = _logger.Log(migration.Name, e.ToString());
                }

                if (!isMigrated)
                {
                    return($"Error: {migration.Name} was not migrated successfully. See {logPath} for more details.");
                }

                changeLogCollection.Insert(new Changelog
                {
                    AppliedAt = DateTime.Now,
                    FileName  = migration.Name
                });
                migrationResult.AppendLine($"Migrated: {migration.Name}");
            }

            if (migrationResult.Length > 0)
            {
                return(migrationResult.ToString());
            }

            return("Error: Unable to location migrations to be executed. Verify that a Migrations directory exists in your project");
        }