private static IReadOnlyList <IOperationProvider> SetupCustomOperations(IReadOnlyList <ICustomOperationModel> customModel, IDirectory templateRoot, IVariableCollection variables)
        {
            ITemplateEngineHost       host             = templateRoot.MountPoint.EnvironmentSettings.Host;
            List <IOperationProvider> customOperations = new List <IOperationProvider>();

            foreach (ICustomOperationModel opModelUntyped in customModel)
            {
                CustomOperationModel opModel = opModelUntyped as CustomOperationModel;
                if (opModel == null)
                {
                    host.LogMessage($"Operation type = [{opModelUntyped.Type}] could not be cast as a CustomOperationModel");
                    continue;
                }

                string opType    = opModel.Type;
                string condition = opModel.Condition;

                if (string.IsNullOrEmpty(condition) ||
                    CppStyleEvaluatorDefinition.EvaluateFromString(templateRoot.MountPoint.EnvironmentSettings, condition, variables))
                {
                    IOperationConfig realConfigObject;
                    if (_operationConfigLookup.TryGetValue(opType, out realConfigObject))
                    {
                        customOperations.AddRange(
                            realConfigObject.ConfigureFromJObject(opModel.Configuration, templateRoot));
                    }
                    else
                    {
                        host.LogMessage($"Operation type = [{opType}] from configuration is unknown.");
                    }
                }
            }

            return(customOperations);
        }
예제 #2
0
        public static async Task <int> Instantiate(ITemplateEngineHost host, string templateName, string name, string fallbackName, bool createDir, string aliasName, IReadOnlyDictionary <string, string> inputParameters, bool skipUpdateCheck)
        {
            ITemplateInfo templateInfo;

            using (Timing.Over("Get single"))
            {
                if (!TryGetTemplate(templateName, out templateInfo))
                {
                    return(-1);
                }
            }

            ITemplate template = SettingsLoader.LoadTemplate(templateInfo);

            if (!skipUpdateCheck)
            {
                host.LogMessage("Checking for updates...");

                //UpdateCheck();    // this'll need params
            }

            string        realName       = name ?? template.DefaultName ?? fallbackName;
            IParameterSet templateParams = SetupDefaultParamValuesFromTemplateAndHost(host, template, realName);

            if (aliasName != null)
            {
                //TODO: Add parameters to aliases (from _parameters_ collection)
                AliasRegistry.SetTemplateAlias(aliasName, template);
                host.LogMessage("Alias created.");
                return(0);
            }

            ResolveUserParameters(template, templateParams, inputParameters);
            bool missingParams = CheckForMissingRequiredParameters(host, templateParams);

            if (missingParams)
            {
                return(missingParams ? -1 : 0);
            }

            try
            {
                Stopwatch sw = Stopwatch.StartNew();
                // todo: pass an implementation of ITemplateEngineHost
                IComponentManager componentManager = Settings.SettingsLoader.Components;
                await template.Generator.Create(host, template, templateParams, componentManager);

                sw.Stop();
                host.OnTimingCompleted("Content generation time", sw.Elapsed);
            }
            finally
            {
            }

            return(0);
        }
예제 #3
0
        public void TEMP_CONSOLE_DEBUG_CreationResult()
        {
            ITemplateEngineHost host = EngineEnvironmentSettings.Host;

            foreach (IPostAction postActionInfo in PostActions)
            {
                host.LogMessage(string.Format("Placeholder for post action processing of action: {0}", postActionInfo.Description));

                host.LogMessage(string.Format("\tActionId: {0}", postActionInfo.ActionId));
                host.LogMessage(string.Format("\tContinueOnError: {0}", postActionInfo.ContinueOnError));
                host.LogMessage(string.Format("\tConfigFile: {0}", postActionInfo.ConfigFile));
                host.LogMessage(string.Format("\tManual Instructions: {0}", postActionInfo.ManualInstructions));
                host.LogMessage(string.Format("\tArgs"));

                foreach (KeyValuePair <string, string> arg in postActionInfo.Args)
                {
                    host.LogMessage(string.Format("\t\tKey = {0} | Value = {1}", arg.Key, arg.Value));
                }
            }

            host.LogMessage("Primary Outputs (artifacts)");
            foreach (ICreationPath pathInfo in PrimaryOutputs)
            {
                host.LogMessage(string.Format("\tPath: {0}", pathInfo.Path));
            }
        }
예제 #4
0
        public bool TryGetTemplateFromConfigInfo(IFileSystemInfo config, out ITemplate template, IFileSystemInfo localeConfig = null, IFile hostTemplateConfigFile = null)
        {
            IFile file = config as IFile;

            if (file == null)
            {
                template = null;
                return(false);
            }

            IFile localeFile = localeConfig as IFile;

            try
            {
                JObject srcObject = ReadJObjectFromIFile(file);

                JObject localeSourceObject = null;
                if (localeFile != null)
                {
                    localeSourceObject = ReadJObjectFromIFile(localeFile);
                }

                SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(file.MountPoint.EnvironmentSettings, srcObject, localeSourceObject);
                template = new RunnableProjectTemplate(srcObject, this, file, templateModel, null, hostTemplateConfigFile);
                return(true);
            }
            catch (Exception ex)
            {
                ITemplateEngineHost host = config.MountPoint.EnvironmentSettings.Host;
                host.LogMessage($"Error reading template from file: {file.FullPath} | Error = {ex.ToString()}");
            }

            template = null;
            return(false);
        }
        public bool TryGetTemplateFromConfigInfo(IFileSystemInfo templateFileConfig, out ITemplate template, IFileSystemInfo localeFileConfig = null, IFile hostTemplateConfigFile = null, string baselineName = null)
        {
            IFile templateFile = templateFileConfig as IFile;

            if (templateFile == null)
            {
                template = null;
                return(false);
            }

            IFile localeFile         = localeFileConfig as IFile;
            ITemplateEngineHost host = templateFileConfig.MountPoint.EnvironmentSettings.Host;

            try
            {
                JObject baseSrcObject = ReadJObjectFromIFile(templateFile);
                JObject srcObject     = MergeAdditionalConfiguration(baseSrcObject, templateFileConfig);

                JObject localeSourceObject = null;
                if (localeFile != null)
                {
                    localeSourceObject = ReadJObjectFromIFile(localeFile);
                }

                ISimpleConfigModifiers configModifiers = new SimpleConfigModifiers()
                {
                    BaselineName = baselineName
                };
                SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(templateFile.MountPoint.EnvironmentSettings, srcObject, configModifiers, localeSourceObject);

                if (!PerformTemplateValidation(templateModel, templateFile, host))
                {
                    template = null;
                    return(false);
                }

                if (!CheckGeneratorVersionRequiredByTemplate(templateModel.GeneratorVersions))
                {   // template isn't compatible with this generator version
                    template = null;
                    return(false);
                }

                RunnableProjectTemplate runnableProjectTemplate = new RunnableProjectTemplate(srcObject, this, templateFile, templateModel, null, hostTemplateConfigFile);
                if (!AreAllTemplatePathsValid(templateModel, runnableProjectTemplate))
                {
                    template = null;
                    return(false);
                }

                template = runnableProjectTemplate;
                return(true);
            }
            catch (Exception ex)
            {
                host.LogMessage($"Error reading template from file: {templateFile.FullPath} | Error = {ex.Message}");
            }

            template = null;
            return(false);
        }
        private bool TryGetLangPackFromFile(IFile file, out ILocalizationModel locModel)
        {
            if (file == null)
            {
                locModel = null;
                return(false);
            }

            try
            {
                JObject srcObject = ReadJObjectFromIFile(file);
                locModel = SimpleConfigModel.LocalizationFromJObject(srcObject);
                return(true);
            }
            catch (Exception ex)
            {
                ITemplateEngineHost host = file.MountPoint.EnvironmentSettings.Host;
                host.LogMessage($"Error reading Langpack from file: {file.FullPath} | Error = {ex.ToString()}");
            }

            locModel = null;
            return(false);
        }
예제 #7
0
 public virtual void LogMessage(string message) => _baseHost.LogMessage(message);
        public bool TryGetTemplateFromConfigInfo(IFileSystemInfo templateFileConfig, out ITemplate template, IFileSystemInfo localeFileConfig = null, IFile hostTemplateConfigFile = null, string baselineName = null)
        {
            IFile templateFile = templateFileConfig as IFile;

            if (templateFile == null)
            {
                template = null;
                return(false);
            }

            IFile localeFile         = localeFileConfig as IFile;
            ITemplateEngineHost host = templateFileConfig.MountPoint.EnvironmentSettings.Host;

            try
            {
                JObject baseSrcObject = ReadJObjectFromIFile(templateFile);
                JObject srcObject     = MergeAdditionalConfiguration(baseSrcObject, templateFileConfig);

                JObject localeSourceObject = null;
                if (localeFile != null)
                {
                    localeSourceObject = ReadJObjectFromIFile(localeFile);
                }

                ISimpleConfigModifiers configModifiers = new SimpleConfigModifiers()
                {
                    BaselineName = baselineName
                };
                SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(templateFile.MountPoint.EnvironmentSettings, srcObject, configModifiers, localeSourceObject);

                if (!PerformTemplateValidation(templateModel, templateFile, host))
                {
                    template = null;
                    return(false);
                }

                if (!CheckGeneratorVersionRequiredByTemplate(templateModel.GeneratorVersions))
                {   // template isn't compatible with this generator version
                    template = null;
                    return(false);
                }

                RunnableProjectTemplate runnableProjectTemplate = new RunnableProjectTemplate(srcObject, this, templateFile, templateModel, null, hostTemplateConfigFile);
                if (!AreAllTemplatePathsValid(templateModel, runnableProjectTemplate))
                {
                    template = null;
                    return(false);
                }

                // Record the timestamp of the template file so we
                // know to reload it if it changes
                if (templateFile.MountPoint.Info.MountPointFactoryId == FileSystemMountPointFactoryId &&
                    host.FileSystem is IFileLastWriteTimeSource timeSource)
                {
                    var physicalPath = Path.Combine(templateFile.MountPoint.Info.Place, templateFile.FullPath.TrimStart('/'));
                    runnableProjectTemplate.ConfigTimestampUtc = timeSource.GetLastWriteTimeUtc(physicalPath);
                }

                template = runnableProjectTemplate;
                return(true);
            }
            catch (Exception ex)
            {
                host.LogMessage($"Error reading template from file: {templateFile.FullPath} | Error = {ex.Message}");
            }

            template = null;
            return(false);
        }
예제 #9
0
 public void LogInformationSummary(string data)
 {
     _host.LogMessage(data);
 }