public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     // You can disable dynamic templates completely, but 
     // then all convenience methods (Compile and RunCompile) with
     // a TemplateSource will no longer work (they are not really needed anyway).
     throw new NotImplementedException("dynamic templates are not supported!");
 }
예제 #2
0
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     if (!_templates.ContainsKey(key))
     {
         _templates.Add(key, source);
     }
 }
예제 #3
0
        /// <summary>
        /// Compiles the specified template.
        /// </summary>
        /// <param name="key">The string template.</param>
        /// <param name="source">The template content.</param>
        /// <param name="modelType">The model type.</param>
        public ICompiledTemplate Compile(ITemplateKey key, ITemplateSource source, Type modelType)
        {
            Contract.Requires(key != null);
            Contract.Requires(source != null);

            var result = CreateTemplateType(source, modelType);
            return new CompiledTemplate(result.Item2, key, source, result.Item1, modelType);
        }
 public void SetUp()
 {
     mailServiceMock = MockRepository.GenerateMock<IMailService>();
     templateEngineMock = MockRepository.GenerateMock<ITemplateEngine>();
     templateSourceMock = MockRepository.GenerateMock<ITemplateSource>();
     listener = new SendWelcomeEmailUserRegisteredEventListener(mailServiceMock, templateEngineMock,
                                                                templateSourceMock);
 }
 public void SetUp()
 {
     mailServiceMock = MockRepository.GenerateMock<IMailService>();
     templateEngineMock = MockRepository.GenerateMock<ITemplateEngine>();
     templateSourceMock = MockRepository.GenerateMock<ITemplateSource>();
     listener = new SendMailPasswordResettedEventListener(mailServiceMock, templateEngineMock,
                                                          templateSourceMock);
 }
예제 #6
0
 public CompiledTemplate(CompilationData tempFiles, ITemplateKey key, ITemplateSource source, Type templateType, Type modelType)
 {
     _tempFiles = tempFiles;
     _key = key;
     _source = source;
     _templateType = templateType;
     _modelType = modelType;
 }
 /// <summary>
 /// Initialises a new instance of <see cref="TemplateCompilationException"/>.
 /// </summary>
 /// <param name="errors">The set of compiler errors.</param>
 /// <param name="files">The source code that wasn't compiled.</param>
 /// <param name="template">The source template that wasn't compiled.</param>
 public TemplateCompilationException(IEnumerable<RazorEngineCompilerError> errors, CompilationData files, ITemplateSource template)
     : base(TemplateCompilationException.GetMessage(errors, files, template))
 {
     var list = errors.ToList();
     CompilerErrors = new ReadOnlyCollection<RazorEngineCompilerError>(list);
     CompilationData = files;
     Template = template.Template;
 }
예제 #8
0
 public TemplateHttpResponse(
     string templateText,
     string contentType,
     IDictionary properties)
 {
     this.template = new StringTemplate(templateText);
     this.contentType = contentType;
     this.properties = properties;
 }
예제 #9
0
 public TemplateHttpResponse(
     ITemplateSource templateSource,
     string contentType,
     IDictionary properties)
 {
     template = templateSource;
     this.contentType = contentType;
     this.properties = properties;
 }
 /// <summary>
 /// Adds a template dynamically.
 /// </summary>
 /// <param name="key">the key of the template</param>
 /// <param name="source">the source of the template</param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     _dynamicTemplates.AddOrUpdate(key, source, (k, oldSource) =>
     {
         if (oldSource.Template != source.Template)
         {
             throw new InvalidOperationException("The same key was used for another template!");
         }
         return source;
     });
 }
        /// <summary>
        /// Gets a exact error message of the given error collection
        /// </summary>
        /// <param name="errors"></param>
        /// <param name="files"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        internal static string GetMessage(IEnumerable<RazorEngineCompilerError> errors, CompilationData files, ITemplateSource template)
        {
            var errorMsgs = string.Join("\n\t", errors.Select(error =>
                string.Format(
                    " - {0}: ({1}, {2}) {3}", 
                    error.IsWarning ? "warning" : "error", 
                    error.Line, error.Column, error.ErrorText)));

            const string rawTemplateFileMsg = "The template-file we tried to compile is: {0}\n";
            const string rawTemplate = "The template we tried to compile is: {0}\n";
            const string rawTmpFiles = "Temporary files of the compilation can be found in (please delete the folder): {0}\n";
            const string rawSourceCode = "The generated source code is: {0}\n";

            string templateFileMsg;
            if (string.IsNullOrEmpty(template.TemplateFile)) {
                templateFileMsg = string.Format(rawTemplate, Separate(template.Template ?? string.Empty));
	        } else{
                templateFileMsg = string.Format(rawTemplateFileMsg, template.TemplateFile ?? string.Empty);
            }
            string tempFilesMsg = string.Empty;
            if (files.TmpFolder != null)
            {
                tempFilesMsg = string.Format(rawTmpFiles, files.TmpFolder);
            }

            string sourceCodeMessage = string.Empty;
            if (files.SourceCode != null)
            {
                sourceCodeMessage = string.Format(rawSourceCode, Separate(files.SourceCode));
            }

            string loadedAssemblies =
                "\nList of loaded Assemblies:\n" +
                string.Join("\n\tLoaded Assembly: ",
                    (new Compilation.ReferenceResolver.UseCurrentAssembliesReferenceResolver())
                    .GetReferences().Select(r => r.GetFile()));

            var rawMessage = @"Errors while compiling a Template.
Please try the following to solve the situation:
  * If the problem is about missing/invalid references or multiple defines either try to load 
    the missing references manually (in the compiling appdomain!) or
    Specify your references manually by providing your own IReferenceResolver implementation.
    See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details.
    Currently all references have to be available as files!
  * If you get 'class' does not contain a definition for 'member': 
        try another modelType (for example 'null' to make the model dynamic).
        NOTE: You CANNOT use typeof(dynamic) to make the model dynamic!
    Or try to use static instead of anonymous/dynamic types.
More details about the error:
{0}
{1}{2}{3}{4}";
            return string.Format(rawMessage, errorMsgs, tempFilesMsg, templateFileMsg, sourceCodeMessage, loadedAssemblies);
        }
예제 #12
0
 /// <summary>
 /// Adds a given template to the <see cref="ITemplateManager"/> as dynamic template.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="templateSource"></param>
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     Configuration.TemplateManager.AddDynamic(key, templateSource);
 }
 /// <summary>
 /// Add a dynamic template (throws an exception)
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     inner.AddDynamic(key, source);
 }
 public EmbeddedTemplateSource(IConfiguredTemplateSource parent, ITemplateSourceEntry entry, ITemplateSource source)
 {
     _parent = parent;
     _entry  = entry;
     _source = source;
 }
예제 #15
0
 public void Parse(ITemplateKey key, ITemplateSource source, System.IO.TextWriter writer, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     CheckModelType(modelType);
     _origin.Parse(key, source, writer, modelType, GetDynamicModel(modelType, model, _allowMissingPropertiesOnDynamic), viewBag);
 }
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     _origin.AddTemplate(key, templateSource);
 }
예제 #17
0
 public void SetUp()
 {
     fileService = MockRepository.GenerateMock<IFileService>();
     templateEngineRegistry = MockRepository.GenerateMock<ITemplateEngineRegistry>();
     templateSource = new DefaultTemplateSource(fileService, templateEngineRegistry);
 }
예제 #18
0
 /// <summary>
 /// Throws NotSupportedException.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     throw new NotSupportedException("Adding templates dynamically is not supported. This Manager only supports embedded resources.");
 }
 /// <summary>
 /// See <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.RunCompile"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="key"></param>
 /// <param name="writer"></param>
 /// <param name="modelType"></param>
 /// <param name="model"></param>
 /// <param name="viewBag"></param>
 public static void RunCompile(this IRazorEngineService service, ITemplateSource templateSource, ITemplateKey key, TextWriter writer, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     service.AddTemplate(key, templateSource);
     service.RunCompile(key, writer, modelType, model, viewBag);
 }
예제 #20
0
 /// <summary>
 /// See <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which creates a <see cref="TextWriter"/> and returns the result as string.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="name"></param>
 /// <param name="modelType"></param>
 /// <param name="model"></param>
 /// <param name="viewBag"></param>
 /// <returns></returns>
 public static string RunCompile(this IRazorEngineService service, ITemplateSource templateSource, string name, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     service.AddTemplate(name, templateSource);
     return(service.RunCompile(name, modelType, model, viewBag));
 }
예제 #21
0
        /// <summary>
        /// Adds a given template to the template manager as dynamic template.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="name"></param>
        /// <param name="templateSource"></param>
        public static void AddTemplate(this IRazorEngineService service, string name, ITemplateSource templateSource)
        {
            var key = service.GetKey(name);

            service.AddTemplate(key, templateSource);
        }
예제 #22
0
파일: Map.cs 프로젝트: tnelab/TMiniblink
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     keyPathDic_.Add(key, source);
 }
예제 #23
0
 public Template(ITemplateSource template)
 {
     _template = template;
     Params    = new Dictionary <string, object>();
 }
예제 #24
0
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     throw new NotImplementedException();
 }
예제 #25
0
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     m_templateManager.AddDynamic(key, source);
 }
예제 #26
0
 /// <summary>
 /// Adds a given template to the template manager as dynamic template.
 /// </summary>
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     m_engineService.AddTemplate(key, templateSource);
 }
예제 #27
0
 /// <summary>
 /// Parse the tempalte source
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 /// <param name="writer"></param>
 /// <param name="modelType"></param>
 /// <param name="model"></param>
 /// <param name="viewBag"></param>
 public void Parse(ITemplateKey key, ITemplateSource source, System.IO.TextWriter writer, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     var template = _core_with_cache.Compile(key, source, modelType);
     #if RAZOR4
     try
     {
         _core_with_cache.RunTemplate(template, writer, model, viewBag).Wait();
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.Flatten().InnerExceptions.First()).Throw();
     }
     #else
     _core_with_cache.RunTemplate(template, writer, model, viewBag);
     #endif
 }
예제 #28
0
        private async Task AddFromSourceAsync(
            ITemplateSource source,
            string searchTerm,
            CategorizedViewModel parent,
            bool alterSelection,
            CancellationToken ct,
            string continuationToken = null,
            VisualStudio.Imaging.Interop.ImageMoniker?updateableImage = null
            )
        {
            var loading = new LoadingViewModel();

            parent.Templates.Add(loading);
            if (alterSelection)
            {
                loading.IsSelected = true;
            }

            try {
                var result = await source.GetTemplatesAsync(searchTerm, continuationToken, ct);

                foreach (var t in result.Templates)
                {
                    ct.ThrowIfCancellationRequested();

                    var vm = new TemplateViewModel();
                    vm.DisplayName       = t.Name;
                    vm.Description       = t.Description;
                    vm.AvatarUrl         = t.AvatarUrl;
                    vm.OwnerUrl          = t.OwnerUrl;
                    vm.RemoteUrl         = t.RemoteUrl;
                    vm.ClonedPath        = t.LocalFolderPath;
                    vm.IsUpdateAvailable = t.UpdateAvailable == true;
                    parent.Templates.Add(vm);
                }

                ct.ThrowIfCancellationRequested();

                if (result.ContinuationToken != null)
                {
                    var loadMore = new ContinuationViewModel(result.ContinuationToken);
                    parent.Templates.Add(loadMore);
                }
            } catch (TemplateEnumerationException ex) {
                var template = new ErrorViewModel()
                {
                    ErrorDescription = ex.Message,
                    ErrorDetails     = ex.InnerException?.Message,
                };
                parent.Templates.Add(template);
            } finally {
                // Check if the loading item is still selected before we remove it, the user
                // may have selected something else while we were loading results.
                bool loadingStillSelected = loading.IsSelected;
                parent.Templates.Remove(loading);
                if (alterSelection && loadingStillSelected)
                {
                    // Loading was still selected, so select something else.
                    var newLast = parent.Templates.LastOrDefault() as TreeItemViewModel;
                    if (newLast != null)
                    {
                        newLast.IsSelected = true;
                    }
                }
            }
        }
 /// <summary>
 /// Adds a given template to the template manager as dynamic template.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="name"></param>
 /// <param name="templateSource"></param>
 public static void AddTemplate(this IRazorEngineService service, string name, ITemplateSource templateSource)
 {
     var key = service.GetKey(name);
     service.AddTemplate(key, templateSource);
 }
 /// <summary>
 /// Add a dynamic template (throws an exception)
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     inner.AddDynamic(key, source);
 }
예제 #31
0
 /// <summary>
 /// Adds a given template to the <see cref="ITemplateManager"/> as dynamic template.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="templateSource"></param>
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     Configuration.TemplateManager.AddDynamic(key, templateSource);
 }
예제 #32
0
 public TemplateTreeViewModel(ITemplateSource source)
 {
     templateSource = source;
     List.Clear();
 }
예제 #33
0
 /// <summary>
 /// Adds a given template to the template manager as dynamic template.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="templateSource"></param>
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     _proxy.AddTemplate(key, templateSource);
 }
예제 #34
0
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
 }
예제 #35
0
 internal CompileUnit(ITemplateSource source)
 {
     m_TemplateSource = source;
 }
예제 #36
0
 public MvcTemplateHttpResponse(
     ITemplateSource templateSource,
     string contentType,
     IDictionary properties) : base(templateSource, contentType, properties)
 {
 }
 public ConfiguredTemplateSource(ITemplateSource source, string alias, string location)
 {
     Source    = source;
     _location = location;
     Alias     = alias;
 }
예제 #38
0
 public void RegisterSource(ITemplateSource source)
 {
     _templateSources.Add(source);
 }
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     throw new NotImplementedException("dynamic templates are not supported!");
 }
예제 #40
0
        /// <summary>
        /// Compiles a page with a specified <param name="key" />
        /// </summary>
        /// <param name="key"></param>
        /// <returns>Compiled type in succeded. Compilation errors on fail</returns>
        public CompilationResult KeyCompile(string key)
        {
            ITemplateSource source = TemplateManager.Resolve(key);

            return(CompileSource(source, null));
        }
예제 #41
0
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     dictTmp.Add(key, source);
 }
        /// <summary>
        /// Gets a exact error message of the given error collection
        /// </summary>
        /// <param name="errors"></param>
        /// <param name="files"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        internal static string GetMessage(IEnumerable <RazorEngineCompilerError> errors, CompilationData files, ITemplateSource template)
        {
            var errorMsgs = string.Join("\n\t", errors.Select(error =>
                                                              string.Format(
                                                                  " - {0}: ({1}, {2}) {3}",
                                                                  error.IsWarning ? "warning" : "error",
                                                                  error.Line, error.Column, error.ErrorText)));

            const string rawTemplateFileMsg = "The template-file we tried to compile is: {0}\n";
            const string rawTemplate        = "The template we tried to compile is: {0}\n";
            const string rawTmpFiles        = "Temporary files of the compilation can be found in (please delete the folder): {0}\n";
            const string rawSourceCode      = "The generated source code is: {0}\n";

            string templateFileMsg;

            if (string.IsNullOrEmpty(template.TemplateFile))
            {
                templateFileMsg = string.Format(rawTemplate, Separate(template.Template ?? string.Empty));
            }
            else
            {
                templateFileMsg = string.Format(rawTemplateFileMsg, template.TemplateFile ?? string.Empty);
            }
            string tempFilesMsg = string.Empty;

            if (files.TmpFolder != null)
            {
                tempFilesMsg = string.Format(rawTmpFiles, files.TmpFolder);
            }

            string sourceCodeMessage = string.Empty;

            if (files.SourceCode != null)
            {
                sourceCodeMessage = string.Format(rawSourceCode, Separate(files.SourceCode));
            }

            var rawMessage = @"Errors while compiling a Template.
Please try the following to solve the situation:
  * If the problem is about missing references either try to load the missing references manually (in the compiling appdomain!) or
    Specify your references manually by providing your own IReferenceResolver implementation.
    Currently all references have to be available as files!
  * If you get 'class' does not contain a definition for 'member': 
        try another modelType (for example 'null' or 'typeof(DynamicObject)' to make the model dynamic).
        NOTE: You CANNOT use typeof(dynamic)!
    Or try to use static instead of anonymous/dynamic types.
More details about the error:
{0}
{1}{2}{3}";

            return(string.Format(rawMessage, errorMsgs, tempFilesMsg, templateFileMsg, sourceCodeMessage));
        }
 /// <summary>
 /// Adds a given template to the template manager as dynamic template.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="templateSource"></param>
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     _proxy.AddTemplate(key, templateSource);
 }
예제 #44
0
        public CookiecutterViewModel(ICookiecutterClient cutter, IGitHubClient githubClient, IGitClient gitClient, ICookiecutterTelemetry telemetry, Redirector outputWindow, ILocalTemplateSource installedTemplateSource, ITemplateSource feedTemplateSource, ITemplateSource gitHubTemplateSource, Action<string> openFolder, IProjectSystemClient projectSystemClient) {
            _cutterClient = cutter;
            _githubClient = githubClient;
            _gitClient = gitClient;
            _telemetry = telemetry;
            _outputWindow = outputWindow;
            _recommendedSource = feedTemplateSource;
            _installedSource = installedTemplateSource;
            _githubSource = gitHubTemplateSource;
            _openFolder = openFolder;
            _projectSystemClient = projectSystemClient;

            Installed = new CategorizedViewModel(Strings.TemplateCategoryInstalled);
            Recommended = new CategorizedViewModel(Strings.TemplateCategoryRecommended);
            GitHub = new CategorizedViewModel(Strings.TemplateCategoryGitHub);
            Custom = new CategorizedViewModel(Strings.TemplateCategoryCustom);
        }
 /// <summary>
 /// See <see cref="RazorEngineService.Compile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.Compile"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="name"></param>
 /// <param name="modelType"></param>
 public static void Compile(this IRazorEngineService service, ITemplateSource templateSource, string name, Type modelType = null)
 {
     service.AddTemplate(name, templateSource);
     service.Compile(name, modelType);
 }
예제 #46
0
        private async Task AddFromSource(
            ITemplateSource source,
            string searchTerm,
            CategorizedViewModel parent,
            CancellationToken ct,
            string continuationToken = null,
            VisualStudio.Imaging.Interop.ImageMoniker? updateableImage = null
        ) {
            var loading = new LoadingViewModel();
            parent.Templates.Add(loading);

            try {
                var result = await source.GetTemplatesAsync(searchTerm, continuationToken, ct);
                foreach (var t in result.Templates) {
                    ct.ThrowIfCancellationRequested();

                    var vm = new TemplateViewModel();
                    vm.DisplayName = t.Name;
                    vm.Description = t.Description;
                    vm.AvatarUrl = t.AvatarUrl;
                    vm.OwnerUrl = t.OwnerUrl;
                    vm.RemoteUrl = t.RemoteUrl;
                    vm.ClonedPath = t.LocalFolderPath;
                    vm.IsUpdateAvailable = t.UpdateAvailable == true;
                    parent.Templates.Add(vm);
                }

                ct.ThrowIfCancellationRequested();

                if (result.ContinuationToken != null) {
                    parent.Templates.Add(new ContinuationViewModel(result.ContinuationToken));
                }
            } catch (TemplateEnumerationException ex) {
                var template = new ErrorViewModel() {
                    ErrorDescription = ex.Message,
                    ErrorDetails = ex.InnerException?.Message,
                };
                parent.Templates.Add(template);
            } finally {
                parent.Templates.Remove(loading);
            }
        }
 /// <summary>
 /// See <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which creates a <see cref="TextWriter"/> and returns the result as string.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="name"></param>
 /// <param name="modelType"></param>
 /// <param name="model"></param>
 /// <param name="viewBag"></param>
 /// <returns></returns>
 public static string RunCompile(this IRazorEngineService service, ITemplateSource templateSource, string name, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     service.AddTemplate(name, templateSource);
     return service.RunCompile(name, modelType, model, viewBag);
 }
예제 #48
0
        public void SetupTest() {
            _redirector = new MockRedirector();

            var output = TestData.GetTempPath("Cookiecutter", true);
            var outputProjectFolder = Path.Combine(output, "integration");
            var feedUrl = new Uri(TestFeedPath);
            var installedPath = TestInstalledTemplateFolderPath;
            var userConfigFilePath = TestUserConfigFilePath;

            _gitClient = GitClientProvider.Create(_redirector, null);
            _gitHubClient = new GitHubClient();
            _cutterClient = CookiecutterClientProvider.Create(null, _redirector);
            _telemetry = new CookiecutterTelemetry(new TelemetryTestService());
            _installedTemplateSource = new LocalTemplateSource(installedPath, _gitClient);
            _gitHubTemplateSource = new GitHubTemplateSource(_gitHubClient);
            _feedTemplateSource = new FeedTemplateSource(feedUrl);
            _projectSystemClient = new MockProjectSystemClient();

            _vm = new CookiecutterViewModel(
                _cutterClient,
                _gitHubClient,
                _gitClient,
                _telemetry,
                _redirector,
                _installedTemplateSource,
                _feedTemplateSource,
                _gitHubTemplateSource,
                OpenFolder,
                _projectSystemClient
            );

            _vm.UserConfigFilePath = userConfigFilePath;
            ((CookiecutterClient)_cutterClient).DefaultBasePath = outputProjectFolder;
        }
 /// <summary>
 /// See <see cref="RazorEngineService.Compile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.Compile"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="key"></param>
 /// <param name="modelType"></param>
 public static void Compile(this IRazorEngineService service, ITemplateSource templateSource, ITemplateKey key, Type modelType = null)
 {
     service.AddTemplate(key, templateSource);
     service.Compile(key, modelType);
 }
예제 #50
0
        [Pure][SecuritySafeCritical] // This should not be SecuritySafeCritical (make the template classes SecurityCritical instead)
        public virtual Tuple<Type, CompilationData> CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
        {
            var context = new TypeContext
            {
                ModelType = modelType ?? typeof(System.Dynamic.DynamicObject),
                TemplateContent = razorTemplate,
                TemplateType = (_config.BaseTemplateType) ?? typeof(TemplateBase<>)
            };

            foreach (string ns in _config.Namespaces)
                context.Namespaces.Add(ns);

            var service = _config
                .CompilerServiceFactory
                .CreateCompilerService(_config.Language);
            service.Debug = _config.Debug;
            service.DisableTempFileLocking = _config.DisableTempFileLocking;
#if !RAZOR4
#pragma warning disable 0618 // Backwards Compat.
            service.CodeInspectors = _config.CodeInspectors ?? Enumerable.Empty<ICodeInspector>();
#pragma warning restore 0618 // Backwards Compat.
#endif
            service.ReferenceResolver = _config.ReferenceResolver ?? new UseCurrentAssembliesReferenceResolver();

            var result = service.CompileType(context);

            return result;
        }
예제 #51
0
 public string GetCodeCompileUnit(string className, ITemplateSource template, ISet<string> namespaceImports, Type templateType, Type modelType)
 {
     var typeContext =
         new TypeContext(className, namespaceImports)
         {
             TemplateContent = template,
             TemplateType = templateType,
             ModelType = modelType
         };
     return GetCodeCompileUnit(typeContext);
 }
        /// <summary>
        /// Initialises a new instance of <see cref="TemplateCompilationException"/>.
        /// </summary>
        /// <param name="errors">The set of compiler errors.</param>
        /// <param name="files">The source code that wasn't compiled.</param>
        /// <param name="template">The source template that wasn't compiled.</param>
        public TemplateCompilationException(IEnumerable <RazorEngineCompilerError> errors, CompilationData files, ITemplateSource template)
            : base(TemplateCompilationException.GetMessage(errors, files, template))
        {
            var list = errors.ToList();

            CompilerErrors  = new ReadOnlyCollection <RazorEngineCompilerError>(list);
            CompilationData = files;
            Template        = template.Template;
        }
		public void AddDynamic(ITemplateKey key, ITemplateSource source)
		{
			throw new NotImplementedException("dynamic templates are not supported!");
		}
 /// <summary>
 /// Throws NotSupportedException.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     throw new NotSupportedException("Adding templates dynamically is not supported! Instead you probably want to use the full-path in the name parameter?");
 }
예제 #55
0
 /// <summary>
 /// See <see cref="RazorEngineService.RunCompile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.RunCompile"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="name"></param>
 /// <param name="writer"></param>
 /// <param name="modelType"></param>
 /// <param name="model"></param>
 /// <param name="viewBag"></param>
 public static void RunCompile(this IRazorEngineService service, ITemplateSource templateSource, string name, TextWriter writer, Type modelType = null, object model = null, DynamicViewBag viewBag = null)
 {
     service.AddTemplate(name, templateSource);
     service.RunCompile(name, writer, modelType, model, viewBag);
 }
예제 #56
0
 public FilteredTemplateSource(ITemplateSource concreteSource, Func <Template, bool> filterFunction)
 {
     this.concreteSource = concreteSource;
     this.filterFunction = filterFunction;
 }
예제 #57
0
        public CookiecutterViewModel(ICookiecutterClient cutter, IGitHubClient githubClient, IGitClient gitClient, ICookiecutterTelemetry telemetry, Redirector outputWindow, ILocalTemplateSource installedTemplateSource, ITemplateSource feedTemplateSource, ITemplateSource gitHubTemplateSource, Action <string> openFolder)
        {
            _cutterClient      = cutter;
            _githubClient      = githubClient;
            _gitClient         = gitClient;
            _telemetry         = telemetry;
            _outputWindow      = outputWindow;
            _recommendedSource = feedTemplateSource;
            _installedSource   = installedTemplateSource;
            _githubSource      = gitHubTemplateSource;
            _openFolder        = openFolder;

            Installed   = new CategorizedViewModel(Strings.TemplateCategoryInstalled);
            Recommended = new CategorizedViewModel(Strings.TemplateCategoryRecommended);
            GitHub      = new CategorizedViewModel(Strings.TemplateCategoryGitHub);
            Custom      = new CategorizedViewModel(Strings.TemplateCategoryCustom);
        }
예제 #58
0
 public void AddTemplate(ITemplateKey key, ITemplateSource templateSource)
 {
     _razor.AddTemplate(key, templateSource);
 }
예제 #59
0
 /// <summary>
 /// Throws NotSupportedException.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="source"></param>
 public void AddDynamic(ITemplateKey key, ITemplateSource source)
 {
     throw new NotSupportedException("Adding templates dynamically is not supported! Instead you probably want to use the full-path in the name parameter?");
 }
예제 #60
0
 /// <summary>
 /// See <see cref="RazorEngineService.Compile"/>.
 /// Convenience method which calls <see cref="RazorEngineService.AddTemplate"/> before calling <see cref="RazorEngineService.Compile"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="templateSource"></param>
 /// <param name="key"></param>
 /// <param name="modelType"></param>
 public static void Compile(this IRazorEngineService service, ITemplateSource templateSource, ITemplateKey key, Type modelType = null)
 {
     service.AddTemplate(key, templateSource);
     service.Compile(key, modelType);
 }