MVC Localization - database

I'm trying to do localization in MVC3, and I want to use a database to store the resources. I've read up on resource providers, but I haven't found a way of using a resource provider without losing the strongly-typed access that a regular resource file has.
So, what is the best way to do localization, while maintaining strongly-typed access? (Ideally with a database too)

If you want to store the entries in a database you can do the same trick as the normal resource files in Visual Studio are doing for you.
Normally the resource file is parsed and a static class is generated from it. In your case you could us a T4 template(Code Generation and T4) to connect to the database and build a resource class from the 'Id' columns in your database you have the same resource class.
On startup you could load the translated strings from the database and initialize your T4 resource class with it.

The simple and effective way to do it, is just to use the NuGet package dedicated for storing resources in database and generating the Strongly Typed Resources.
NuGet Package: http://www.nuget.org/packages/Globsite.Globalization.Mvc
Project Site: http://globsite.net/GlobsiteGlobalizationLibrary
This package contains the ready to use and complex infrastructure for database stored resources, which implements .NET Resource-Provider Model.
Generated classes can be synchronized with a database with the T4 Template run, what can be done, for example, on each build.
You can use the resources like this:
#using MyResources.SampleSet
#Resources.SampleKey

Related

How to read data from SQLite database on Eclipse

I'm using a static database that I created with SQLite Database Browser. I put it in my assets folder and built a code to copy the database to a database variable (Does that make sense?) so I could read information from it. Problem is I don't know how - mostly the SQL queries involved - and what are your suggested methods do to that? In other words, what methods should I add to my Database Handler class (Or data adapter?) in order to present the data in a list view, for example.
Thank you for all your help.
Read the Android database documentation.
Copying your database from the assets folder is typically done in the onCreate and/or onUpgrade functions of your SQLiteOpenHelper-derived class.
This tutorial covers the basics:
Using the SQLite Database with ListView
As for naming things: use whatever names make sense in your application.

Can I use EF code-first with SQL Server CE on WPF?

I would like to use a local SQL Server CE in my app; I've read that using EF code-first I can let the system create the db starting from POCO classes; I've configured EFCodeFirst.SqlServerCompact using NuGet but it's not clear to me how can I use it in my WPF app....can anyone help me?
It doesn't really matter whether you use the default WPF style application development or MVVM pattern, as long as you have a separate data layer.
Your data layer should hide away all of the DB implementation logic, including the creation of the DB from the rest of your code.
You could implement it using the Repository pattern, but as long as it provides a known interface and definitions for the data objects that your business logic requires you should be okay.
Note that the data objects used by the other layers of code do not need to be the same as the POCO objects used by the DB.
If you have your data layer accessed by a Singleton class that implements the layer's interface then you could automatically call the DB creation code if the DB can not be found when DataLayer.Instance (for example) is called.
The important thing to remember is that only the internal workings of the datalayer should know where the data comes from the rest of your code should be DB agnostic, only caring that it has the data that it needs, not where it comes from.
As for practicalities here's a link that gives a Code First with EF example.

Integrating GeoDjango into existing Django project

I have a Django project with multiple apps. They all share a db with engine = django.db.backends.postgresql_psycopg2. Now I want some functionality of GeoDjango and decided I want to integrate it into my existing project. I read through the tutorial, and it looks like I have to create a separate spartial database for GeoDjango. I wonder if there is anyway around. I tried to add this into one of my apps' models.py without changing my db settings :
from django.contrib.gis.db.models import PointField
class Location(models.Model):
location = PointField()
But when I run syncdb, I got this error.
File "/home/virtual/virtual-env/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 200, in db_type
return connection.ops.geo_db_type(self)
Actually, as i recall, django.contrib.gis.db.backends.postgis is extension of postgresql_psycopg2 so you could change db driver in settings, create new db with spatial template and then migrate data to new db (South is great for this). By itself geodjango is highly dependent on DB inner methods thus, unfortunately, you couldn't use it with regular db.
Other way - you could make use of django's multi-db ability, and create extra db for geodjango models.
Your error looks like it comes from not changing the database extension in your settings file. You don't technically need to create a new database using the spatial template, you can simply run the PostGIS scripts on your existing database to get all of the geospatial goodies. As always, you should backup your existing database before doing this though.
I'm not 100%, but I think that you can pipe postgis.sql and spatial_ref_sys.sql into your existing database, grant permissions to the tables, and change the db setting to "django.contrib.gis.db.backends.postgis". (After you have installed the deps of course)
https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#spatialdb-template
I'd be interested to see what you find. Be careful, postgis installation can build some character but you don't want it to build too much.
From the docs (django 3.1) https://docs.djangoproject.com/en/3.1/ref/databases/#migration-operation-for-adding-extensions :
If you need to add a PostgreSQL extension (like hstore, postgis, etc.) using a migration, use the CreateExtension operation.

How do create a custom database driver for CodeIgniter

How do you create a custom database driver to extend CodeIgniter's functionalities to other types of database systems? I'm using iRODS (www.irods.org). I have a version of the site created using MySQL, but I want to be able to change the database backend with minimal changes. Is there an easy way to add this function, like how you can add a custom library in CI? I haven't been able to find any so far.
I'm assuming you mean how do you create a custom Active Record driver for codeigniter? Otherwise I'm probably far off the mark here but:
There is no way I know of to simply extend or override the DB classes it is not a common thing. You can implement your own and patch up your CI config to use the new DB though.
Under system/database/drivers you find all the AR driver source. You would need to reimplement each function in each of the four files (may be able to skip on forge if you don't use it.)
I'd use the MySQL driver as a starting template as you mention you already use that, in which case you'll want to make sure all the features you use are re-implemented.
It sounds like a daunting task if you're not too experienced but I assure you the code is pretty simple.

How do I load a module catalog from a database in Prism?

I'm using Prism in my WPF application and up to now, I've been loading the modules via var moduleCatalog = new ConfigurationModuleCatalog();. I'd like to get the module catalog from a database. The Prism documentation indicates that this is possible, but it doesn't go into any details.
Has anyone done this and can provide some guidance?
This is a theoretical possibility, but it's not in any samples I've seen.
Basically what you'd do is either base64 encode the DLLs / Files into the database or zip them up and store them in one blob. You'd download them in your bootstrapper and copy them locally (in a temp directory) and then allows them to load normally from the filesystem using the DirectoryModuleCatalog. If you wanted it to be a bit more elegant, you could write your own ModuleCatalog that encapsulates this logic.
This is very similar to what I do... I actually download a zip file of all of the modules from a website at launch time and unzip them and load them with the DirectoryModuleCatalog.
You can write your own ModuleCatalog implementation by implementing IModuleCatalog. Your implementation can then populate the catalog by any means you define.
You could also use the CreateFromXAML overload that accepts a Stream and implement a webservice that delivers the ModuleCatalog in XAML over HTTP.

Resources