Esempio n. 1
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);
        }
Esempio n. 2
0
        public static async Task <int> Instantiate(string templateName, string name, string fallbackName, bool createDir, string aliasName, IReadOnlyDictionary <string, string> inputParameters, bool skipUpdateCheck)
        {
            ITemplateInfo templateInfo;

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

            // SettingsLoader.LoadTemplate is where the loc info should be read!!!
            // templateInfo knows enough to get at the loc, if any
            ITemplate template = SettingsLoader.LoadTemplate(templateInfo);

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

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

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

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

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

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

            ICreationResult creationResult;

            try
            {
                Stopwatch         sw = Stopwatch.StartNew();
                IComponentManager componentManager = Settings.SettingsLoader.Components;
                await template.Generator.Create(template, templateParams, componentManager, out creationResult);

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

            // TODO: pass back the creationResult (probably as an out param)
            // (and get rid of this debugging)
            creationResult.TEMP_CONSOLE_DEBUG_CreationResult();

            return(0);
        }
Esempio n. 3
0
        private async Task <CreationResultStatus> EnterSingularTemplateManipulationFlowAsync()
        {
            if (!string.IsNullOrWhiteSpace(Alias))
            {
                if (!ValidateRemainingParameters())
                {
                    ShowUsageHelp();
                    return(CreationResultStatus.InvalidParamValues);
                }

                _aliasRegistry.SetTemplateAlias(Alias, UnambiguousTemplateToUse.Info);
                Reporter.Output.WriteLine(LocalizableStrings.AliasCreated);
                return(CreationResultStatus.Success);
            }
            else if (IsListFlagSpecified)
            {
                if (!ValidateRemainingParameters())
                {
                    ShowUsageHelp();
                    return(CreationResultStatus.InvalidParamValues);
                }

                DisplayTemplateList();
                return(CreationResultStatus.Success);
            }

            //If we've made it here, we need the actual template's args
            string commandParseFailureMessage = null;

            try
            {
                ParseTemplateArgs(UnambiguousTemplateToUse.Info);
            }
            catch (CommandParserException ex)
            {
                commandParseFailureMessage = ex.Message;
            }

            bool argsError = !ValidateRemainingParameters();

            if (argsError || IsHelpFlagSpecified)
            {
                if (argsError)
                {
                    Reporter.Error.WriteLine(commandParseFailureMessage.Bold().Red());
                }

                ShowUsageHelp();
                ShowTemplateHelp();
                return(argsError ? CreationResultStatus.InvalidParamValues : CreationResultStatus.Success);
            }
            else
            {
                try
                {
                    return(await CreateTemplateAsync(UnambiguousTemplateToUse.Info).ConfigureAwait(false));
                }
                catch (ContentGenerationException cx)
                {
                    Reporter.Error.WriteLine(cx.Message.Bold().Red());
                    if (cx.InnerException != null)
                    {
                        Reporter.Error.WriteLine(cx.InnerException.Message.Bold().Red());
                    }

                    return(CreationResultStatus.CreateFailed);
                }
                catch (Exception ex)
                {
                    Reporter.Error.WriteLine(ex.Message.Bold().Red());
                }

                return(CreationResultStatus.CreateFailed);
            }
        }