Exemplo n.º 1
0
        public void Resolve_MissingView_Exception()
        {
            TemplateResolver resolver = new TemplateResolver();

            string path = resolver.Resolve("does_not_exist.html");

            Assert.Fail();
        }
Exemplo n.º 2
0
        public void Resolve_ExistingView_Found()
        {
            TemplateResolver resolver = new TemplateResolver();

            string path = resolver.Resolve("index.html");

            Assert.IsNotNull(path);
        }
        private bool SupportsTag(IContent content, string tag)
        {
            var templateModel = _templateResolver.Resolve(HttpContext,
                                                          content.GetOriginalType(),
                                                          content,
                                                          TemplateTypeCategories.MvcPartial,
                                                          tag);

            return(templateModel != null);
        }
Exemplo n.º 4
0
        public virtual void Render(HtmlHelper helper, ContentArea contentArea)
        {
            var contents = (_contentRequestContext.IsInEditMode(helper.ViewContext.HttpContext)
                                ? contentArea.Contents
                                : contentArea.FilteredContents).ToArray();

            foreach (var content in contents)
            {
                var templateModel = _templateResolver.Resolve(helper.ViewContext.HttpContext,
                                                              content.GetOriginalType(), content,
                                                              TemplateTypeCategories.MvcPartial, null);

                using (new ContentAreaContext(helper.ViewContext.RequestContext, content.ContentLink))
                {
                    helper.RenderContentData(content, true, templateModel, _contentRenderer);
                }
            }
        }
Exemplo n.º 5
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            var filesInPackage   = !string.IsNullOrWhiteSpace(pathToPackage);
            var environment      = AwsEnvironmentGeneration.Create(log, variables).GetAwaiter().GetResult();
            var templateResolver = new TemplateResolver(fileSystem);

            IAmazonCloudFormation ClientFactory() => ClientHelpers.CreateCloudFormationClient(environment);
            StackArn StackProvider(RunningDeployment x) => new StackArn(stackName);
            ChangeSetArn ChangesetProvider(RunningDeployment x) => new ChangeSetArn(x.Variables[AwsSpecialVariables.CloudFormation.Changesets.Arn]);
            string RoleArnProvider(RunningDeployment x) => x.Variables[AwsSpecialVariables.CloudFormation.RoleArn];

            var iamCapabilities = JsonConvert.DeserializeObject <List <string> >(variables.Get(AwsSpecialVariables.IamCapabilities, "[]"));

            CloudFormationTemplate TemplateFactory()
            {
                var resolvedTemplate   = templateResolver.Resolve(templateFile, filesInPackage, variables);
                var resolvedParameters = templateResolver.MaybeResolve(templateParameterFile, filesInPackage, variables);

                if (templateParameterFile != null && !resolvedParameters.Some())
                {
                    throw new CommandException("Could not find template parameters file: " + templateParameterFile);
                }

                var parameters = CloudFormationParametersFile.Create(resolvedParameters, fileSystem, variables);

                return(CloudFormationTemplate.Create(resolvedTemplate, parameters, fileSystem, variables));
            }

            var stackEventLogger = new StackEventLogger(log);

            var conventions = new List <IConvention>
            {
                new LogAwsUserInfoConvention(environment),
                new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)),

                //Create or Update the stack using changesets
                new AggregateInstallationConvention(
                    new GenerateCloudFormationChangesetNameConvention(log),
                    new CreateCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, RoleArnProvider, TemplateFactory, iamCapabilities),
                    new DescribeCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider),
                    new ExecuteCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider, waitForComplete)
                    .When(ImmediateChangesetExecution),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    .When(ImmediateChangesetExecution)
                    ).When(ChangesetsEnabled),

                //Create or update stack using a template (no changesets)
                new AggregateInstallationConvention(
                    new  DeployAwsCloudFormationConvention(
                        ClientFactory,
                        TemplateFactory,
                        stackEventLogger,
                        StackProvider,
                        RoleArnProvider,
                        waitForComplete,
                        stackName,
                        iamCapabilities,
                        disableRollback,
                        environment),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    )
                .When(ChangesetsDisabled)
            };

            var deployment       = new RunningDeployment(pathToPackage, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            conventionRunner.RunConventions();
            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);
            if (variablesFile != null && !File.Exists(variablesFile))
            {
                throw new CommandException("Could not find variables file: " + variablesFile);
            }

            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile,
                                                           sensitiveVariablesPassword);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var filesInPackage   = !string.IsNullOrWhiteSpace(packageFile);
            var environment      = new AwsEnvironmentGeneration(variables);
            var templateResolver = new TemplateResolver(fileSystem);

            IAmazonCloudFormation ClientFactory() => ClientHelpers.CreateCloudFormationClient(environment);
            StackArn StackProvider(RunningDeployment x) => new StackArn(stackName);
            ChangeSetArn ChangesetProvider(RunningDeployment x) => new ChangeSetArn(x.Variables[AwsSpecialVariables.CloudFormation.Changesets.Arn]);
            string RoleArnProvider(RunningDeployment x) => x.Variables[AwsSpecialVariables.CloudFormation.RoleArn];

            CloudFormationTemplate TemplateFactory()
            {
                var resolvedTemplate   = templateResolver.Resolve(templateFile, filesInPackage, variables);
                var resolvedParameters = templateResolver.MaybeResolve(templateParameterFile, filesInPackage, variables);

                if (templateParameterFile != null && !resolvedParameters.Some())
                {
                    throw new CommandException("Could not find template parameters file: " + templateParameterFile);
                }

                var parameters = CloudFormationParametersFile.Create(resolvedParameters, fileSystem, variables);

                return(CloudFormationTemplate.Create(resolvedTemplate, parameters, fileSystem, variables));
            }

            var stackEventLogger = new StackEventLogger(new LogWrapper());

            var conventions = new List <IConvention>
            {
                new LogAwsUserInfoConvention(environment),
                new ContributeEnvironmentVariablesConvention(),
                new LogVariablesConvention(),
                new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem),

                //Create or Update the stack using changesets
                new AggregateInstallationConvention(
                    new GenerateCloudFormationChangesetNameConvention(),
                    new CreateCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, RoleArnProvider, TemplateFactory, iamCapabilities),
                    new DescribeCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider),
                    new ExecuteCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider, waitForComplete)
                    .When(ImmediateChangesetExecution),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    .When(ImmediateChangesetExecution)
                    ).When(ChangesetsEnabled),

                //Create or update stack using a template (no changesets)
                new AggregateInstallationConvention(
                    new  DeployAwsCloudFormationConvention(
                        ClientFactory,
                        TemplateFactory,
                        stackEventLogger,
                        StackProvider,
                        RoleArnProvider,
                        waitForComplete,
                        stackName,
                        iamCapabilities,
                        disableRollback,
                        environment),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    )
                .When(ChangesetsDisabled)
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            conventionRunner.RunConventions();
            return(0);
        }