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()); }
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 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)); }
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(); }
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")); }
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))); }
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")); }
public void TestLoad() { var bundle = new ResourceBundle("FormatTags/compiled", null); Assert.That(bundle.Prefix, Is.EqualTo("")); Assert.That(bundle.BaseName, Is.EqualTo("FormatTags/compiled")); }
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")); }
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); } }
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")); }
public void TestGetTranslationsOfNonExistingKey() { var bundle = new ResourceBundle("FormatTags/complex", null); Assert.That(bundle.Get("wrong", new CultureInfo("en-US")), Is.EqualTo("?wrong?")); }
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")); }
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")); }
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")); }
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); } }
public ResourceKeyStack(ResourceBundle bundle) { _bundle = bundle; _tags= new List<ITag>(); }