Click or drag to resize

Costumer Configuration

User Interface

The user interface has tow parts: a WPF page part and a WPF window part

Page: handling the data items of configuration

Windows: handling the configuration file

Note: a window can contain more than one page

Costumer configuration page user interface

  1. Create a standard class. Use SOWI Class template. And inherit the base class SOWI Win Helper PageConfiguration with data class of settings

    C#
    /// <summary>
    /// Windows page for costumer configuration based on <see cref="PageConfiguration{DataItemClass}"/>
    /// </summary>
    public class PageConfigurationCostumer : SOWIWin.Helper.PageConfiguration<Costumer.Setting.ConfiguraitonCostumer>
    {
          // ...
    }
  2. Declaration configuration data handling class (App) into class constructor

    C#
    /// <summary>
    /// Initializes a new instance of class.
    ///    Constructor without parameter
    /// </summary>
    public PageConfigurationCostumer() : base(new CostumerApp.Setting.ConfigurationCostumer()) { }

Costumer configuration windows user interface

  1. Create a standard class. Use SOWI Class template

    C#
    /// <summary>
    /// Costumer configuration windows user interface
    /// </summary>
    public class WindowConfiguration
    {
          // ...
    }
  2. Declaration objects: windows user interface object from SOWI Win Helper and costumer configuration page

    C#
    /// <summary>
    /// Window configuration user interface
    /// </summary>
    public SOWIWin.Helper.WindowConfiguration WindowConfigurationUI = new SOWIWin.Helper.WindowConfiguration();
    
    /// <summary>
    /// Costumer configuration page
    /// </summary>
    internal Costumer.Pages.PageConfigurationCostumer PageConfigurationCostumer = new Pages.PageConfigurationCostumer();
  3. Write logic for frame handling. This is a example with dictionary and enumeration

    C#
    #region --- frames handling ---
    
            /// <summary>
            /// Configuration tab page enumeration
            /// </summary>
            private enum Tabs
            {
                none = -1,
                CostumerConfiguration
            }
    
            /// <summary>
            /// List of WPF frames with tabs index
            /// </summary>
            private Dictionary<Tabs, Frame> Frames { get; set; }
    
            /// <summary>
            /// Initialization WPF frames
            /// </summary>
            private void InitializeFrame()
            {
                //* Frame object list with index of enumeration Tabs *
                this.Frames = new Dictionary<Tabs, Frame>();
    
                Tabs lTab;
                TabItem lTabItem;
                Frame lFrame;
    
                //* creates tab (TabItem and Frame) according to enumeration Tabs *
                foreach (var item in Enum.GetNames(typeof(Tabs)))
                {
                    if (item.ToString() != Tabs.none.ToString())
                    {
                        lTab = SOWIData.Helper.Enumeration.Parse<Tabs>(item);
                        lTabItem = new TabItem()
                        {
                            Header = lTab.ToString()
                        };
                        lFrame = new Frame()
                        {
                            Name = "Frame" + lTab.ToString(),
                            NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Hidden
                        };
                        this.Frames.Add(lTab, lFrame);
                        lTabItem.Content = lFrame;
                        this.WindowConfigurationUI.TabMain.Items.Add(lTabItem);
                    }
                }
            }
    
    #endregion
  4. Setting user interface into the class constructor

    C#
    /// <summary>
    /// Initializes a new instance of the class.
    ///    Constructor without parameter
    /// </summary>
    public WindowConfiguration() 
    {
        this.InitializeFrame();
        this.WindowConfigurationUI.Title = "Costumer Configuration";
        this.WindowConfigurationUI.FileFilter = "Costumer configuration files (*.config)|*.config|All files (*.*)|*.*";
        this.WindowConfigurationUI.FilterIndex = 1;
    
        this.Frames[Tabs.CostumerConfiguration].Content = this.PageConfigurationCostumer.PageConfigurationUI;
        this.WindowConfigurationUI.FileNameChange += this.PageConfigurationCostumer.OnFileNameChange;
        this.WindowConfigurationUI.SaveAs += this.PageConfigurationCostumer.OnSaveAs;                      
    }

    The configuration file can same file be SOWI Framework uses

    C#
    this.WindowConfigurationUI.Title = "SOWI Framework Configuration";
    this.WindowConfigurationUI.FileFilter = "SOWI configuration files (*.sconfig)|*.sconfig|All files (*.*)|*.*";
    this.WindowConfigurationUI.FilterIndex = 1;
Handling

Costumer configuration handling class (App)

  1. Create a class based on SIC.FileXMLDataItemClass

    C#
    /// <summary>
    /// List of settings
    /// </summary>
    /// <remarks>
    /// Data based on XML file
    /// </remarks>
    /// <seealso cref="SIC.File.XML{DataItemClass}"/>              
    public class Path : SIC.File.XML<CostumerData.Setting.Path>
    {
    }
  2. Write a constructor with parameter of XML file

    C#
    #region --- constructors ---
    
    /// <summary>
    /// Initializes a new instance of class.
    ///    Constructor with parameter
    /// </summary>
    /// <param name="pFileName">Setting XML file</param>
    public Path(string pFileName) : base(pFileName) { }
    
    #endregion
Data Model

Costumer configuration data class

  1. Create a data class based on SIC.SettingSettingXML

    C#
    /// <summary>
    /// Setting data
    /// </summary>
    /// <seealso cref="SIC.Setting.SettingXML"/>
    [Table("Path")]
    public class Path : SIC.Setting.SettingXML
    {              
    }
    The attribute Table using System.ComponentModel.DataAnnotations.Schema
  2. Write a constructor without parameter

    C#
    #region --- constructors ---
    
    /// <summary>
    /// Initializes a new instance of setting data class.
    ///    Constructor without parameter
    /// </summary>
    public Path() { }
    
    #endregion

    Sometimes it's helpful to write a constructor with data parameter

    C#
    /// <summary>
    /// Initializes a new instance of the setting data class.
    /// Constructor with setting data parameter.
    /// </summary>
    /// <param name="pName">Name of setting</param>
    /// <param name="pHomeDrive">See property HomeDrive</param>
    /// <param name="pGroupDrive">See property GroupDrive</param>                
    public Path(string pName, string pHomeDrive = "", string pGroupDrive = "")
    {
        this.Name = pName;
        this.HomeDrive = pHomeDrive;
        this.GroupDrive = pGroupDrive;
    }
    Text "See property" can replace with see tag an example <see cref="CostumerData.Setting.Path.GroupDrive"/>
  3. Definition setting fields

    C#
    #region --- fields ---
    
    /// <summary>
    /// Home drive example H:\
    /// </summary>
    public string HomeDrive { get; set; }
    
    /// <summary>
    /// Group drive example G:\
    /// </summary>
    public string GroupDrive { get; set; }
    
    #endregion
Where store the configuration file?

Where is the best hands one to store a costumer configuration file?

Standard folder for storage of configuration files is directory App_Data. Method ConfigurationDirectory gives this folder.

An example by namespace CostumerData.Setting create a class Configuration

C#
/// <summary>
/// Costumer configuration
/// </summary>
public static class Configuration
{
    /// <summary>
    /// Gives costumer configuration filename (Costumer.config) include path (App_Data)
    /// </summary>
    /// <seealso cref="SIC.Settings.Configuration.Directory"/>
    public static string FileName
    {
        get
        {
            return SIC.Settings.Configuration.Directory + "Costumer.config";
        }
    }

}
Complete code example
Configuration page
/// <summary>
/// Windows page for costumer configuration based on <see cref="PageConfiguration{DataItemClass}"/>
/// </summary>
public class PageConfigurationCostumer : SOWIWin.Helper.PageConfiguration<Costumer.Setting.ConfiguraitonCostumer>
{
    /// <summary>
    /// Initializes a new instance of class.
    ///    Constructor without parameter
    /// </summary>
    public PageConfigurationCostumer() : base(new CostumerApp.Setting.ConfigurationCostumer()) { }                            
}
Configuration window
/// <summary>
/// Costumer configuration windows user interface
/// </summary>
public class WindowConfiguration
{

    /// <summary>
    /// Initializes a new instance of the class.
    ///    Constructor without parameter
    /// </summary>
    public WindowConfiguration() 
    {
        this.InitializeFrame();
        this.WindowConfigurationUI.Title = "Costumer Configuration";
        this.WindowConfigurationUI.FileFilter = "Costumer configuration files (*.config)|*.config|All files (*.*)|*.*";
        this.WindowConfigurationUI.FilterIndex = 1;

        this.Frames[Tabs.CostumerConfiguration].Content = this.PageConfigurationCostumer.PageConfigurationUI;
        this.WindowConfigurationUI.FileNameChange += this.PageConfigurationCostumer.OnFileNameChange;
        this.WindowConfigurationUI.SaveAs += this.PageConfigurationCostumer.OnSaveAs;                      
    }

    /// <summary>
    /// Window configuration user interface
    /// </summary>
    public SOWIWin.Helper.WindowConfiguration WindowConfigurationUI = new SOWIWin.Helper.WindowConfiguration();

    /// <summary>
    /// Costumer configuration page
    /// </summary>
    internal Costumer.Pages.PageConfigurationCostumer PageConfigurationCostumer = new Pages.PageConfigurationCostumer();

    #region --- frames handling ---

            /// <summary>
            /// Configuration tab page enumeration
            /// </summary>
            private enum Tabs
            {
                none = -1,
                CostumerConfiguration
            }

            /// <summary>
            /// List of WPF frames with tabs index
            /// </summary>
            private Dictionary<Tabs, Frame> Frames { get; set; }

            /// <summary>
            /// Initialization WPF frames
            /// </summary>
            private void InitializeFrame()
            {
                //* Frame object list with index of enumeration Tabs *
                this.Frames = new Dictionary<Tabs, Frame>();

                Tabs lTab;
                TabItem lTabItem;
                Frame lFrame;

                //* creates tab (TabItem and Frame) according to enumeration Tabs *
                foreach (var item in Enum.GetNames(typeof(Tabs)))
                {
                    if (item.ToString() != Tabs.none.ToString())
                    {
                        lTab = SOWIData.Helper.Enumeration.Parse<Tabs>(item);
                        lTabItem = new TabItem()
                        {
                            Header = lTab.ToString()
                        };
                        lFrame = new Frame()
                        {
                            Name = "Frame" + lTab.ToString(),
                            NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Hidden
                        };
                        this.Frames.Add(lTab, lFrame);
                        lTabItem.Content = lFrame;
                        this.WindowConfigurationUI.TabMain.Items.Add(lTabItem);
                    }
                }
            }

    #endregion

}
Setting handling class (App)
/// <summary>
/// List of settings
/// </summary>
/// <remarks>
/// Data based on XML file
/// </remarks>
/// <seealso cref="SIC.File.XML{DataItemClass}"/>              
public class Path : SIC.File.XML<CostumerData.Setting.Path>
{
    #region --- constructors ---

    /// <summary>
    /// Initializes a new instance of class.
    ///    Constructor with parameter
    /// </summary>
    /// <param name="pFileName">Setting XML file</param>
    public Path(string pFileName) : base(pFileName) { }

    #endregion

}
Setting data class
using System.ComponentModel.DataAnnotations.Schema;

/// <summary>
/// Setting data
/// </summary>
/// <seealso cref="SIC.Setting.SettingXML"/>
[Table("Path")]
public class Path : SIC.Setting.SettingXML
{  
    #region --- constructors ---

    /// <summary>
    /// Initializes a new instance of setting data class.
    ///    Constructor without parameter
    /// </summary>
    public Path() { }

    /// <summary>
    /// Initializes a new instance of setting data class.
    /// Constructor with setting data parameter.
    /// </summary>
    /// <param name="pName">Name of setting</param>
    /// <param name="pHomeDrive">See property HomeDrive</param>
    /// <param name="pGroupDrive">See property GroupDrive</param>                
    public Path(string pName, string pHomeDrive = "", string pGroupDrive = "")
    {
        this.Name = pName;
        this.HomeDrive = pHomeDrive;
        this.GroupDrive = pGroupDrive;
    }

    #endregion

    #region --- fields ---

    /// <summary>
    /// Home drive example H:\
    /// </summary>
    public string HomeDrive { get; set; }

    /// <summary>
    /// Group drive example G:\
    /// </summary>
    public string GroupDrive { get; set; }

    #endregion

}
See Also