Esempio n. 1
0
        public void Should_resolve_component_names()
        {
            var component = new Component(SetupMock <IComponentDependenciesFactory>());

            component.Name = "AbcDef";
            _nameManager.Register(component);

            Assert.AreEqual(component, _nameManager.ResolveComponent("AbcDef"));
            Assert.AreEqual(component, _nameManager.ResolveComponent("abcdef"));
            Assert.AreEqual(component, _nameManager.ResolveComponent("ABCDEF"));

            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveComponent("Xyz"));

            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveDataProvider("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveLayout("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveModule("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolvePackage("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolvePage("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveRegion("AbcDef"));
            Assert.Throws <NameResolutionFailureException>(() => _nameManager.ResolveService("AbcDef"));
        }
        /// <summary>
        /// Loads a template from a URI
        /// </summary>
        /// <param name="uri">The URI to load from</param>
        /// <param name="parser">The parser to use to parse the template</param>
        /// <param name="templatePath">Optional path to register the template at
        /// with the name manager</param>
        /// <returns>The template that was loaded</returns>
        public ITemplate LoadUri(Uri uri, ITemplateParser parser, string templatePath)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            if (!uri.IsAbsoluteUri)
            {
                throw new ArgumentException("The Uri must be absolute", "uri");
            }

            Encoding encoding;
            var      buffer   = LoadUriContents(uri, out encoding);
            var      template = parser.Parse(new[] { new TemplateResource {
                                                         Content = buffer, Encoding = encoding
                                                     } }, Package);

            if (!string.IsNullOrEmpty(templatePath))
            {
                _nameManager.Register(template, templatePath);

                Reload(new TemplateInfo
                {
                    Uri          = uri,
                    Parser       = parser,
                    TemplatePath = templatePath,
                    Checksum     = CalculateChecksum(buffer)
                });
            }

            template.IsStatic = !ReloadInterval.HasValue;

            return(template);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads a set of files that comprise the parts of a single template
        /// </summary>
        /// <param name="fileNames">The files to load</param>
        /// <param name="parser">The parser to use to parse the template files</param>
        /// <param name="templatePath">Optional template path registers the template
        /// with the Name Manager. Also causes the template to be periodically
        /// reloaded</param>
        /// <returns>The template that was loaded</returns>
        public ITemplate LoadFileSet(string[] fileNames, ITemplateParser parser, string templatePath = null)
        {
            var resources = new TemplateResource[fileNames.Length];

            for (var i = 0; i < fileNames.Length; i++)
            {
                resources[i] = new TemplateResource
                {
                    Content = LoadFileContents(fileNames[i], out Encoding encoding)
                };
                resources[i].Encoding    = encoding;
                resources[i].ContentType = ContentTypeFromExt(Path.GetExtension(fileNames[i]));
            }

            var template = parser.Parse(resources, Package);

            if (!string.IsNullOrEmpty(templatePath))
            {
                _nameManager.Register(template, templatePath);

                var templateInfo = new TemplateInfo
                {
                    FileNames    = fileNames,
                    Parser       = parser,
                    TemplatePath = templatePath,
                    Checksum     = new byte[fileNames.Length][]
                };

                for (var i = 0; i < fileNames.Length; i++)
                {
                    templateInfo.Checksum[i] = CalculateChecksum(resources[i].Content);
                }

                Reload(templateInfo);
            }

            template.IsStatic = !ReloadInterval.HasValue;

            return(template);
        }
Esempio n. 4
0
        /// <summary>
        /// This method is called from the ElementDefinition.Build() method
        /// when the element is completely built and configured. It can also be
        /// called at application startup to register custom types that were built
        /// by the application
        /// </summary>
        void IFluentBuilder.Register(object obj)
        {
            var package = obj as IPackage;

            if (package != null)
            {
                _nameManager.Register(package);
            }

            var module = obj as IModule;

            if (module != null)
            {
                _nameManager.Register(module);
            }

            var element = obj as IElement;

            if (element != null)
            {
                _nameManager.Register(element);
            }

            var dataProvider = obj as IDataProvider;

            if (dataProvider != null)
            {
                _nameManager.Register(dataProvider);
            }

            var dataSupplier = obj as IDataSupplier;

            if (dataSupplier != null)
            {
                _dataCatalog.Register(dataSupplier);
            }
        }
        private string AddTemplate(
            string baseName,
            StringBuilder less,
            List <string> modules)
        {
            LoadScriptModule(baseName, modules);

            var templateDefinition = _templateBuilder.BuildUpTemplate();

            var markupFileName     = baseName + ".html";
            var stylesheetFileName = baseName + ".less";

            var markupLines = GetEmbeddedTextFile(markupFileName);

            if (markupLines != null)
            {
                foreach (var line in markupLines)
                {
                    templateDefinition.AddHtml(line);
                    templateDefinition.AddLineBreak();
                }
            }

            var styles = GetEmbeddedTextFile(stylesheetFileName);

            if (styles != null)
            {
                foreach (var line in styles)
                {
                    less.AppendLine(line);
                }
            }

            var template     = templateDefinition.Build();
            var templatePath = _configuration.TemplateBasePath + baseName;

            _nameManager.Register(template, templatePath);

            return(templatePath);
        }
        /// <summary>
        /// This method is called from the ElementDefinition.Build() method
        /// when the element is completely built and configured. It can also be
        /// called at application startup to register custom types that were built
        /// by the application
        /// </summary>
        void IFluentBuilder.Register(object obj)
        {
            var package = obj as IPackage;

            if (package != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering the '" +
                                    package.Name + "' package of type " + obj.GetType().DisplayName() + " with the name manager");
                }
                _nameManager.Register(package);
            }

            var module = obj as IModule;

            if (module != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering the '" +
                                    module.Name + "' module of type " + obj.GetType().DisplayName() + " with the name manager");
                }
                _nameManager.Register(module);
            }

            var runable = obj as IRunable;

            if (runable != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering the '" +
                                    runable.Name + "' runable of type " + obj.GetType().DisplayName() + " with the name manager");
                }
                _nameManager.Register(runable);
            }

            var element = obj as IElement;

            if (element != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering the '" +
                                    element.Name + "' " + element.ElementType + " of type " + obj.GetType().DisplayName() + " with the name manager");
                }
                _nameManager.Register(element);
            }

            var dataProvider = obj as IDataProvider;

            if (dataProvider != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering the '" +
                                    dataProvider.Name + "' data provider of type " + obj.GetType().DisplayName() + " with the name manager");
                }
                _nameManager.Register(dataProvider);
            }

            var dataSupplier = obj as IDataSupplier;

            if (dataSupplier != null)
            {
                if (_debugLogging)
                {
                    Trace.WriteLine("Fluent builder is registering data supplier of type " +
                                    obj.GetType().DisplayName() + " with the data catalog");
                }
                _dataCatalog.Register(dataSupplier);
            }
        }