Ejemplo n.º 1
0
 public Formatter()
 {
     _lib           = new TagLib();
     _expressionLib = new ExpressionLib();
     _lib.Register(new Sharp());
     _lib.Register(new Macro());
 }
Ejemplo n.º 2
0
 public void SetUp()
 {
     _lib = new TagLib();
     _lib.Register(new Tags.Tiles());
     _lib.Register(new Sharp());
     _factory          = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory;
     _map              = new TilesMap();
     _data             = new Hashtable();
     _model            = new TagModel(_data);
     _nestedAttributes = new AttributeSet(
         "nested",
         new TileAttribute("aAttribute", new StringTile("aAttributeValue"))
         );
     _map.AddTile(new TemplateTile("fileWithAttributes", _factory.Handle("filewithtileattributes.htm", true),
                                   _nestedAttributes));
     _attributes = new AttributeSet(
         "main",
         new TileAttribute("simple", new StringTile("simpleValue")),
         new TileAttribute("file", new TemplateTile(null, _factory.Handle("a.htm", true), null)),
         new TileAttribute("fileWithVars", new TemplateTile(null, _factory.Handle("b.htm", true), null)),
         new TileAttribute("fileWithTilesAttributes", new TileReference("fileWithAttributes", _map))
         );
     _model.Decorate().With(_attributes);
     _data["simpleAsProperty"] = "simple";
     _data["some"]             = new Hashtable {
         { "a", "AA" }
     };
 }
Ejemplo n.º 3
0
 public void SetUp()
 {
     _lib = new TagLib();
     _lib.Register(new Tags.Tiles());
     _lib.Register(new Sharp());
     _factory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory;
 }
Ejemplo n.º 4
0
 public void SetUp()
 {
     _lib = new TagLib();
     _lib.Register(new Tags.Tiles());
     _lib.Register(new Sharp());
     _factory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory;
 }
Ejemplo n.º 5
0
 public ResourceTemplate(ITagLib lib, IResourceLocator resource, IResourceLocatorFactory factory, string path)
 {
     _lib = lib;
     _path = path;
     _resource = resource;
     _factory = factory;
     Load();
 }
Ejemplo n.º 6
0
 public ResourceTemplate(ITagLib lib, IResourceLocator resource, IResourceLocatorFactory factory, string path)
 {
     _lib      = lib;
     _path     = path;
     _resource = resource;
     _factory  = factory;
     Load();
 }
Ejemplo n.º 7
0
 public Formatter OverrideLib(ITagLib lib)
 {
     if (lib == null)
     {
         return(this);
     }
     _lib = lib;
     return(this);
 }
Ejemplo n.º 8
0
        public IResourceLocatorFactory CloneForTagLib(ITagLib lib)
        {
            var f = new AssemblyLocatorFactory(_inAssembly, _filePrefix)
            {
                _lib = lib ?? _lib
            };

            return(f);
        }
Ejemplo n.º 9
0
        public IResourceLocatorFactory CloneForTagLib(ITagLib lib)
        {
            var f = new FileLocatorFactory(_filePath, _filePrefix)
            {
                _lib = lib ?? _lib
            };

            return(f);
        }
Ejemplo n.º 10
0
        public static Formatter FileBasedFormatter(string path, Encoding encoding, ITagLib lib = null)
        {
            var locator = new FileBasedResourceLocator();

            return(new Formatter(locator.GetDataAsString(path)).
                   OverrideLib(lib).
                   AllowTags(true).
                   SetLocatorFactory(new FileLocatorFactory()).
                   SetInitialLocator(locator.Update(path)).
                   SetTagValidator(CreateTagValidatorFor(lib)).
                   Parse());
        }
Ejemplo n.º 11
0
        public Formatter SwitchToMode(TagLibMode mode)
        {
            if (_templateParsed != null)
            {
                throw new InvalidOperationException("SwitchToMode can only be called before calling Parse!");
            }

            var lib = new TagLib(mode, _lib.ToArray());

            _lib = lib;
            return(this);
        }
Ejemplo n.º 12
0
        public static Formatter LocatorBasedFormatter(ITagLib lib, string path, IResourceLocator locator, IResourceLocatorFactory factory)
        {
            var template = locator.GetDataAsString(path);

            return(new Formatter(template).
                   OverrideLib(lib).
                   OverrideExpressionLib(factory.ExpressionLib).
                   AllowTags(true).
                   SetLocatorFactory(factory).
                   SetInitialLocator(locator.Update(path)).
                   SetTagValidator(CreateTagValidatorFor(lib)).
                   Parse());
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            _lib = new TagLib();
            _lib.Register(new Tags.Tiles());
            _lib.Register(new Sharp());

            book = new Dictionary <string, object>
            {
                { "title", "SharpTiles integration test" },
                { "author", "R.Z. Slijp" },
                { "copyrights", "2008 (c) R.Z. Slijp" },
                {
                    "chapters", new List <object>
                    {
                        new Dictionary <string, object>
                        {
                            { "url", "#c1" },
                            { "title", "Setting up some mock templates" },
                            {
                                "paragraphs", new List <object>
                                {
                                    "aaa", "bbb", "ccc"
                                }
                            }
                        },
                        new Dictionary <string, object>
                        {
                            { "url", "#c2" },
                            { "title", "Setting up some test data" },
                            {
                                "paragraphs", new List <object>
                                {
                                    "111", "222"
                                }
                            }
                        },
                        new Dictionary <string, object>
                        {
                            { "url", "#c3" },
                            { "title", "Making the tests" },
                            {
                                "paragraphs", new List <object>
                                {
                                    "I", "II", "III", "IV", "V"
                                }
                            }
                        }
                    }
                }
            };
        }
Ejemplo n.º 14
0
        public static IResourceLocatorFactory GetCustomFactory(ITagLib lib, Type factoryType)
        {
            if (factoryType == null)
            {
                return(null);
            }
            var factory = Activator.CreateInstance(factoryType);

            if (factory is IResourceLocatorFactory)
            {
                var resourceFactory = (IResourceLocatorFactory)factory;
                return(resourceFactory.CloneForTagLib(lib));
            }
            throw new XmlException(string.Format("Configured factory {0} doesn't implement IResourceLocatorFactory.", factoryType.FullName));
        }
Ejemplo n.º 15
0
        private static void BenchMarkReUse(string fileNameTemplate, TagModel model, ITagLib lib, int run)
        {
            Formatter formatter = Formatter.FileBasedFormatter(fileNameTemplate, lib);

            formatter.Format(model);

            DateTime start = DateTime.Now;

            for (int i = 0; i < run; i++)
            {
                formatter.Format(model);
            }
            DateTime end  = DateTime.Now;
            TimeSpan time = end.Subtract(start);
            double   avg  = (run / (time.TotalMilliseconds / 1000.0));

            //the number in run should be able to be processed in a second
            //the benchmark ratio is to cope with individual performance of different systems
            Assert.That(avg, Is.GreaterThanOrEqualTo(BENCHMARK_RATIO * run));
            Console.WriteLine(fileNameTemplate + ": " + avg + " average formats per second no one parse");
        }
Ejemplo n.º 16
0
 public void SetUp()
 {
     _lib = new TagLib();
     _lib.Register(new Tags.Tiles());
     _lib.Register(new Sharp());
 }
Ejemplo n.º 17
0
 public static Formatter FileBasedFormatter(string path, TagLibMode mode, ITagLib lib=null)
 {
     var locator = new FileBasedResourceLocator();
     return new Formatter(locator.GetDataAsString(path)).
                 OverrideLib(lib).
                 AllowTags(true).
                 SetLocatorFactory(new FileLocatorFactory()).
                 SetInitialLocator(locator.Update(path)).
                 SwitchToMode(mode).
                 SetTagValidator(CreateTagValidatorFor(lib)).
                 Parse();
 }
Ejemplo n.º 18
0
 public Formatter()
 {
     _lib = new TagLib();
     _expressionLib = new ExpressionLib();
     _lib.Register(new Sharp());
 }
Ejemplo n.º 19
0
        public Formatter SwitchToMode(TagLibMode mode)
        {
            if (_templateParsed != null)
                throw new InvalidOperationException("SwitchToMode can only be called before calling Parse!");

            var lib=new TagLib(mode,_lib.ToArray());
            _lib = lib;
            return this;
        }
Ejemplo n.º 20
0
 public static Formatter LocatorBasedFormatter(ITagLib lib, string path, IResourceLocator locator, IResourceLocatorFactory factory)
 {
     var template = locator.GetDataAsString(path);
     return new Formatter(template).
                 OverrideLib(lib).
                 OverrideExpressionLib(factory.ExpressionLib).
                 AllowTags(true).
                 SetLocatorFactory(factory).
                 SetInitialLocator(locator.Update(path)).
                 SetTagValidator(CreateTagValidatorFor(lib)).
                 Parse();
 }
Ejemplo n.º 21
0
 public TileXmlConfigurator(ITagLib lib, IResourceLocatorFactory factory)
 {
     _factory = factory.CloneForTagLib(lib);
     Load();
 }
Ejemplo n.º 22
0
 public TileXmlConfigurator(ITagLib lib, string filePath, string filePrefix)
     : this(lib,new FileLocatorFactory(filePath, filePrefix))
 {
 }
Ejemplo n.º 23
0
 public TileXmlConfigurator(ITagLib lib, IResourceLocatorFactory factory)
 {
     _factory = factory.CloneForTagLib(lib);
     Load();
 }
Ejemplo n.º 24
0
 public TileXmlConfigurator(ITagLib lib, Type factoryType)
     : this(lib, GetCustomFactory(lib, factoryType))
 {
 }
Ejemplo n.º 25
0
 public TileXmlConfigurator(ITagLib lib, string filePath, string filePrefix)
     : this(lib, new FileLocatorFactory(filePath, filePrefix))
 {
 }
Ejemplo n.º 26
0
 public TileXmlConfigurator(ITagLib lib, Assembly assembly, string prefix)
     : this(lib, new AssemblyLocatorFactory(assembly, prefix))
 {
 }
Ejemplo n.º 27
0
 public TileXmlConfigurator(ITagLib lib, Assembly assembly)
     : this(lib, new AssemblyLocatorFactory(assembly, null))
 {
 }
Ejemplo n.º 28
0
 private static ITemplateProcessor CreateTemplateProcessorFor(ITagLib lib)
 {
     return(new TemplateProcessorCollection(lib?.OfType <IHaveTemplateProcessor>().Select(t => t.TemplateProcessor).ToArray()));
 }
Ejemplo n.º 29
0
 public AssemblyLocatorFactory(Assembly inAssembly, string filePrefix)
 {
     _lib        = new TagLib();
     _inAssembly = inAssembly;
     _filePrefix = filePrefix;
 }
Ejemplo n.º 30
0
 public TagLibForParsing(ITagLib tagLib)
 {
     _top = tagLib;
     _stack.Push(tagLib);
 }
Ejemplo n.º 31
0
 public TileXmlConfigurator(ITagLib lib, Assembly assembly, string prefix)
     : this(lib, new AssemblyLocatorFactory(assembly, prefix))
 {
 }
Ejemplo n.º 32
0
 public TagLibForParsing(ITagLib tagLib)
 {
     _top = tagLib;
     _stack.Push(tagLib);
 }
Ejemplo n.º 33
0
 public TileXmlConfigurator(ITagLib lib, Type factoryType)
     : this(lib, GetCustomFactory(lib,factoryType))
 {
 }
Ejemplo n.º 34
0
 public IResourceLocatorFactory CloneForTagLib(ITagLib lib)
 {
     var f = new FileLocatorFactory(_filePath,_filePrefix) {_lib=lib??_lib};
     return f;
 }
Ejemplo n.º 35
0
 public static IResourceLocatorFactory GetCustomFactory(ITagLib lib, Type factoryType)
 {
     if(factoryType==null) return null;
     var factory = Activator.CreateInstance(factoryType);
     if(factory is IResourceLocatorFactory)
     {
         var resourceFactory=(IResourceLocatorFactory) factory;
         return resourceFactory.CloneForTagLib(lib);
     }
     throw new XmlException(string.Format("Configured factory {0} doesn't implement IResourceLocatorFactory.", factoryType.FullName));
 }
Ejemplo n.º 36
0
 private static ITagValidator CreateTagValidatorFor(ITagLib lib)
 {
     return(new TagValidatorCollection(lib?.OfType <IHaveTagValidator>().Select(t => t.TagValidator).ToArray()));
 }
Ejemplo n.º 37
0
 public Formatter OverrideLib(ITagLib lib)
 {
     if (lib == null) return this;
     _lib = lib;
     return this;
 }
Ejemplo n.º 38
0
 public static Formatter FileBasedFormatter(string path, ITagLib lib = null)
 {
     return(FileBasedFormatter(path, TagLibMode.Strict, lib));
 }
Ejemplo n.º 39
0
 private static ITemplateValidator CreateTemplateValidatorFor(ITagLib lib)
 {
     return new TemplateValidatorCollection(lib?.OfType<IHaveTemplateValidator>().Select(t => t.TemplateValidator).ToArray());
 }
Ejemplo n.º 40
0
        private static void BenchMarkReUse(string fileNameTemplate, TagModel model, ITagLib lib, int run)
        {
            Formatter formatter = Formatter.FileBasedFormatter(fileNameTemplate, lib);
            formatter.Format(model);

            DateTime start = DateTime.Now;
            for (int i = 0; i < run; i++)
            {
                formatter.Format(model);
            }
            DateTime end = DateTime.Now;
            TimeSpan time = end.Subtract(start);
            double avg = (run / (time.TotalMilliseconds / 1000.0));
            //the number in run should be able to be processed in a second
            //the benchmark ratio is to cope with individual performance of different systems
            Assert.That(avg, Is.GreaterThanOrEqualTo(BENCHMARK_RATIO * run));
            Console.WriteLine(fileNameTemplate + ": " + avg + " average formats per second no one parse");
        }
Ejemplo n.º 41
0
 public static Formatter FileBasedFormatter(string path, ITagLib lib=null)
 {
     return FileBasedFormatter(path, TagLibMode.Strict, lib);
 }
Ejemplo n.º 42
0
 public AssemblyLocatorFactory(Assembly inAssembly, string filePrefix)
 {
     _lib = new TagLib();
     _inAssembly = inAssembly;
     _filePrefix = filePrefix;
 }
Ejemplo n.º 43
0
 public void SetUp()
 {
     _lib = new TagLib();
     _lib.Register(new Tags.Tiles());
     _lib.Register(new Sharp());
     _factory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory;
     _map = new TilesMap();
     _data = new Hashtable();
     _model = new TagModel(_data);
     _nestedAttributes = new AttributeSet(
         "nested",
         new TileAttribute("aAttribute", new StringTile("aAttributeValue"))
         );
     _map.AddTile(new TemplateTile("fileWithAttributes", _factory.Handle("filewithtileattributes.htm", true),
                                   _nestedAttributes));
     _attributes = new AttributeSet(
         "main",
         new TileAttribute("simple", new StringTile("simpleValue")),
         new TileAttribute("file", new TemplateTile(null, _factory.Handle("a.htm", true), null)),
         new TileAttribute("fileWithVars", new TemplateTile(null, _factory.Handle("b.htm",true), null)),
         new TileAttribute("fileWithTilesAttributes", new TileReference("fileWithAttributes", _map))
         );
     _model.Decorate().With(_attributes);
     _data["simpleAsProperty"] = "simple";
     _data["some"] = new Hashtable {{"a", "AA"}};
 }
Ejemplo n.º 44
0
 public IResourceLocatorFactory CloneForTagLib(ITagLib lib)
 {
     var f = new AssemblyLocatorFactory(_inAssembly, _filePrefix){ _lib = lib ?? _lib };
     return f;
 }
Ejemplo n.º 45
0
 public TileXmlConfigurator(ITagLib lib,Assembly assembly)
     : this(lib, new AssemblyLocatorFactory(assembly, null))
 {
 }
Ejemplo n.º 46
0
        public void SetUp()
        {
            _lib = new TagLib();
            _lib.Register(new Tags.Tiles());
            _lib.Register(new Sharp());

            book = new Dictionary<string, object>
                       {
                           {"title", "SharpTiles integration test"},
                           {"author", "R.Z. Slijp"},
                           {"copyrights", "2008 (c) R.Z. Slijp"},
                           {
                               "chapters", new List<object>
                                               {
                                                   new Dictionary<string, object>
                                                       {
                                                           {"url", "#c1"},
                                                           {"title", "Setting up some mock templates"},
                                                           {
                                                               "paragraphs", new List<object>
                                                                                 {"aaa", "bbb", "ccc"}
                                                               }
                                                       },
                                                   new Dictionary<string, object>
                                                       {
                                                           {"url", "#c2"},
                                                           {"title", "Setting up some test data"},
                                                           {
                                                               "paragraphs", new List<object>
                                                                                 {"111", "222"}
                                                               }
                                                       },
                                                   new Dictionary<string, object>
                                                       {
                                                           {"url", "#c3"},
                                                           {"title", "Making the tests"},
                                                           {
                                                               "paragraphs", new List<object>
                                                                                 {"I", "II", "III", "IV", "V"}
                                                               }
                                                       }
                                               }
                               }
                       };
        }
Ejemplo n.º 47
0
 public FileLocatorFactory()
 {
     _lib = new TagLib();
 }
Ejemplo n.º 48
0
 public FileLocatorFactory()
 {
     _lib=new TagLib();
 }