How do I do per-client localization in Silverlight? - silverlight

I'm trying to do custom per-client localization in Silverlight and am running into problems. I tried using custom cultures (en-US-c1, en-US-c2, etc), but found that doesn't work because the culture needs to exist on the client. Is there a good clean way to do this?

You'll need to write the user's culture to Isolated Storage
The values are stored as a Key/Value pair:
// Create an instance of IsolatedStorageSettings.
private IsolatedStorageSettings userSettings =
IsolatedStorageSettings.ApplicationSettings;
// Add a key and its value.
userSettings.Add("userCulture", "en-US-c1");
// Remove the setting.
userSettings.Remove("userCulture");
Just default the value to something sensible and you'll need an option to allow the user to select their culture.

Related

How to use containerRegistry.RegisterForNavigation with a generic ViewModel?

I have an app with two regions, one serving as a selector for data type (called NavigationPane) and the other one as a setter view for that data type (called SimulationPane). The SimulatorView.xaml I use to fill the SimulationPane has a corresponding SimulatorViewModel which dynamically creates a list of settable properties for TDataType and eventually binds it to a ItemsControl in SimulatorView.xaml. So my ViewModel needs System.Type as input:
I want to set it up as following:
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<TopicSelectorView, TopicSelectorViewModel>("Selector");
containerRegistry.RegisterForNavigation<SimulatorView, SimulatorViewModel<A>>("Simulator_A");
containerRegistry.RegisterForNavigation<SimulatorView, SimulatorViewModel<B>>("Simulator_B"); // and so on..
}
Once I have it registered, I want to be able to call (from other module):
regionManager.RequestNavigate("SimulationPane", $"Simulator_{topicType.Name}");
where topicType is the data type based on user's selection (here: 'A', 'B', and so on).
The problem with this approach is that I end up with just one ViewModel, i.e. the one I registered last. My impression is that that the registration uses some kind of dictionary with view as a key.
What am I doing wrong here? How else can I achieve my goal of being able to provide a type for VM at runtime, and navigate to it?
How else can I achieve my goal of being able to provide a type for VM at runtime, and navigate to it?
Register multiple viewmodels with the same view is not supported in Prism. See #brianlagunas answer on GitHub:
As I said in my reply to your PR, this is not something we will support in Prism. You have a few options, two of which we have already discussed; create a unique view, or have a single VM and load the relevant data.
Why do you need to pass A and B as generic parameters?
I'd have a single SimulatorViewModel and inject a service from which the view model can get the list of parameters to be set by the user. This could be done through reflection (on the simulator type) or a list of parameter descriptors (IReadOnlyCollection<Parameter> ISimulator.Parameters { get; }), whatever you prefer.
When changing the simulator type, you update it in the service and the SimulatorViewModel updates its list of parameters, because it listens to the service's INotifyPropertyChanged.PropertyChanged.

C1 as a store and editor for custom private files

Preface
Our site uses C1 as a CMS for public area (info, help, faq, etc.).
Our private area is implemented as a standalone ASP.NET app, so there almost no connection between the CMS and the app.
In the app there are ~50 email templates (HTML+razor), and almost all of them are localized (8 languages).
At the moment those templates are stored as files, and they are under the source control. Consequently, any editing is done by developers.
The goal
We'd like to put those template files under the control of Composite C1 and thereby make them editable by people who manage the content.
The key requirements:
The template files must not be accessible by the internet user; the CMS must only show them in the administration console and allow to edit them. It's easy to achieve this by putting the files in e.g. App_Data, so they will be observable in the System perspective, however it's not the best way when considering security, and it doesn't help with the following requirements.
It would be great to have the published/unpublished feature applied to these files, just like the pages in the Content perspective.
It would be great to use the built-in C1 localization feature, so that at a time only those files are visible, which are in the currently selected language.
The questions
Is there anybody who had experience with putting such private content under the C1 control?
In order to meet the requirements, would it make us to store our email templates in the CMS database instead of storing them as files?
UPDATE
In the Data perspective it's possible to create a custom global datatype suitable for storing email templates: it's just necessary to have at least one field "Body" of type String with the xhtml editor assigned to it. This way it's possible to add all the templates into the database, and there are abilities to make them published/unpublished and localized. The application would have to access the templates via the database, what is OK.
The only actual problem is that the xhtml editor should be reconfigured to allow non-strict html with razor. Any advice on that?
So, here is the solution we've ended with.
Create custom global datatype EmailTemplate in the Data perspective.
Tick the "Has publishing" checkbox in the Settings tab.
The most important fields are:
TemplateID - the string identifier of the email template
Body - the template text
The Body field should be thoroughly configured:
Field type: String
String maximum length: Unlimited length
Advanced config: Widget type: VisualXhtmlEditor
Enable Localization for the newly created datatype (see its context menu).
Edit Form Markup for the newly created datatype (see its context menu).
Replace the InlineXhtmlEditor element with the following code:
<TextEditor Label="Template" Help="" MimeType="application/x-cshtml">
<cms:bind source="Body" />
</TextEditor>
This way the editor is configured to support the html+razor syntax.
Show the datatype in Content perspective (see its context menu).
This way the email templates appear in the Website Items of the Content tree.
How the application can access the published email templates
In the CMS database the following tables will be created:
dbo.<datatype_name_with_namespace>_<culture_code>
dbo.<datatype_name_with_namespace>_Unpublished_<culture_code>
For example
dbo.Composite_EmailTemplate_en_GB
dbo.Composite_EmailTemplate_Unpublished_en_GB
dbo.Composite_EmailTemplate_de_DE
dbo.Composite_EmailTemplate_Unpublished_de_DE
...
Each table has columns that correspond the fields configured for the datatype, e.g. TemplateID and Body.
I believe now it's clear how to find certain template in certain culture.

Storing app preferences in Spring app

I'm working in a Spring MVC application that needs access to some variables that the admin user must set using a web wizard (smtp server, preferences, etc). I want to store this info in a database to be accessible by the app. Which is the best way to store this info?
Please spend some time with Section IV of Spring Reference Manual. There are plenty data persistence option supported by Spring. To name few popular ones: JDBC, JPA, Hibernate, XML
We use an approach with default values and a generic GUI. Therefore we use a property file that contains the default value as well as type information for every key. in the dayabdatabase we store only this values that have been modified by the user. The database schema is just a simple key value table. The key is the same like the one from the property file, the value is of type string, because we have to parse the default value anyway. The type info (int, positiveInt, boolean, string, text, html) from the propty file is used by the generic GUI to have the right input for every key.
Example:
default.properties
my.example.value=1
my.example.type=into
default.properties_en
my.example.title=Example Value
my.example.descruption=This is..
Db:
Key=string(256)
Value=string(2048)

Xpages - Convert a database searched document as currentDocument

I have an xPages form editing a document, which can be edited automatically (as a datasource) coming frme a view. But you can also input directly (in an input field) the key of the document; then (if it exists) it will be searched in the database (converting the key in an UNID).
The matter is that in this case it is not the currentDocument and custom controls tests (for example for displaying buttons) do not work.
So my question is how to "convert" a programmatically searched document in the database (by UNID) to the normal datasource currentDocument, so normal controls can be apply to it too ?
Thanks if you know.
Store the Unid in the session and compute the data source from there - or open the Form with the matching URL parameter
Your problem is in the URL: it does not contains params to initialize default data source. This is IMHO the simplest way to fix it: native Domino links and XPages.
I am not sure whether it will help, it depends on actual value of context.getUrl(). If it doesn't, you need to redirect to URL you compute from UNID, as Stephan suggested.

yii framework models database access object

I want to use the database access objects to access a table in my database instead of doing active record since that takes a long time to load. if I use database access objets instead (calling createCommand, query, execute, etc), do i still need to create a model class for the table? if so what would be the parent class of this model class? My goal is to access/edit the table values using yii database access objects. I'm using YII FRAMEWORK. Or is it best to use a component? If so, when do you usually have to use components? I don't understand what components are for....
No, you can create a generic class which has a member property of a CDbConnection. For that matter, you can just use CDbConnection, but you might end up creating a lot of connections that way.
class Foo
{
private $conn;
function __construct(){ $this->conn =
new CDbConnection($dsn,$username,$password); }
function runQuery($sql) {
$command=$connection->createCommand($sqlStatement);
return $command->query();
}
}
If you have your database settings in your config/main.php file, you can also do:
$command = Yii::app()->db->createCommand($sql);
$result = $command->queryAll();
and if you need to reset the command:
$command = false;
If you create a custom class, you don't need to reference a Model or extend an existing class, your connection will use CDbConnection (by using the method above or calling it directly in your connection statement).
this page has pretty clear info on Yii's DAO.
As far as components go, they can mean different things - there are Yii's "core components", which are things like urlManager, user, db, etc. and can have their default properties set in the config/main.php file. Then there is the "components" directory which can be configured to autoload classes and "contains components (e.g. helpers, widgets) that are only used by this application." So you can put custom classes in there that you want available throughout your app.
Components are used to make widgets.which is available through out the app.

Resources