Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to customize timer to fire my routine at specific time Pin
Tridip Bhattacharjee23-Feb-17 22:50
professionalTridip Bhattacharjee23-Feb-17 22:50 
GeneralRe: How to customize timer to fire my routine at specific time Pin
OriginalGriff23-Feb-17 23:01
mveOriginalGriff23-Feb-17 23:01 
AnswerRe: How to customize timer to fire my routine at specific time Pin
Ralf Meier24-Feb-17 0:16
mveRalf Meier24-Feb-17 0:16 
QuestionInserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 8:16
Jammer23-Feb-17 8:16 
AnswerRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 9:53
mveGerry Schmitz23-Feb-17 9:53 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 10:16
Jammer23-Feb-17 10:16 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 11:35
mveGerry Schmitz23-Feb-17 11:35 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 13:04
Jammer23-Feb-17 13:04 
I might not have explained my question properly to be honest.

Localising an application using Resx and custom UI binders for XAML, iOS and Android Xamarin apps is fine. I've done all these things before. Handling RTL globalisation in WPF apps is also something I've done before as well.

I was basically looking for inspiration regarding taking localised strings from RESX files and populating various database tables with lookup values for things.

What I've ended up doing is implementing the Builder pattern to aggregate key value pairs from these RESX files and utilising my repository pattern bits to automatically populate these lookup tables on the initial creation of the SQLite db3 file.

My base builder class looks like this (not perfect by a long shot, there is no abstraction of the connection I can use for instance):

public abstract class LookupBuilderBase<T> where T : class, IEntity, new()
{
    protected SQLiteAsyncConnection AsyncConnection;
    protected IDictionary<string, string> LookupData;
    protected IRepository<T> Repository;
    protected readonly IList<T> Data = new List<T>();

    protected LookupBuilderBase(SQLiteAsyncConnection conn, IDictionary<string, string> lookupData)
    {
        AsyncConnection = conn;
        LookupData = lookupData;
    }

    public async Task Execute()
    {
        CreateRepository();
        BuildData();
        await InsertData();
    }

    protected abstract void BuildData();

    protected virtual async Task InsertData()
    {
        foreach (var item in Data)
        {
            await Repository.Insert(item);
        }
    }

    private void CreateRepository()
    {
        Repository = new Repository<T>(AsyncConnection);
    }
}


I can then write builders like this:

public class CategoryBuilder : LookupBuilderBase<Category>
{
    public CategoryBuilder(SQLiteAsyncConnection conn, IDictionary<string, string> lookupData)
        : base(conn, lookupData)
    {
    }

    protected override void BuildData()
    {
        var values = LookupData.Where(x => x.Key.StartsWith("Category"));
        foreach (var keyValuePair in values)
        {
            Data.Add(new Category { Name = keyValuePair.Value });
        }
    }
}

Jammer
My Blog | JamSoft

GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 13:36
mveGerry Schmitz23-Feb-17 13:36 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 13:45
Jammer23-Feb-17 13:45 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 13:54
mveGerry Schmitz23-Feb-17 13:54 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 20:34
Jammer23-Feb-17 20:34 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 20:38
mveGerry Schmitz23-Feb-17 20:38 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Jammer23-Feb-17 20:49
Jammer23-Feb-17 20:49 
GeneralRe: Inserting Localised Lookup Data into a Fresh Database Pin
Gerry Schmitz23-Feb-17 21:28
mveGerry Schmitz23-Feb-17 21:28 
AnswerRe: Inserting Localised Lookup Data into a Fresh Database Pin
Bernhard Hiller23-Feb-17 21:32
Bernhard Hiller23-Feb-17 21:32 
Questionwhy not escape to catch an error when i next run? Pin
Member 245846723-Feb-17 2:18
Member 245846723-Feb-17 2:18 
AnswerRe: why not escape to catch an error when i next run? Pin
OriginalGriff23-Feb-17 2:40
mveOriginalGriff23-Feb-17 2:40 
GeneralRe: why not escape to catch an error when i next run? Pin
Member 245846723-Feb-17 16:08
Member 245846723-Feb-17 16:08 
GeneralRe: why not escape to catch an error when i next run? Pin
OriginalGriff23-Feb-17 20:35
mveOriginalGriff23-Feb-17 20:35 
GeneralRe: why not escape to catch an error when i next run? Pin
Member 24584672-Mar-17 16:03
Member 24584672-Mar-17 16:03 
AnswerRe: why not escape to catch an error when i next run? Pin
Eddy Vluggen23-Feb-17 2:43
professionalEddy Vluggen23-Feb-17 2:43 
QuestionVS c# 2015 Setup Project: How to force Rollback before commit on my own condition Pin
nemo1423-Feb-17 1:07
nemo1423-Feb-17 1:07 
AnswerRe: VS c# 2015 Setup Project: How to force Rollback before commit on my own condition Pin
OriginalGriff23-Feb-17 1:22
mveOriginalGriff23-Feb-17 1:22 
AnswerRe: VS c# 2015 Setup Project: How to force Rollback before commit on my own condition Pin
Bernhard Hiller23-Feb-17 21:39
Bernhard Hiller23-Feb-17 21:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.