Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Integrated Help system in a WPF Application

, 20 Jun 2013
Quick guideline to understand a workflow of screen without reading long and boring(!!) documentation guide.
integratedhelpinwpf-noexe.zip
IntegratedHelpInWPF
IntegratedHelpInWPF
AttachProperties
bin
Debug
DynamicHelpReference
IntegratedHelpInWPF.vshost.exe.manifest
Commands
DynamicHelpReference
IntegratedHelpInWPF.csproj.user
Languages
Popup
Properties
Settings.settings
Resources
integratedhelpinwpf.zip
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
Release
IntegratedHelpInWPF.csproj.user
obj
Debug
Resources
TempPE
Settings.settings
IntegratedHelpInWPF_Revised_-noexe.zip
IntegratedHelpInWPF.vshost.exe.manifest
Converter
IntegratedHelpInWPF.csproj.user
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
WishlistView.baml
Settings.settings
IntegratedHelpInWPF.v11.suo
IntegratedHelpInWPF_Revised_.zip
Assembly
System.Windows.Interactivity.dll
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
System.Windows.Interactivity.dll
IntegratedHelpInWPF.csproj.user
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.csproj.GenerateResource.Cache
IntegratedHelpInWPF.csprojResolveAssemblyReference.cache
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.cache
IntegratedHelpInWPF_MarkupCompile.i.cache
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
Properties.Resources.Designer.cs.dll
WishlistView.baml
Settings.settings
IntegratedHelpInWPF.v11.suo
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Morshed Anwar
Team Leader Adaptive Enterprise Limited (www.ael-bd.com)
Bangladesh Bangladesh
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Jun 2013
Article Copyright 2012 by Morshed Anwar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid