We use the Nvelocity templating engine to produce much of our user-templated text. This includes CMS text, assignment descriptions, and many other places. I've been considering a move to the RazorEngine. No descision has been made yet but I wanted to publish our test results. MethodI looked at several parsing methods. RazorEngine Raw Parse This uses the build-in parse helper method in razor engine with no template name. Razor.Parse(template, model); Razor Compiled parse This uses the same method but adds the template name. By adding the template name RazorEngine will use the compiled version on subsequent calls. Razor.Parse(template, model, "test"); NVelocity Parse This method uses a single NVelocity Parsing Engine Context to perform its work. NVelocity Singleton This method uses the Velocity.Init() and Velocity.Evaluate() methods. This allows NVelocity to track it's own singleton pool of parsers. The TemplatesRazor Template @Model.Name, the narrator, announces his intent to ship aboard a whaling vessel. He has made several voyages as a sailor but none as a whaler. He travels to New Bedford, Massachusetts, where he stays in a whalers’ inn. Since the inn is rather full, he has to share a bed with a harpooner from the South Pacific named Queequeg. At first repulsed by Queequeg’s strange habits and shocking appearance (Queequeg is covered with tattoos), Ishmael eventually comes to appreciate the man’s generosity and kind spirit, and the two decide to seek work on a whaling vessel together. They take a ferry to Nantucket, the traditional capital of the whaling industry. There they secure berths on the Pequod, a savage-looking ship adorned with the bones and teeth of sperm whales. Peleg and Bildad, the Pequod’s Quaker owners, drive a hard bargain in terms of salary. They also mention the ship’s mysterious captain, Ahab, who is still recovering from losing his leg in an encounter with a sperm whale on his last voyage. The Pequod leaves Nantucket on a cold Christmas Day with a crew made up of men from many different countries and races. Soon the ship is in warmer waters, and Ahab makes his first appearance on deck, balancing gingerly on his false leg, which is made from a sperm whale’s jaw. He announces his desire to pursue and kill Moby Dick, the legendary great white whale who took his leg, because he sees this whale as the embodiment of evil. Ahab nails a gold doubloon to the mast and declares that it will be the prize for the first man to sight the whale. As the Pequod sails toward the southern tip of Africa, whales are sighted and unsuccessfully hunted. During the hunt, a group of men, none of whom anyone on the ship’s crew has seen before on the voyage, emerges from the hold. The men’s leader is an exotic-looking man named Fedallah. These men constitute Ahab’s private harpoon crew, smuggled aboard in defiance of Bildad and Peleg. Ahab hopes that their skills and Fedallah’s prophetic abilities will help him in his hunt for Moby Dick. The Pequod rounds Africa @if (Model == null){ <span>Null Here</span> } and enters the Indian Ocean. A few whales are successfully caught and processed for their oil. From time to time, the ship encounters other whaling vessels. Ahab always demands information about Moby Dick from their captains. One of the ships, the Jeroboam, carries Gabriel, a crazed prophet who predicts doom for anyone who threatens Moby Dick. His predictions seem to carry some weight, as those aboard his ship who have hunted the whale have met disaster. While trying to drain the oil from the head of a captured sperm whale, Tashtego, one of the Pequod’s harpooners, falls into the whale’s voluminous head, which then rips free of the ship and begins to sink. Queequeg saves Tashtego by diving into the ocean and cutting into the slowly sinking head. During another whale hunt, Pip, the Pequod’s black cabin boy, VTL Template $Model.Name, the narrator, announces his intent to ship aboard a whaling vessel. He has made several voyages as a sailor but none as a whaler. He travels to New Bedford, Massachusetts, where he stays in a whalers’ inn. Since the inn is rather full, he has to share a bed with a harpooner from the South Pacific named Queequeg. At first repulsed by Queequeg’s strange habits and shocking appearance (Queequeg is covered with tattoos), Ishmael eventually comes to appreciate the man’s generosity and kind spirit, and the two decide to seek work on a whaling vessel together. They take a ferry to Nantucket, the traditional capital of the whaling industry. There they secure berths on the Pequod, a savage-looking ship adorned with the bones and teeth of sperm whales. Peleg and Bildad, the Pequod’s Quaker owners, drive a hard bargain in terms of salary. They also mention the ship’s mysterious captain, Ahab, who is still recovering from losing his leg in an encounter with a sperm whale on his last voyage. The Pequod leaves Nantucket on a cold Christmas Day with a crew made up of men from many different countries and races. Soon the ship is in warmer waters, and Ahab makes his first appearance on deck, balancing gingerly on his false leg, which is made from a sperm whale’s jaw. He announces his desire to pursue and kill Moby Dick, the legendary great white whale who took his leg, because he sees this whale as the embodiment of evil. Ahab nails a gold doubloon to the mast and declares that it will be the prize for the first man to sight the whale. As the Pequod sails toward the southern tip of Africa, whales are sighted and unsuccessfully hunted. During the hunt, a group of men, none of whom anyone on the ship’s crew has seen before on the voyage, emerges from the hold. The men’s leader is an exotic-looking man named Fedallah. These men constitute Ahab’s private harpoon crew, smuggled aboard in defiance of Bildad and Peleg. Ahab hopes that their skills and Fedallah’s prophetic abilities will help him in his hunt for Moby Dick. The Pequod rounds Africa #if ($Model){ <span>Null Here</span> #end and enters the Indian Ocean. A few whales are successfully caught and processed for their oil. From time to time, the ship encounters other whaling vessels. Ahab always demands information about Moby Dick from their captains. One of the ships, the Jeroboam, carries Gabriel, a crazed prophet who predicts doom for anyone who threatens Moby Dick. His predictions seem to carry some weight, as those aboard his ship who have hunted the whale have met disaster. While trying to drain the oil from the head of a captured sperm whale, Tashtego, one of the Pequod’s harpooners, falls into the whale’s voluminous head, which then rips free of the ship and begins to sink. Queequeg saves Tashtego by diving into the ocean and cutting into the slowly sinking head. During another whale hunt, Pip, the Pequod’s black cabin boy, ResultsAll results are in TICKS. 10,000 TICKS = 1 MILLISECOND.
---------------- Begining Test Run 1 ---------------- Razor Raw Parse took 55855585 Razor Compiled parse 1 took 24572457 Razor Compiled Parse 2 took 0 NVelocity Parse took 6130613 NVelocity Parse 2 took 10001 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 50005 NVelocity Singleton Parse 2 took 10001 ---------------- Begining Test Run 2 ---------------- Razor Raw Parse took 5300530 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 0 NVelocity Parse 2 took 0 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 0 NVelocity Singleton Parse 2 took 10001 ---------------- Begining Test Run 3 ---------------- Razor Raw Parse took 5560556 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 10001 NVelocity Parse took 10001 NVelocity Parse 2 took 0 NVelocity Parse 3 template changed took 0 NVelocity Singleton Parse 1 took 0 NVelocity Singleton Parse 2 took 10001 ---------------- Begining Test Run 4 ---------------- Razor Raw Parse took 5380538 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 0 NVelocity Parse 2 took 0 NVelocity Parse 3 template changed took 0 NVelocity Singleton Parse 1 took 10001 NVelocity Singleton Parse 2 took 10001 ---------------- Begining Test Run 5 ---------------- Razor Raw Parse took 5270527 Razor Compiled parse 1 took 10001 Razor Compiled Parse 2 took 0 NVelocity Parse took 0 NVelocity Parse 2 took 0 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 10001 NVelocity Singleton Parse 2 took 10001 ---------------- Begining Test Run 6 ---------------- Razor Raw Parse took 5410541 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 10001 NVelocity Parse 2 took 10001 NVelocity Parse 3 template changed took 0 NVelocity Singleton Parse 1 took 0 NVelocity Singleton Parse 2 took 0 ---------------- Begining Test Run 7 ---------------- Razor Raw Parse took 5380538 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 10001 NVelocity Parse 2 took 10001 NVelocity Parse 3 template changed took 0 NVelocity Singleton Parse 1 took 0 NVelocity Singleton Parse 2 took 0 ---------------- Begining Test Run 8 ---------------- Razor Raw Parse took 5580558 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 10001 NVelocity Parse 2 took 10001 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 0 NVelocity Singleton Parse 2 took 0 ---------------- Begining Test Run 9 ---------------- Razor Raw Parse took 5470547 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 0 NVelocity Parse 2 took 0 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 10001 NVelocity Singleton Parse 2 took 0 ---------------- Begining Test Run 10 ---------------- Razor Raw Parse took 5360536 Razor Compiled parse 1 took 0 Razor Compiled Parse 2 took 0 NVelocity Parse took 40004 NVelocity Parse 2 took 10001 NVelocity Parse 3 template changed took 10001 NVelocity Singleton Parse 1 took 10001 NVelocity Singleton Parse 2 took 0
1 Comment
Starting with NexPort Campus v5.1 NexPort will support both Castle Validation and Fluent Validation. Castle Validation will be completely phased out by v6.0 and replaced by Fluent Validation. Fluent Validations are created in a similar manner to an Nhibernate Mapping. Here is an example of a model entity with its mapping and validator. Simple entity validation can be performed anytime by instantiating the validator directly and testing the result: var validator = new ValidationTestEntityValidator(); var result = validator.Validate(entity);Validation can also be performed anytime by using the Validation Factory: var factory = new FluentValidatorFactory(); var validator = factory.CreateInstance(entity.GetType()); validator.Validate(entity);The ValidatorAttribute is applied to the model entity to let the ValidatorFactory know which validator to use. [Validator(typeof(ValidationTestEntityValidator))] public class ValidationTestEntity : ModelBase {When saving or updating an entity to an Nhibernate session there is no need to validate it first. A validation check is performed in the ModelBaseEventListener for all updates and inserts. If the entity fails to validate then a ValidationExcpetion will be thrown. Until v6.0 the ModelBaseEventListener will validate against both the Fluent and Castle validation frameworks. using (var session = NHibernateHelper.OpenSession()) { session.BeginTransaction(IsolationLevel.ReadUncommitted); var testObj = session.Load<ValidationTestEntity>(id); // THIS IS NOT A VALID CREDIT CARD NUMBER testObj.CreditCard = "123667"; // A VALIDATION EXCEPTION WILL BE THROWN BY COMMIT session.Transaction.Commit(); } The ModelBaseEventListener uses the NexPort FluentValidationFactory to create an instance of the proper validator. The factory stores singleton validator references in a ConcurrentDictionary in order to mitigate the performance hit incurred by constructing new validators. In my next article, I will discuss using Fluent Validation to validate model entities on the client side. In the meantime, please check out the Fluent Validation Documentation. About NexPort Solutions GroupNexPort Solutions Group is a division of Darwin Global, LLC, a systems and software engineering company that provides innovative, cost-effective training solutions and support for federal, state and local government, as well as the private sector.OKLAHOMA CITY – Dec. 7, 2011 – NexPort Solutions will release the latest version of NexPort Campus Jan. 1, 2012. NexPort Campus version 4.0.2 includes new reporting fields, the ability to share or copy test banks between organizations and suborganizations and section blogging capability.
NexPort Campus is a secure, hosted learning and knowledge management system. NexPort Campus also supports interactive engagement within learning communities through the use of videos, an individual calendar, shared documents, organization-wide webpages and threaded discussions. Additional system features include data interoperability with external systems, secure digital libraries with subscriber-only access and an integrated Student Information System (SIS). NexPort Campus also allows clients to become online providers of user-customized, on-demand training and education services. Clients operate within their own branded sites to deliver their specialized services independently of each other. Customers may subdivide their sites to establish and manage subordinate secure sites for their customers, subsidiaries or divisions. Each site provides privacy protection and security. Custom sites can be setup with Secure Sockets Layer technology (128-bit encryption) and a custom domain. About NexPort Solutions NexPort Solutions is a division of Darwin global, a software engineering company that provides innovative, cost-effective training solutions and support for federal, state and local government, as well as the private industry. |
Archives
December 2014
Categories |