This is a quick guideline to get rid of reading long and boring documentation and give you very basic information about a screen.
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Xml.Linq;
using IntegratedHelpInWPF.AttachProperties;
namespace IntegratedHelpInWPF.Languages
{
public class DynamicHelpStringLoader
{
private const string HelpStringReferenceFolder = "DynamicHelpReference";
private const string UsFileName = "DynamicHelp_EN_US.xml";
private const string FrFileName = "DynamicHelp_FR.xml";
private const string EsFileName = "DynamicHelp_ES.xml";
private const string DefaultFileName = "DynamicHelp_EN_US.xml";
/// <summary>
/// This is the collection where all the JerichoMessage objects
/// will be stored.
/// </summary>
private static readonly Dictionary<string, DynamicHelpModel> HelpMessages;
private static Languages _languageType;
/// <summary>
/// The static constructor.
/// </summary>
static DynamicHelpStringLoader()
{
HelpMessages = new Dictionary<string,DynamicHelpModel>();
_languageType = Languages.None;
}
/// <summary>
/// Generates the collection of JerichoMessage objects as if the provided language.
/// </summary>
/// <param name="languages">The Languages enum. Represents the user's choice of language.</param>
public static void GenerateCollection(Languages languages)
{
if (_languageType == languages)
{
return;
}
_languageType = languages;
string startUpPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
string fileName;
switch (languages)
{
case Languages.English:
fileName = UsFileName;
break;
case Languages.French:
fileName = FrFileName;
break;
case Languages.Spanish:
fileName = EsFileName;
break;
default:
fileName = DefaultFileName;
break;
}
Task.Factory.StartNew(() =>
{
LoadXmlFile(Path.Combine(startUpPath,
string.Format(@"{0}\{1}", HelpStringReferenceFolder,
fileName)));
});
}
/// <summary>
/// Load the provided xml file and populate the dictionary.
/// </summary>
/// <param name="fileName"></param>
private static void LoadXmlFile(string fileName)
{
XDocument doc = null;
try
{
//Load the XML Document
doc = XDocument.Load(fileName);
//clear the dictionary
HelpMessages.Clear();
var helpCodeTypes = doc.Descendants("item");
//now, populate the collection with JerichoMessage objects
foreach (XElement message in helpCodeTypes)
{
var key = message.Attribute("element_name").Value;
if(!string.IsNullOrWhiteSpace(key))
{
var index = 0;
//get all Message elements under the help type
//create a JerichoMessage object and insert appropriate values
var dynamicHelp = new DynamicHelpModel
{
Title = message.Element("title").Value,
HelpText = message.Element("helptext").Value,
URL = message.Element("moreURL").Value,
ShortCut = message.Element("shortcut").Value,
FlowIndex = (int.TryParse(message.Element("flowindex").Value, out index)) ? index : 0
};
//add the JerichoMessage into the collection
HelpMessages.Add(key.TrimStart().TrimEnd(), dynamicHelp);
}
}
}
catch (FileNotFoundException)
{
throw new Exception(LanguageLoader.GetText("HelpCodeFileNotFound"));
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// Returns mathced string from the xml.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DynamicHelpModel GetDynamicHelp(string name)
{
if(!string.IsNullOrWhiteSpace(name))
{
var key = name.TrimStart().TrimEnd();
if(HelpMessages.ContainsKey(key))
return HelpMessages[key];
}
return new DynamicHelpModel();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In my childhood, my uncle has shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that the cloud becomes closer to me and It teaches me one thing that, a deeper-look to something will give you some clues to draw your imagination. You can able to see that one which you have build-up in your mind.
Years past, I have started my career as a software engineer and has been looking for passion in my coding and development which I should be to enjoy my profession and has started asking myself- 'am I doing any engineering here?!' Is my code becoming that thing which I have designed in my mind? So to find that answer I have tried that old solution here... I have decided to come closer to my code and start analyzing them. And it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. It also helps me to think out of the box, solve each problems by making blocks and make me careful on each steps.
• Morshed's Technical Blog site: http://morshedanwar.wordpress.com/
• Morshed's Technical articles those are published in Codeproject site: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=2992452
• Morshed's Linkedin profile: http://www.linkedin.com/in/morshedanwar
• Morshed's Facebook Profile : http://www.facebook.com/morshed.pulok
Beside all these I like to do - photography and music. Here is my Flickr photos : http://www.flickr.com/photos/morshed_anwar/