How to localize MVC with database backed resources - database

I have read most of the literature Google and SO provides on this (correct me if I've missed something).
What I am trying to do is to localize an MVC site using resources, I want the compiletime safety of strongly typed resource files (ResX) but the flexibility of the ASP.NET 2.0 Resource-Provider Model, or something similar to that. I dont mind doing some work but it seems all paths I've researched lead to a dead end.
For displaying localized text in views I can hack together a helper to pull resources from HttpContext.Get(Global|Local)ResourceObject but that gets me nowhere when it comes to model validation and scaffolding, I suppose I could subclass the attributes and provide data but since it means pulling stuff from HttpContext I doubt that is available at the time the attributes are activated.
Since the direction localization in MVC seems to be toward ResX files and away from the 2.0 Resource-Provider model I could try to inject myself in the classes generated by the ResXFileCodeGenerator with a custom ResXFileCodeGenerator to provide my own ResourceProvider but that is terribly hackish involving custom Visual Studio Addins and codegeneration.
So my question is basically, what's the story with flexible MVC localization?
The referenced literature below:
http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html
http://msdn.microsoft.com/en-us/library/aa905797.aspx
http://www.eworldui.net/blog/post/2008/10/ASPNET-MVC-Simplified-Localization-via-ViewEngines.aspx
http://ryanrivest.com/blog/archive/2010/01/15/reusable-validation-error-message-resource-strings-for-dataannotations.aspx
http://www.codeproject.com/KB/dotnet/ResXFileCodeGeneratorEx.aspx

A resource provider should work fine (i.e. http://msdn.microsoft.com/en-us/library/aa905797.aspx). I've been using this in some projects with a SQL Server backed provider, works fine. It allows you to use all ASP.NET localization features and all the validation attribute translations using resources as well.

Please try a dedicated NuGet package for localization of MVC applications with database resources:
Globsite.Globalization.Mvc
It is built on the native ASP.NET Resource-Provider Model, so it can be integrated with your application in the similar way like standard ResX resources.
What is more, the library allow you to generate Strongly Typed Resources just with a single click, if you need.
The project site with more details:
globsite.net/GlobsiteGlobalizationLibrary

Related

Guide to migrate Silverlight application

We are planning to migrate our Silverlight application which having both business and UI logic to new technology. Is there any standard procedures or tools available for silverlight migration.
We want to move to standard technology like html and supported by all windows/mac/Linux browsers. Please give us any suggestions
There is no straight-forward migration path from Silverlight to any technology, despite probably to WPF to a degree, but as you mentioned that you want to run in the browser, probably the best way today is to use Blazor, which just got its first official release, and Microsoft is heavily investing in it right now.
On top of that, the French company Userware created the OpenSilver platform, which is a Silverlight replacement based on WebAssembly and Blazor, compatible with all major browsers. They even provide professional migration services based on this approach.
There is also rich ecosystem already evolved, with a lot of third-party UI components vendors (like Telerik, DevExpress, Radzen, etc.).
At Mobilize.Net we have a migration tool that converts the client side XAML and C# to TypeScript using Angular, Kendo UI, HTML, and CSS. It supports C# constructs like generics and interfaces.
You can watch a live stream from Twitch here This is an approach most suitable for very large complex SL web apps that would be too time consuming or expensive to rewrite into a pure native approach.

Building a Single Page Application with AngularJS and Sitecore (SPA)

I want to implement Sitecore application (single page design with angular js) :
Is that possible ?
If it is possible, what about experience editor, it will work with it ?
What about Sitecore personalization ?
I have no experience with angular js. what should I take in my consideration to achieve this
I will use Sitecore 8. i found this helpful blog about that but as he mentioned, page editor simply won't work
Thanks.
1.
Yes it is possible, I implemented a SPA in Sitecore 7 using AngularJS for the front-end and WebAPI to serve the data from Sitecore Items and it all worked really well together.
You could look into using Sitecore MVC Controllers which will work just as well as WebAPI. Or if you have time to learn a new Sitecore Technology you can look into using Sitecore's Entity Service. Either will work for serving data from Sitecore.
From experience I recommend you make controllers which are responsible for a single type of data consumed by the AnglarJS. The models passed by the controllers should be lean, containing only data relevant to the controllers purpose.
2.
For my implementation, the Experience Editor would not work as I used AngularJS to manipulate and present the data. It could be possible to use Sitecore Controls if you don't pull out the data using AngularJS but I don't think it'll be possible without hacking at it with code.
3.
Personalisation through the Experience Editor should be possible if you use Sitecore Controls. Personalisation through the Content Editor and code will be possible. I recommend you build your SPA as you would most Sitecore implementations; Layout, Sublayout etc. You can implement personalisation through code in the Controllers, Application Logic etc
4.
I had no experience with AngularJs either but I learned everything I needed to know from tutorials and the rest is logical enough for you to figure out if you're familiar with any programming language. I recommend you work through this Codecademy Tutorial that has you completing exercises - its how I learned.
I've yet to write a blog on how I achieved it but Dave Peterson has written two blogs on his experiences with SPA with Sitecore and AngularJs that might be worth a read.
Yes it is possible
Yes you can use the experience editor, BUT you have to build the site in a specific way. Not in the "normal" way.
Again, same as experience editor, you can use it, but the site has to be built to accommodate that.
Not sure on Angular - I have used backbone, but the principles are very similar.
I have a blog post on how we achieved this for a client: http://www.sitecorenutsbolts.net/2015/12/07/Single-Page-Applications-in-Sitecore-Part-I/
Have a read of that, it gives the principles you should follow to enable Sitecore in an SPA.
Anything is possible in Sitecore, but some customization are too complex to be considered practical.
You can easily build SPA application with the following limitations:
Display various views with either
a) server generated templates, or
b) static .html template with Sitecore-managed content (retrieved as json via custom controllers or Content API) and bound to template using AngularJS.
Limit the scope of personalization to just content.
Have experience or page editor view significantly different from the end-user experience. And even then, this will require separate design to create and maintain.
What is significantly more challenging is:
Utilize Personalization to dynamically display different renderings. Hide/show renderings, etc.
Have Experience Editor reflect the actual design of the SPA experience

Cucumber.js testing without relying any web browsers(Headless or real web browsers)

I was a .net based windows application developer and being a web developer now.
For the last couple of years, I tried to follow principles of Specification by example in a project.
On the last project I was involved, our team used WPF with MVVM(Model-View-ViewModel) pattern and I tried SpecFlow for testing. (Well.. the coverage by SpecFlow was very low though cause it was not officially adopted from our team and I couldn't spend enough time on it.)
Now our team started to migrate the existing windows application to a web based application and decided to use cucumber.js as a tool for implementing 'Specification by example'.
When I was trying SpecFlow before, I made all the step definitions to test ViewModel layer instead of View and it was the only way actually. What I'm confused with cucumber.js is that most of examples demonstrate how to test features via web browsers(headless or real ones).
If the features are specifying specific ui behaviors then accessing a DOM element and evaluating its value make sense. However, as far as I learned about Specification by examples, testing under the UI layer is recommended instead of UI elements directly.
It seems like most of modern web applications have layers such as MVC, MVVM(knouckout.js) nowadays. Our web application will use Angularjs and this is my theory.
I guess it is possible to use feature files - which do not state any specific UI controls and behaviors - to test under the skin of UI layer, without relying browser support. That layer would be Model of angularjs, not ui elements.
Is this approach missing something or wrong with cucumber.js?
Please give me some insights and correct me if I'm wrong.
Thanks in advance!
Specification by example specifies requirements by giving examples from the point of view of the user. What's more representative of the user: clicking items on a web page, or directly calling code? A user won't be calling methods on your view model, so in my opinion a feature test is a much better way to test expected behaviour.

Web database application architecture

There is a medium size database application that needs to be built featuring a web interface. The platform is asp.net 3.5 (asp.net mvc 2), sql server and ext.net 1.3.0. The tool is visual studio 2010.
I wonder, should I start with the database design and business logic and move on to the UI when I've a complete working draft/skeleton? Or should I build the database and BL step by step and bind them to the web UI as I progress?
Even more specifically, should I construct the whole BL functionality as a separate dll project and then have it referenced by the web application project? If so, what communication options do I have? web services, for example?
Last but not least, the web application requires a security mechanism (user accounts etc). Should I design and integrate it right from the start or can I add it when everything else is ready?
(I hope my question is clear enough. As far as I know, creating a dozen or more aspx pages as a means of building and testing the application functionality leads to all shorts of problems and dead ends while being extremely time consuming. What I seek is a way to separate the UI from everything else. Something like having a working prototype to show case to the customer and have the (ext.net) web UI built later as a completely separate step.)
Is there a particular reason why you are not planning on using .NET 4.0 and MVC 3? MVC 3 comes with the razor view engine, which produces much nicer and cleaner views. And if you use .NET 4.0 you can use the Entity Framework. The new Entity Framework 4.3 lets you use code first with migrations, which might be a good way to go in a project where you need to "explore" the requirements in collaboration with the customer. Using code first you build your model using POCO classes and let EF take care of the database schema. This is effective if you make lots of changes to your model, which it sound like you might want to. Check out this video for a good introduction to code first with migrations.

Lightswitch evaluation and questions

There seems to have a buzz around the Lightswitch application framework.
Reading some posts/forums/articles and listening to a video provdided some answers, but raised some others.
Extensibility?
Is there several hooks to override or extend features?
Modularity? Can MEF/Prism be integrated? Is there a concept of dynamic modules that can be loaded at runtime?
Localizable? Any special features about localization in different languages?
Versionnable? Any concept of version so simultaneous version can co-exist?
Abstraction? The connection to data source can be abstracted and replaced?
Testability? Are the different components unit testable in an automated way? Easy or difficult to achieve?
Cross-cutting / NFR ? Any hooks so we can plug NFR code? (logging, caching, audit, secuity )
Is this a solid framework to build some PAAS application over?
Let me give you my 2 cents based on an eval I just did:
Extensibility
You can of course add custom controls and apparently there will be a published extensability API.
Modularity
No. Lightswitch is not a code generator, it abstracts out implementation of the UI.
Localizable
Did not see anything, but I imagine this will occur in stages.
Versionnable?
You could TFS the Lightswitch project, but if you mean versioning from an execution standpoint ... it's as simple as deploying a new version of the app to the server. The client will check for updates on run and install as necessary from what I understand.
Abstraction
Yes, if you abstract it at the WCF RIA Services layer which is very easy to do.
Testability
Business rules can be implemented at the RIA Services layer so testing there should be a snap, but if you rely heavily on rules driven through the UI you will have to use another UI-based testing tool.
Cross-cutting / NFR
If you focus on getting the RIA Services tier of the app to be the central location for business rules and let the UI just focus on user experience you won't run into much overlap. I think Lightswitch is a good client for many solutions, but the core power of it is using it as a client for RIA Services which itself is not dependent on Lightswitch by any stretch.
I hope I at least provided some useful insight.
Extensibility? When the built-in LS controls don't allow you to do what you need, you can use just about any Silverlight control (including 3rd party controls), or create your own custom Silverlight controls. There is a little more work to do than using LS controls, because the LS controls have some extra "smarts" built into them, so you can just drop them on a screen, bind, & use them. There are also extensibility points built into the framework that allows you to create your own "extensions" (shells, controls, themes etc).
Modularity? LS already uses MEF under the covers, so it's quite possible that it may be able to be leveraged further in the future. LS does generate code, but for itself, not for external consumption. There is an excellent article, however, by Microsoft's Eric Erhardt
http://blogs.msdn.com/b/lightswitch/archive/2011/04/08/how-do-i-display-a-chart-built-on-aggregated-data-eric-erhardt.aspx
that shows how to reuse the data model that LS constructs (in Eric's case, he uses it to create a RIA service that aggregates data for presentation in a chart control).
Localizable? I don't believe there are currently any built-in localisation features.
Versionable? For a web-based app, if the data schema didn't change, I don't see why you couldn't publish separate versions, but desktop (OOB) apps are click-once apps & are therefore governed by that technology.
Abstraction? If you were to create a RIA service for your data source, you could abstract away the implementation details.
Testability? Unfortunately, V1 was not written with "testability" in mind. If you extract out your business logic into Silverlight class libraries (for use on the client, or full .NET class libraries for use on the server), you can unit test that logic, but the code that you write in an LS application itself is not really unit-testable at this point in time.

Resources