コード例 #1
0
ファイル: GenerationContext.cs プロジェクト: malain/candle
        /// <summary>
        /// Vérification si une stratégie n'a pas les droits de génération exclusif sur cet élément
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="strategy">The strategy.</param>
        /// <param name="generatedFileName">Name of the generated file.</param>
        /// <returns>
        ///     <c>true</c> if [is generation locked] [the specified element]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsGenerationLocked(ICustomizableElement element, StrategyBase strategy, string generatedFileName)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.BeginStep("Check generation lock", LogType.Debug);
                logger.Write("Check generation lock",
                             String.Concat("Current strategy ", strategy.StrategyId, " for outputfile ",
                                           generatedFileName ?? "(no file specified)"), LogType.Debug);
            }

            foreach (StrategyBase otherStrategy in element.GetStrategies(false))
            {
                if (strategy.StrategyId != otherStrategy.StrategyId &&
                    otherStrategy.IsModelGenerationExclusive(this, element, generatedFileName))
                {
                    if (logger != null)
                    {
                        logger.Write("Check generation lock",
                                     String.Format("Element {0} generation locked by strategy {1}", element.Name,
                                                   otherStrategy.StrategyId), LogType.Debug);
                        logger.EndStep();
                    }
                    return(true);
                }
            }

            if (logger != null)
            {
                logger.EndStep();
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Execute les stratégies de génération de projet
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="context">The context.</param>
        internal static void ApplyProjectGeneratorStrategies(ICustomizableElement element, GenerationContext context)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.BeginStep("Project generation " + element.Name, LogType.Info);
                logger.Write("Project generation", String.Concat("Current layer is ", element.Name, " (id=", element.Id, ")"), LogType.Debug);
            }
            IList <StrategyBase> strategies = element.GetStrategies(true);

            // D'abord exécution des stratégies générant les projets
            bool strategyFinding = false;

            foreach (StrategyBase strategy in strategies)
            {
                if (strategy is IStrategyProjectGenerator)
                {
                    strategyFinding = true;
                    try
                    {
                        strategy.InitializeContext(context, element);
                        ((IStrategyProjectGenerator)strategy).GenerateVSProject(element);
                        if (logger != null)
                        {
                            logger.Write("Project generation", String.Concat("Strategy '", strategy.DisplayName, "' id : ", strategy.StrategyId, " on layer ", element.Name), LogType.Debug);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (logger != null)
                        {
                            logger.WriteError("Project generation", String.Concat("Strategy '", strategy.DisplayName, "' id : ", strategy.StrategyId, " on layer ", element.Name, " See errors list"), ex);
                        }
                    }
                    finally
                    {
                        strategy.InitializeContext(null, null);
                    }
                }
            }
            if (logger != null)
            {
                if (!strategyFinding)
                {
                    logger.Write("Project generation", "No project generation finding", LogType.Warning);
                }
                logger.EndStep();
            }
        }
コード例 #3
0
        /// <summary>
        /// Applique les stratégies
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="context">The context.</param>
        internal static void ApplyStrategies(ICustomizableElement element, GenerationContext context)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.BeginStep("Strategy generation", LogType.Debug);
                logger.Write("Strategy generation", String.Concat("Current element is ", element.Name, " (id=", element.Id, ")"), LogType.Debug);
            }
            IList <StrategyBase> strategies = element.GetStrategies(true);

            // Execution des stratégies
            StrategyBase cfgStrategy = null;

            foreach (StrategyBase strategy in strategies)
            {
                if (strategy is IStrategyProjectGenerator)
                {
                    continue;
                }

                if (strategy is IStrategyConfigGenerator)
                {
                    cfgStrategy = strategy;
                    continue;
                }

                RunStrategy(element, context, strategy);
            }

            if (cfgStrategy != null)
            {
                RunStrategy(element, context, cfgStrategy);
            }

            if (logger != null)
            {
                logger.EndStep();
            }
        }
コード例 #4
0
        /// <summary>
        /// Applique les stratégies d'injection de code
        /// </summary>
        /// <param name="projectItem">The project item.</param>
        /// <param name="element">The element.</param>
        /// <param name="context">The context.</param>
        public static void ApplyCodeInjectionStrategies(ProjectItem projectItem, ICustomizableElement element, GenerationContext context)
        {
            ILogger logger = ServiceLocator.Instance.GetService <ILogger>();

            if (logger != null)
            {
                logger.BeginStep("Injection code generation", LogType.Info);
                logger.Write("Injection code generation", String.Concat("Current element is ", element.Name, " (id=", element.Id, ")"), LogType.Debug);
            }

            EnvDTE80.FileCodeModel2 fcm = null;
            if (projectItem != null)
            {
                fcm = projectItem.FileCodeModel as EnvDTE80.FileCodeModel2;
                if (fcm == null)
                {
                    if (logger != null)
                    {
                        logger.Write("Injection code generation", "No code model associated with this element - exit", LogType.Debug);
                        logger.EndStep();
                    }
                    return;
                }
                //fcm.BeginBatch();
            }

            try
            {
                CodeInjectionContext gc = new CodeInjectionContext(context);

                List <StrategyBase> strategies = new List <StrategyBase>();

                // Execution des stratégies
                foreach (StrategyBase strategy in element.GetStrategies(false))
                {
                    if (!(strategy is IStrategyCodeInjector))
                    {
                        continue;
                    }

                    if (logger != null)
                    {
                        logger.Write("Injection code generation", String.Concat("Strategy ", strategy.StrategyId), LogType.Debug);
                    }
                    if (context.SelectedStrategies != null && (context.SelectedStrategies != null && !context.SelectedStrategies.Contains(strategy)))
                    {
                        if (logger != null)
                        {
                            logger.Write("Injection code generation", "Strategy skipped because this is not a selected strategy", LogType.Debug);
                        }
                        continue;
                    }
                    strategies.Add(strategy);
                }

                // Tri dans l'ordre d'exécution
//                strategies.Sort(delegate(IStrategyCodeInjector a, IStrategyCodeInjector b) { return a.ExecutionOrder.CompareTo(b.ExecutionOrder); });

                foreach (StrategyBase injector in strategies)
                {
                    if (logger != null)
                    {
                        logger.BeginStep(String.Concat("Run strategy ", injector.DisplayName, " id=", injector.StrategyId), LogType.Debug);
                    }
                    gc.CurrentElement = element;
                    gc.Strategy       = (IStrategyCodeInjector)injector;

                    try
                    {
                        if (gc.GenerationContext.GenerationPass == GenerationPass.MetaModelUpdate)
                        {
                            ((IStrategyCodeInjector)injector).OnMetaModelUpdate(gc);
                        }
                        else
                        {
                            CodeModelWalker walker = new CodeModelWalker(new CodeInjectorVisitor(gc));
                            walker.Traverse(fcm);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (logger != null)
                        {
                            logger.WriteError(injector.DisplayName, "Code Injection error", ex);
                        }
                    }
                    finally
                    {
                        gc.Strategy       = null;
                        gc.CurrentElement = null;
                        if (logger != null)
                        {
                            logger.EndStep();
                        }
                    }
                }
            }
            finally
            {
                if (fcm != null)
                {
                    //    fcm.EndBatch();
                    //    fcm.Synchronize();
                }
            }
            if (logger != null)
            {
                logger.EndStep();
            }
        }