Exemplo n.º 1
0
        private void RebuildDatabaseCacheIfSerializerChanged()
        {
            var serializer        = ConfigurationManager.AppSettings[Nucache_Serializer_Key];
            var currentSerializer = _keyValueService.GetValue(Nucache_Serializer_Key);

            if (currentSerializer == null)
            {
                currentSerializer = JSON_SERIALIZER_VALUE;
            }
            if (serializer == null)
            {
                serializer = JSON_SERIALIZER_VALUE;
            }

            if (serializer != currentSerializer)
            {
                _profilingLogger.Warn <NuCacheSerializerComponent>($"Database NuCache was serialized using {currentSerializer}. Currently configured NuCache serializer {serializer}. Rebuilding Nucache");

                using (_profilingLogger.TraceDuration <NuCacheSerializerComponent>($"Rebuilding NuCache database with {currentSerializer} serializer"))
                {
                    _service.Value.Rebuild();
                    _keyValueService.SetValue(Nucache_Serializer_Key, serializer);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes.
        /// </summary>
        /// <param name="scopeProvider">A scope provider.</param>
        /// <param name="migrationBuilder">A migration builder.</param>
        /// <param name="keyValueService">A key-value service.</param>
        /// <param name="logger">A logger.</param>
        public void Execute(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
        {
            if (scopeProvider == null)
            {
                throw new ArgumentNullException(nameof(scopeProvider));
            }
            if (migrationBuilder == null)
            {
                throw new ArgumentNullException(nameof(migrationBuilder));
            }
            if (keyValueService == null)
            {
                throw new ArgumentNullException(nameof(keyValueService));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            var plan = Plan;

            using (var scope = scopeProvider.CreateScope())
            {
                BeforeMigrations(scope, logger);

                // read current state
                var currentState = keyValueService.GetValue(StateValueKey);
                var forceState   = false;

                if (currentState == null)
                {
                    currentState = plan.InitialState;
                    forceState   = true;
                }

                // execute plan
                var state = plan.Execute(scope, currentState, migrationBuilder, logger);
                if (string.IsNullOrWhiteSpace(state))
                {
                    throw new Exception("Plan execution returned an invalid null or empty state.");
                }

                // save new state
                if (forceState)
                {
                    keyValueService.SetValue(StateValueKey, state);
                }
                else if (currentState != state)
                {
                    keyValueService.SetValue(StateValueKey, currentState, state);
                }

                AfterMigrations(scope, logger);

                scope.Complete();
            }
        }
Exemplo n.º 3
0
        public TelemetryLevel GetConsentLevel()
        {
            var analyticsLevelString = _keyValueService.GetValue(Key);

            if (analyticsLevelString is null || Enum.TryParse(analyticsLevelString, out TelemetryLevel analyticsLevel) is false)
            {
                return(TelemetryLevel.Basic);
            }

            return(analyticsLevel);
        }
        private EnterspeedUmbracoConfiguration GetConfigurationFromDatabase()
        {
            var savedConfigurationValue = _keyValueService.GetValue(_configurationDatabaseKey);

            if (string.IsNullOrWhiteSpace(savedConfigurationValue))
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <EnterspeedUmbracoConfiguration>(savedConfigurationValue));
        }
        public void Initialize()
        {
            // a quick version of only run once.
            // for a more complete set of methods see Migrations samples
            var installed = keyValueService.GetValue(setupKey);

            if (installed == null || installed != "installed")
            {
                AddSection("admin", CustomSection.SectionAlias);
                keyValueService.SetValue(setupKey, "installed");
            }
        }
Exemplo n.º 6
0
        public void RebuildDatabaseCacheIfSerializerChanged()
        {
            NuCacheSerializerType serializer = _nucacheSettings.Value.NuCacheSerializerType;
            var currentSerializerValue       = _keyValueService.GetValue(NuCacheSerializerKey);

            if (!Enum.TryParse(currentSerializerValue, out NuCacheSerializerType currentSerializer) ||
                serializer != currentSerializer)
            {
                _logger.LogWarning("Database NuCache was serialized using {CurrentSerializer}. Currently configured NuCache serializer {Serializer}. Rebuilding Nucache", currentSerializer, serializer);

                using (_profilingLogger.TraceDuration <NuCacheContentService>($"Rebuilding NuCache database with {serializer} serializer"))
                {
                    Rebuild();
                    _keyValueService.SetValue(NuCacheSerializerKey, serializer.ToString());
                }
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc/>
        public void Handle(UmbracoApplicationStartingNotification notification)
        {
            if (notification.RuntimeLevel == Umbraco.Cms.Core.RuntimeLevel.Run)
            {
                var firstBootMigration = new FirstBootMigrationPlan();
                var upgrader           = new Upgrader(firstBootMigration);

                // this bit is done inside the upgrader.Execute method too,
                // but we don't want the extra three log messages during startup,
                // so we also check before we start
                var currentState = _keyValueService.GetValue(upgrader.StateValueKey);
                if (currentState == null || currentState != firstBootMigration.FinalState)
                {
                    upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService);
                }
            }
        }
        public HttpResponseMessage GetConfig()
        {
            var settings = _keyValueService.GetValue("redirectSettings_" + _key);

            RedirectSettings model;

            if (settings != null)
            {
                model = JsonConvert.DeserializeObject <RedirectSettings>(settings);
            }
            else
            {
                model = CreateEmptySettings();
            }


            return(Request.CreateResponse(HttpStatusCode.OK, model));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Executes a db migration to install the UmbracoIdentity DB schema if required
        /// </summary>
        private void EnsureDatabaseSchema()
        {
            // migrate database schema
            var upgrader = new Upgrader(new UmbracoIdentityMigrationPlan());

            // check if we need to execute
            // TODO: This logic should be better built into Umbraco (i.e. Package Migrations)
            // NOTE: The actual migration logic will not execute if the final migration step is detected from within upgrader.Execute, however getting to that point
            // allocates more objects than we need so it's actually slightly faster to do this up-front check first
            var stateValueKey       = upgrader.StateValueKey;
            var currMigrationState  = _keyValueService.GetValue(stateValueKey);
            var finalMigrationState = upgrader.Plan.FinalState;
            var needsUpgrade        = currMigrationState != finalMigrationState;

            _logger.Debug <UmbracoIdentityComponent>("Final upgrade state is {FinalMigrationState}, database contains {DatabaseState}, needs upgrade? {NeedsUpgrade}", finalMigrationState, currMigrationState ?? "<null>", needsUpgrade);

            if (needsUpgrade)
            {
                upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
            }
        }
Exemplo n.º 10
0
        public void CanExecute()
        {
            NullLoggerFactory loggerFactory = NullLoggerFactory.Instance;

            var            database = new TestDatabase();
            IDatabaseScope scope    = Mock.Of <IDatabaseScope>(x => x.Notifications == Mock.Of <IScopedNotificationPublisher>());

            Mock.Get(scope)
            .Setup(x => x.Database)
            .Returns(database);

            var sqlContext    = new SqlContext(new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())), DatabaseType.SQLCe, Mock.Of <IPocoDataFactory>());
            var scopeProvider = new MigrationTests.TestScopeProvider(scope)
            {
                SqlContext = sqlContext
            };

            IMigrationBuilder migrationBuilder = Mock.Of <IMigrationBuilder>();

            Mock.Get(migrationBuilder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case "DeleteRedirectUrlTable":
                    return(new DeleteRedirectUrlTable(c));

                case "NoopMigration":
                    return(new NoopMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            var executor = new MigrationPlanExecutor(scopeProvider, scopeProvider, loggerFactory, migrationBuilder);

            MigrationPlan plan = new MigrationPlan("default")
                                 .From(string.Empty)
                                 .To <DeleteRedirectUrlTable>("{4A9A1A8F-0DA1-4BCF-AD06-C19D79152E35}")
                                 .To <NoopMigration>("VERSION.33");

            IKeyValueService kvs = Mock.Of <IKeyValueService>();

            Mock.Get(kvs).Setup(x => x.GetValue(It.IsAny <string>()))
            .Returns <string>(k => k == "Umbraco.Tests.MigrationPlan" ? string.Empty : null);

            string state;

            using (IScope s = scopeProvider.CreateScope())
            {
                // read current state
                var sourceState = kvs.GetValue("Umbraco.Tests.MigrationPlan") ?? string.Empty;

                // execute plan
                state = executor.Execute(plan, sourceState);

                // save new state
                kvs.SetValue("Umbraco.Tests.MigrationPlan", sourceState, state);

                s.Complete();
            }

            Assert.AreEqual("VERSION.33", state);
            Assert.AreEqual(1, database.Operations.Count);
            Assert.AreEqual("DROP TABLE [umbracoRedirectUrl]", database.Operations[0].Sql);
        }