示例#1
0
 public string Evaluate(TagModel model)
 {
     var baseName = GetAsString(BaseName, model);
     var prefix = GetAsString(Prefix, model);
     IResourceBundle bundle = new ResourceBundle(baseName, prefix, BaseName.ResourceLocator);
     model.PushTagStack();
     model.Tag[FormatConstants.BUNDLE] = bundle;
     return GetAsString(Body, model) ?? string.Empty;
 }
        public DocumentModel BuildModel()
        {
            var assembly = Assembly.GetAssembly(typeof(DocumentationGenerator));
            var prefix = assembly.GetName().Name.EndsWith("Documentation") ? "templates" : "Documentation.templates";
            var locator = new AssemblyLocatorFactory(assembly, prefix).CloneForTagLib(_lib);
            var bundle = new ResourceBundle("Documentation", null, locator.GetNewLocator());
            return new DocumentModel(_subject, _all, bundle, _specials);

            //            var json = JsonConvert.SerializeObject(dm, new TypeJsonConverter(), new StringEnumConverter());
        }
示例#3
0
        public string Evaluate(TagModel model)
        {
            var             baseName = GetAsString(BaseName, model);
            var             prefix   = GetAsString(Prefix, model);
            IResourceBundle bundle   = new ResourceBundle(baseName, prefix, BaseName.ResourceLocator);

            model.PushTagStack();
            model.Tag[FormatConstants.BUNDLE] = bundle;
            return(GetAsString(Body, model) ?? string.Empty);
        }
示例#4
0
 public void TestCache()
 {
     string sourcePath = "FormatTags/compiled";
     string tempPath = Path.GetTempPath();
     tempPath += Path.GetFileName(sourcePath);
     File.Copy(sourcePath + FileBasedResourceLocator.COMPILED_EXTENSION,
               tempPath + FileBasedResourceLocator.COMPILED_EXTENSION, true);
     var bundle1 = new ResourceBundle(tempPath, null);
     var bundle2 = new ResourceBundle(tempPath, null);
     Assert.That(bundle1, Is.Not.SameAs(bundle2));
     Assert.That(bundle1.ResourceManager, Is.SameAs(bundle2.ResourceManager));
 }
示例#5
0
        public DocumentModel(TagLib subject, bool all, ResourceBundle bundle, IList<Func<ITag, TagDocumentation, bool>> specials=null)
        {
            _expressionlib = new ExpressionLib();

            _subject = subject;
            _all = all;
            _specials = specials??new List<Func<ITag, TagDocumentation, bool>>();
            _additionalResources = new Dictionary<string, string>();
            _resouceKey = new ResourceKeyStack(bundle);
            GatherExpressions();
            GatherFunctions();
            GatherGroups();
        }
示例#6
0
 public void TestGetTranslationsWithReplacements()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     Assert.That(bundle.Get("noreplacment", new CultureInfo("en-US")), Is.EqualTo("fixed"));
     Assert.That(bundle.Get("onevar", new CultureInfo("en-US"), "one"), Is.EqualTo("the one var"));
     Assert.That(bundle.Get("onevar", new CultureInfo("en-US"), 1), Is.EqualTo("the 1 var"));
     Assert.That(bundle.Get("twovars", new CultureInfo("en-US"), 1, 2), Is.EqualTo("two 1, 2 vars"));
     Assert.That(bundle.Get("twovars", new CultureInfo("en-US"), "a", "b"), Is.EqualTo("two a, b vars"));
     Assert.That(bundle.Get("twovars", new CultureInfo("en-US"), 1, "b"), Is.EqualTo("two 1, b vars"));
     Assert.That(bundle.Get("twovarswithgap", new CultureInfo("en-US"), "a", "b", "c"),
                 Is.EqualTo("two a, gap, c vars"));
 }
示例#7
0
        private static void BenchMark(string baseName, string key, int run)
        {
            var bundle = new ResourceBundle(baseName, "");
            bundle.Get(key, new CultureInfo("en-US"));

            DateTime start = DateTime.Now;
            for (int i = 0; i < run; i++)
            {
                bundle.Get(key, new CultureInfo("en-US"));
            }
            DateTime end = DateTime.Now;
            TimeSpan time = end.Subtract(start);
            double avg = (run/(time.TotalMilliseconds/1000.0));
            Assert.That(avg, Is.GreaterThan(run*BENCHMARK_FACTOR));
            Console.WriteLine(baseName + ": " + avg + " average formats per second no model");
        }
 public string GenerateDocumentation()
 {
     var assembly = Assembly.GetAssembly(typeof(DocumentationGenerator));
     var prefix = assembly.GetName().Name.EndsWith("Documentation") ? "templates" : "Documentation.templates";
     var locator = new AssemblyLocatorFactory(assembly, prefix).CloneForTagLib(_lib);
     var bundle =  new ResourceBundle("Documentation", null, locator.GetNewLocator());
     var template = locator.Handle(_fragment?"fragment.html":"index.htm", true);
     return template.Evaluate(new TagModel(new DocumentModel(_subject, _all, bundle, _specials)));
 }
示例#9
0
 public void TestGetTranslationsWithReplacementsTooManyParametersShouldBeIgnored()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     Assert.That(bundle.Get("onevar", new CultureInfo("en-US"), "one", "two", "three"), Is.EqualTo("the one var"));
 }
示例#10
0
 public void TestLoad()
 {
     var bundle = new ResourceBundle("FormatTags/compiled", null);
     Assert.That(bundle.Prefix, Is.EqualTo(""));
     Assert.That(bundle.BaseName, Is.EqualTo("FormatTags/compiled"));
 }
示例#11
0
 public void TestGetTranslationsWithReplacementsNonUsedParametersCanBeNull()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     Assert.That(bundle.Get("twovarswithgap", new CultureInfo("en-US"), "a", null, "c"),
                 Is.EqualTo("two a, gap, c vars"));
 }
示例#12
0
 public void TestGetTranslationsWithReplacementssedParametersCanNotBeNull()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     try
     {
         bundle.Get("onevar", new CultureInfo("en-US"), null);
         Assert.Fail("Expected exception");
     }
     catch (Exception e)
     {
         Assert.That(e is ArgumentNullException, Is.True);
     }
 }
示例#13
0
 public void TestGetTranslationsCompiledWithFilePrefix()
 {
     var bundle = new ResourceBundle("compiled", null, new FileBasedResourceLocator("FormatTags"));
     Assert.That(bundle.Get("a", new CultureInfo("en-US")), Is.EqualTo("defaultA"));
     Assert.That(bundle.Get("a", new CultureInfo("nl-NL")), Is.EqualTo("nederlandseA"));
 }
示例#14
0
 public void TestGetTranslationsOfNonExistingKey()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     Assert.That(bundle.Get("wrong", new CultureInfo("en-US")), Is.EqualTo("?wrong?"));
 }
示例#15
0
 public void TestGetTranslationsWithPrefix()
 {
     var bundle = new ResourceBundle("FormatTags/compiled", "pre_");
     Assert.That(bundle.Get("a", new CultureInfo("en-US")), Is.EqualTo("prefixedA"));
     Assert.That(bundle.Get("a", new CultureInfo("nl-NL")), Is.EqualTo("aMetVoorvoegsel"));
 }
示例#16
0
 public void TestGetTranslationsWithCompileWithFilePrefixFromAssembly()
 {
     var bundle = new ResourceBundle("embedded_test", null,
                                     new AssemblyBasedResourceLocator(GetType().Assembly,
                                                                      "FormatTags"));
     Assert.That(bundle.Get("a", new CultureInfo("en-US")), Is.EqualTo("defaultA"));
     Assert.That(bundle.Get("a", new CultureInfo("nl-NL")), Is.EqualTo("nederlandseA"));
 }
示例#17
0
 public void TestGetTranslationsWithCompile()
 {
     var bundle = new ResourceBundle("FormatTags/test", null);
     Assert.That(bundle.Get("a", new CultureInfo("en-US")), Is.EqualTo("defaultA"));
     Assert.That(bundle.Get("a", new CultureInfo("nl-NL")), Is.EqualTo("nederlandseA"));
 }
示例#18
0
 public void TestGetTranslationsWithReplacementsMessageButNoParametersProvided()
 {
     var bundle = new ResourceBundle("FormatTags/complex", null);
     try
     {
         bundle.Get("onevar", new CultureInfo("en-US"));
         Assert.Fail("Expected exception");
     }
     catch (Exception e)
     {
         Assert.That(e is FormatException, Is.True);
     }
 }
示例#19
0
 public ResourceKeyStack(ResourceBundle bundle)
 {
     _bundle = bundle;
     _tags= new List<ITag>();
 }