public static MacroProperty MakeNew(Macro macro, string alias, string name, string editorAlias)
        {
            //try to get the new mapped parameter editor
            var mapped = LegacyParameterEditorAliasConverter.GetNewAliasFromLegacyAlias(editorAlias, false);

            if (mapped.IsNullOrWhiteSpace() == false)
            {
                editorAlias = mapped;
            }

            int macroPropertyId = 0;

            // The method is synchronized
            using (var sqlHelper = Application.SqlHelper)
            {
                sqlHelper.ExecuteNonQuery(
                    "INSERT INTO cmsMacroProperty (macro, macropropertyAlias, macroPropertyName, editorAlias) VALUES (@macro, @alias, @name, @editorAlias)",
                    sqlHelper.CreateParameter("@macro", macro.Id),
                    sqlHelper.CreateParameter("@alias", alias),
                    sqlHelper.CreateParameter("@name", name),
                    sqlHelper.CreateParameter("@editorAlias", editorAlias));
                macroPropertyId = sqlHelper.ExecuteScalar <int>("SELECT MAX(id) FROM cmsMacroProperty");
                return(new MacroProperty(macroPropertyId));
            }
        }
        /// <summary>
        /// Ctor for creating a new property
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="name"></param>
        /// <param name="sortOrder"></param>
        /// <param name="editorAlias"></param>
        public MacroProperty(string @alias, string name, int sortOrder, string editorAlias)
        {
            _alias     = alias;
            _name      = name;
            _sortOrder = sortOrder;

            //try to get the new mapped parameter editor
            var mapped = LegacyParameterEditorAliasConverter.GetNewAliasFromLegacyAlias(editorAlias, false);

            if (mapped.IsNullOrWhiteSpace() == false)
            {
                editorAlias = mapped;
            }

            _editorAlias = editorAlias;
        }
Exemple #3
0
        public virtual IBootManager Initialize()
        {
            if (_isInitialized)
            {
                throw new InvalidOperationException("The boot manager has already been initialized");
            }

            InitializeLoggerResolver();
            InitializeProfilerResolver();

            ProfilingLogger = ProfilingLogger ?? new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler);

            _timer = ProfilingLogger.TraceDuration <CoreBootManager>(
                string.Format("Umbraco {0} application starting on {1}", UmbracoVersion.GetSemanticVersion().ToSemanticString(), NetworkHelper.MachineName),
                "Umbraco application startup complete");

            ApplicationCache = CreateApplicationCache();

            //create and set the plugin manager (I'd much prefer to not use this singleton anymore but many things are using it unfortunately and
            // the way that it is setup, there must only ever be one per app so without IoC it would be hard to make this not a singleton)
            PluginManager         = new PluginManager(ServiceProvider, ApplicationCache.RuntimeCache, ProfilingLogger);
            PluginManager.Current = PluginManager;

            //Create the legacy prop-eds mapping
            LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
            LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();

            //create database and service contexts for the app context
            var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, ProfilingLogger.Logger);

            Database.Mapper = new PetaPocoMapper();

            var scopeProvider = new ScopeProvider(dbFactory);

            dbFactory.ScopeProvider = scopeProvider;

            var dbContext = new DatabaseContext(
                scopeProvider,
                ProfilingLogger.Logger,
                SqlSyntaxProviders.CreateDefault(ProfilingLogger.Logger));

            //initialize the DatabaseContext
            dbContext.Initialize();

            //get the service context
            var serviceContext = CreateServiceContext(dbContext, scopeProvider);

            //set property and singleton from response
            ApplicationContext.Current = ApplicationContext = CreateApplicationContext(dbContext, serviceContext);

            InitializeApplicationEventsResolver();

            InitializeResolvers();

            InitializeModelMappers();

            using (ProfilingLogger.DebugDuration <CoreBootManager>(
                       string.Format("Executing {0} IApplicationEventHandler.OnApplicationInitialized", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()),
                       "Finished executing IApplicationEventHandler.OnApplicationInitialized"))
            {
                //now we need to call the initialize methods
                ApplicationEventsResolver.Current.ApplicationEventHandlers
                .ForEach(x =>
                {
                    try
                    {
                        using (ProfilingLogger.DebugDuration <CoreBootManager>(string.Format("Executing {0} in ApplicationInitialized", x.GetType())))
                        {
                            x.OnApplicationInitialized(UmbracoApplication, ApplicationContext);
                        }
                    }
                    catch (Exception ex)
                    {
                        ProfilingLogger.Logger.Error <CoreBootManager>("An error occurred running OnApplicationInitialized for handler " + x.GetType(), ex);
                        throw;
                    }
                });
            }

            _isInitialized = true;

            return(this);
        }
Exemple #4
0
        public override void Up()
        {
            //now that the controlId column is renamed and now a string we need to convert
            if (Context == null || Context.Database == null)
            {
                return;
            }

            //var cpt = SqlSyntaxContext.SqlSyntaxProvider.GetConstraintsPerTable(Context.Database);
            //var di = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database);

            if (Context.CurrentDatabaseProvider != DatabaseProviders.SqlServer)
            {
                Delete.DefaultConstraint().OnTable("cmsMacroProperty").OnColumn("macroPropertyHidden");
            }
            else
            {
                //If we are on SQLServer, we need to delete default constraints by name, older versions of umbraco did not name these default constraints
                // consistently so we need to look up the constraint name to delete, this only pertains to SQL Server and this issue:
                // http://issues.umbraco.org/issue/U4-4133
                var sqlServerSyntaxProvider = new SqlServerSyntaxProvider();
                var defaultConstraints      = sqlServerSyntaxProvider.GetDefaultConstraintsPerColumn(Context.Database).Distinct();

                //lookup the constraint we want to delete, normally would be called "DF_cmsMacroProperty_macroPropertyHidden" but
                // we cannot be sure with really old versions
                var constraint = defaultConstraints
                                 .SingleOrDefault(x => x.Item1 == "cmsMacroProperty" && x.Item2 == "macroPropertyHidden");
                if (constraint != null)
                {
                    Execute.Sql(string.Format("ALTER TABLE [{0}] DROP CONSTRAINT [{1}]", "cmsMacroProperty", constraint.Item3));
                }
            }

            Delete.Column("macroPropertyHidden").FromTable("cmsMacroProperty");

            if (Context.CurrentDatabaseProvider == DatabaseProviders.MySql)
            {
                Delete.ForeignKey().FromTable("cmsMacroProperty").ForeignColumn("macroPropertyType").ToTable("cmsMacroPropertyType").PrimaryColumn("id");
            }
            else
            {
                //Before we try to delete this constraint, we'll see if it exists first, some older schemas never had it and some older schema's had this named
                // differently than the default.

                var keyConstraints = SqlSyntax.GetConstraintsPerColumn(Context.Database).Distinct();
                var constraint     = keyConstraints
                                     .SingleOrDefault(x => x.Item1 == "cmsMacroProperty" && x.Item2 == "macroPropertyType" && x.Item3.InvariantStartsWith("PK_") == false);
                if (constraint != null)
                {
                    Delete.ForeignKey(constraint.Item3).OnTable("cmsMacroProperty");
                }
            }

            Alter.Table("cmsMacroProperty").AddColumn("editorAlias").AsString(255).NotNullable().WithDefaultValue("");

            //we need to get the data and create the migration scripts before we change the actual schema bits below!
            var list = Context.Database.Fetch <dynamic>("SELECT * FROM cmsMacroPropertyType");

            foreach (var item in list)
            {
                var alias = item.macroPropertyTypeAlias;
                //check if there's a map created
                var newAlias = (string)LegacyParameterEditorAliasConverter.GetNewAliasFromLegacyAlias(alias);
                if (newAlias.IsNullOrWhiteSpace() == false)
                {
                    alias = newAlias;
                }

                //update the table with the alias, the current macroPropertyType will contain the original id
                Update.Table("cmsMacroProperty").Set(new { editorAlias = alias }).Where(new { macroPropertyType = item.id });
            }

            //drop the column now
            Delete.Column("macroPropertyType").FromTable("cmsMacroProperty");

            //drop the default constraint
            Delete.DefaultConstraint().OnTable("cmsMacroProperty").OnColumn("editorAlias");
        }