Click here to Skip to main content
15,899,935 members
Home / Discussions / C#
   

C#

 
QuestionHow can I pass DataTable to view as JSON/XML code? Pin
Member 1079645326-Feb-17 23:34
Member 1079645326-Feb-17 23:34 
SuggestionRe: How can I pass DataTable to view as JSON/XML code? Pin
Richard MacCutchan27-Feb-17 0:30
mveRichard MacCutchan27-Feb-17 0:30 
AnswerRe: How can I pass DataTable to view as JSON/XML code? Pin
F-ES Sitecore28-Feb-17 3:08
professionalF-ES Sitecore28-Feb-17 3:08 
QuestionImage upload error javascript/c# Pin
John Nederveen26-Feb-17 3:00
John Nederveen26-Feb-17 3:00 
AnswerRe: Image upload error javascript/c# Pin
Richard Deeming26-Feb-17 5:33
mveRichard Deeming26-Feb-17 5:33 
GeneralRe: Image upload error javascript/c# Pin
John Nederveen26-Feb-17 8:15
John Nederveen26-Feb-17 8:15 
GeneralRe: Image upload error javascript/c# Pin
Dave Kreskowiak26-Feb-17 8:30
mveDave Kreskowiak26-Feb-17 8:30 
GeneralRe: Image upload error javascript/c# Pin
John Nederveen26-Feb-17 9:05
John Nederveen26-Feb-17 9:05 
GeneralRe: Image upload error javascript/c# Pin
Dave Kreskowiak26-Feb-17 10:48
mveDave Kreskowiak26-Feb-17 10:48 
QuestionWMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Member 1302224424-Feb-17 10:25
Member 1302224424-Feb-17 10:25 
AnswerRe: WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Michael_Davies24-Feb-17 10:37
Michael_Davies24-Feb-17 10:37 
GeneralRe: WMI Events can't get User | ManagementEventWatcher, __INstanceCreationEvent, Win32_Process GetOwner Pin
Member 1302224424-Feb-17 16:02
Member 1302224424-Feb-17 16:02 
QuestionHow to customize timer to fire my routine at specific time Pin
Tridip Bhattacharjee23-Feb-17 22:33
professionalTridip Bhattacharjee23-Feb-17 22:33 
AnswerRe: How to customize timer to fire my routine at specific time Pin
Pete O'Hanlon23-Feb-17 22:42
mvePete O'Hanlon23-Feb-17 22:42 
AnswerRe: How to customize timer to fire my routine at specific time Pin
OriginalGriff23-Feb-17 22:46
mveOriginalGriff23-Feb-17 22:46 
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 

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.