Costumer Configuration |
How to programming a costumer configuration based on SIC
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
Create a standard class. Use SOWI Class template. And inherit the base class SOWI Win Helper PageConfiguration with data class of settings
/// <summary> /// Windows page for costumer configuration based on <see cref="PageConfiguration{DataItemClass}"/> /// </summary> public class PageConfigurationCostumer : SOWIWin.Helper.PageConfiguration<Costumer.Setting.ConfiguraitonCostumer> { // ... }
Declaration configuration data handling class (App) into class constructor
/// <summary> /// Initializes a new instance of class. /// Constructor without parameter /// </summary> public PageConfigurationCostumer() : base(new CostumerApp.Setting.ConfigurationCostumer()) { }
Create a standard class. Use SOWI Class template
/// <summary> /// Costumer configuration windows user interface /// </summary> public class WindowConfiguration { // ... }
Declaration objects: windows user interface object from SOWI Win Helper and costumer configuration page
/// <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();
Write logic for frame handling. This is a example with dictionary and enumeration
#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 user interface into the class constructor
/// <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
this.WindowConfigurationUI.Title = "SOWI Framework Configuration"; this.WindowConfigurationUI.FileFilter = "SOWI configuration files (*.sconfig)|*.sconfig|All files (*.*)|*.*"; this.WindowConfigurationUI.FilterIndex = 1;
Create a class based on SIC.FileXMLDataItemClass
/// <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> { }
Write a constructor with parameter of XML file
#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
Create a data class based on SIC.SettingSettingXML
/// <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
Write a constructor without parameter
#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
/// <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"/>
Definition setting fields
#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 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
/// <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"; } } }
/// <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()) { } }
/// <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 }
/// <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 }
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 }