예제 #1
0
 /// <summary>
 /// The post analytic info.
 /// </summary>
 /// <param name="record">
 /// The record.
 /// </param>
 public async void PostAnalyticInfo(MigrationRecord record)
 {
     if (!MerchelloConfiguration.Current.Section.EnableInstallTracking) return;
     
     var client = new HttpClient();
     
     try
     {
         var data = JsonConvert.SerializeObject(record);
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         await client.PostAsync(PostUrl, new StringContent(data, Encoding.UTF8, "application/json"));
     }
     catch (Exception ex)
     {
         LogHelper.Error<WebMigrationManager>("Migration record post exception", ex);
     }
     finally
     {
         if (client != null)
         {
             client.Dispose();
             client = null;
         } 
     }
     
 }
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info<CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current);

                    bool upgraded;
                    try
                    {
                        foreach (var m in migrations)
                        {
                            m.Up();
                        }

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error<CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }

                    //var entryService = ApplicationContext.Current.Services.MigrationEntryService;

                    //var runner = new MigrationRunner(
                    //    entryService,
                    //    _logger,
                    //    new SemVersion(MerchelloConfiguration.ConfigurationStatusVersion),
                    //    new SemVersion(MerchelloVersion.Current),
                    //    MerchelloConfiguration.MerchelloMigrationName);

                    //var upgraded = runner.Execute(database);

                    if (upgraded)
                    {
                        var migrationKey = this.EnsureMigrationKey(schemaResult);

                        var record = new MigrationRecord()
                                         {
                                             MigrationKey = migrationKey,
                                             CurrentVersion = dbVersion.ToString(),
                                             TargetVersion = MerchelloVersion.Current.ToString(),
                                             DbProvider = database.GetDatabaseProvider().ToString(),
                                             InstallDate = DateTime.Now,
                                             IsUpgrade = true
                                         };

                        this.OnUpgraded(record);

                        _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully");
                    }

                    _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }
            else
            {
                    // this is a new install
                    var migrationKey = this.EnsureMigrationKey(schemaResult);

                    var record = new MigrationRecord()
                                     {
                                         MigrationKey = migrationKey,
                                         CurrentVersion = MerchelloConfiguration.ConfigurationStatus,
                                         TargetVersion = MerchelloVersion.Current.ToString(),
                                         DbProvider = database.GetDatabaseProvider().ToString(),
                                         InstallDate = DateTime.Now,
                                         IsUpgrade = !MerchelloConfiguration.ConfigurationStatus.Equals("0.0.0")
                                     };
                    this.OnUpgraded(record);
            }

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return true;
        }
 /// <summary>
 /// The on upgraded.
 /// </summary>
 /// <param name="record">
 /// The record.
 /// </param>
 private void OnUpgraded(MigrationRecord record)
 {
     if (Upgraded != null)
     {
         Upgraded(this, new MerchelloMigrationEventArgs(record));
     }
 }
예제 #4
0
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            var upgraded = false;

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info<CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current).ToList();

                    var context = InitializeMigrations(migrations, _database, _database.GetDatabaseProvider());

                    try
                    {
                        ExecuteMigrations(context, _database);

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error<CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }

                    _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }

            var currentVersion = dbVersion.ToString();

            if (!upgraded)
            {
                currentVersion = MerchelloConfiguration.ConfigurationStatusVersion.ToString();
            }

            var migrationKey = this.EnsureMigrationKey(schemaResult);

            var record = new MigrationRecord()
            {
                MigrationKey = migrationKey,
                CurrentVersion = currentVersion,
                TargetVersion = MerchelloVersion.Current.ToString(),
                DbProvider = database.GetDatabaseProvider().ToString(),
                InstallDate = DateTime.Now,
                IsUpgrade = currentVersion != "0.0.0"
            };

            this.OnUpgraded(record);

            _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully");

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return true;
        }
예제 #5
0
        /// <summary>
        /// Posts the migration analytic record.
        /// </summary>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task<HttpResponseMessage> PostAnalyticInfo(MigrationRecord record)
        {
            if (!MerchelloConfiguration.Current.Section.EnableInstallTracking)
                return new HttpResponseMessage(HttpStatusCode.OK);

            // reset the domain analytic
            if (MerchelloContext.HasCurrent)
            {
                var storeSettingService = MerchelloContext.Current.Services.StoreSettingService;

                var setting = storeSettingService.GetByKey(Constants.StoreSettingKeys.HasDomainRecordKey);
                if (setting != null)
                {
                    setting.Value = false.ToString();
                }

                storeSettingService.Save(setting);
            }

            var data = JsonConvert.SerializeObject(record);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage responseMessage = null;
                try
                {
                    responseMessage = await client.PostAsync(PostUrl, new StringContent(data, Encoding.UTF8, "application/json"));
                }
                catch (Exception ex)
                {
                    if (responseMessage == null)
                    {
                        responseMessage = new HttpResponseMessage();
                    }

                    responseMessage.StatusCode = HttpStatusCode.InternalServerError;
                    responseMessage.ReasonPhrase = string.Format("PostAnalyticInfo failed: {0}", ex);
                }

                return responseMessage;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MerchelloMigrationEventArgs"/> class.
 /// </summary>
 /// <param name="record">
 /// The record.
 /// </param>
 public MerchelloMigrationEventArgs(MigrationRecord record)
 {
     MigrationRecord = record;
 }
예제 #7
0
        //[Test]
        public void Can_CreateAMigrationRecord()
        {
            var record = new MigrationRecord();

            Assert.NotNull(record);
        }