/// Create new instance of dialog showing module's properties /// <param name="configItem">The object with module's configuration</param> /// <param name="parent">Pointer to parent window (this dialog will be closed when window will be destroyed)</param> public ModulePropertyDialog(BConfigItem configItem, Gtk.Window parent) : base(parent) { this.configItem = configItem; // initialize dialog's widgets InitializeDialog(configItem, "/beline/conf/module/configuration"); // connect signals to handlers btnClose.Clicked += new EventHandler(btnClose_click); }
private BConfigManager() { // create global configuration globalConf = new BConfigItem(Path.Combine(LibBeline.GlobalPath, "global.conf")); globalConf.ImportGlobalConfig(Path.Combine(LibBeline.LocalPath, "global.conf")); try { BValueType str = (BValueType)globalConf["/beline/conf/global/limit[@maxmodulescount]"]; capacity = Convert.ToInt32(str.ToString()); } catch { capacity = 32; } moduleConf = new Hashtable(capacity); }
///<summary>Initialize dialog's widgets by private section of the configuration file</summary> protected override void InitializeDialog(BConfigItem configItem, string wayInXml) { base.InitializeDialog(configItem, wayInXml); Label tabLabel = new Label("Libbeline"); // add hint to created fold tooltips.SetTip(tabLabel, "Konfigurace knihovny libbeline", "Konfigurace knihovny libbeline"); VBox vbox = new VBox(false, 4); //*** subtree limits Label headingLabel = new Label(); headingLabel.Markup = "<b>Limity</b>"; headingLabel.Xalign = 0.0f; headingLabel.Xpad = 10; headingLabel.Ypad = 3; vbox.PackStart(headingLabel, false, false, 6); string timeoutValue = configItem["/beline/conf/global/limit[@defaulttimeout]"].ToString(); AddIntItem(vbox, "Timeout [s]", timeoutValue, "Defaultní timeout pro moduly", "60", "600", "10", "/beline/conf/global/limit[@defaulttimeout]"); //*** subtree paths headingLabel = new Label(); headingLabel.Markup = "<b>Cesty</b>"; headingLabel.Xalign = 0.0f; headingLabel.Xpad = 10; headingLabel.Ypad = 3; vbox.PackStart(headingLabel, false, false, 6); // templates string templatesValue = configItem["/beline/conf/global/paths[@templates]"].ToString(); AddStringItem(vbox, "Šablony", templatesValue, "Cesta k šablonám zpráv", "/beline/conf/global/paths[@templates]"); // fifos string fifosValue = configItem["/beline/conf/global/paths[@fifos]"].ToString(); AddStringItem(vbox, "Dočasný adresář", fifosValue, "Celá cesta k temp adresáři, ve kterém je možné odkládat dočasné soubory", "/beline/conf/global/paths[@fifos]"); // add new tab to the notebook nbProperties.AppendPage(vbox, tabLabel); }
/// Initialize an instance of BSlaveServiceManager /// <param name="projectName">This name is used when searching a project's configuration file. Must be same as the name of the configuration file.</param> private BSlaveServiceManager(string projectName) { try { observers = new ArrayList(); // intialize configuration of this module (module should read this configuration) moduleConfiguration = BConfigManager.GetInstance().LoadModuleConfig( System.IO.Path.Combine(BConfigManager.GlobalModulesPath, projectName + ".conf")); moduleConfiguration.ImportConfig( System.IO.Path.Combine(BConfigManager.LocalModulesPath, projectName + ".conf")); // don't know far end's PID so send 0 to search for busManager = BBusManagerFactory.CreateBusManager(null); } catch (Exception e) { // log all top level errors LibBeline.GetInstance().LogManager.Log(e); throw; } }
/// Go throught all widgets and save changes made by user back to the config item /// and then call SaveConfigToFile to default configuration file /// <param name="configItem">The configuration object whose information should be saved</param> protected virtual void Save(BConfigItem configItem) { foreach (Widget folderWidget in nbProperties.AllChildren) {// go through all tabs (there are stored VBoxs with tab contain and Labels with tab name) Gtk.VBox tmpVBox = folderWidget as Gtk.VBox; if (tmpVBox == null) continue; // skip labels foreach (Widget propertyWidget in tmpVBox.AllChildren) { // go through all headers Gtk.HBox tmpHBox = propertyWidget as Gtk.HBox; if (tmpHBox == null) continue; // skip headings foreach (Widget item in tmpHBox.AllChildren) { if (item.Name.Substring(0,4) == "item") { string [] property = (string[])properties[item.Name]; if (item.GetType() == typeof(Gtk.Entry)) configItem.SetAttribute(property[0], property[1], ((Gtk.Entry)item).Text); else if (item.GetType() == typeof(Gtk.SpinButton)) configItem.SetAttribute(property[0], property[1], ((Gtk.SpinButton)item).Value.ToString()); else if (item.GetType() == typeof(Gtk.CheckButton)) configItem.SetAttribute(property[0], property[1], ((Gtk.CheckButton)item).Active.ToString()); else if (item.GetType() == typeof(Gtk.ComboBox)) configItem.SetAttribute(property[0], property[1], ((Gtk.ComboBox)item).Active.ToString()); } } } } // save to ~/.beline/messages config file configItem.SaveConfigToFile(null); }
///<summary>Initialize dialog's widgets by private section of the configuration file</summary> ///<param name="configItem">The peice of configuration (global, module etc.) that should be dispalyed</param> ///<param name="wayInXml">Way to the root element of custom configuration in configItem</param> protected virtual void InitializeDialog(BConfigItem configItem, string wayInXml) { // create notebook tabs with items XmlNode configure = configItem.GetXmlNode(wayInXml); if (configure == null) { // no private configuration => nothing to build return; } //Console.WriteLine(configure.ChildNodes.Count); // go throught all folds foreach (XmlNode fold in configure.ChildNodes) { // skip non-valid elements if (fold.NodeType != XmlNodeType.Element || fold.LocalName != "fold") continue; XmlElement foldElement = (XmlElement)fold; string foldLabel = foldElement.GetAttribute("label"); string foldHint = foldElement.GetAttribute("hint"); if (wayInXml.LastIndexOf("/fold") == -1) wayInXml += "/fold[@text='" + foldLabel + "']"; else wayInXml = wayInXml.Substring(0, wayInXml.LastIndexOf("/fold")) + "/fold[@text='" + foldLabel + "']"; Label tabLabel = new Label(foldLabel); VBox vbox = new VBox(false, 4); // add hint to created fold tooltips.SetTip(tabLabel , foldHint, foldHint); // go throught all chapters in one fold foreach (XmlNode heading in fold.ChildNodes) { // skip non-valid elements if (heading.NodeType != XmlNodeType.Element || heading.LocalName != "heading") continue; XmlElement headingElement = (XmlElement)heading; string headingText = headingElement.GetAttribute("text"); if (wayInXml.LastIndexOf("/heading") == -1) // this is first iteration of loop, so no heading in string wayInXml += "/heading[@text='" + headingText + "']"; else // this is another iteration of loop, so I must cut heading from prevoius iteration and then append new wayInXml = wayInXml.Substring(0, wayInXml.LastIndexOf("/heading")) + "/heading[@text='" + headingText + "']"; Label headingLabel = new Label(); headingLabel.Markup = "<b>" + headingText + "</b>"; headingLabel.Xalign = 0.0f; headingLabel.Xpad = 10; headingLabel.Ypad = 3; vbox.PackStart(headingLabel, false, false, 6); // go throught all properties in one section foreach (XmlNode property in heading.ChildNodes) { // skip non-valid elements if (property.NodeType != XmlNodeType.Element || property.LocalName != "bcfgitem") continue; // to get attributes cast to XmlElement XmlElement propertyElement = (XmlElement)property; // read info from attributes string propertyLabel = propertyElement.GetAttribute("label"); string propertyHint = propertyElement.GetAttribute("hint"); if (wayInXml.LastIndexOf("/bcfgitem") == -1) // this is first iteration of loop, so no bcfgitem in string wayInXml += "/bcfgitem[@label='" + propertyLabel + "']"; else // this is another iteration of loop, so I must cut bcfgitem from prevoius iteration and then append new wayInXml = wayInXml.Substring(0, wayInXml.LastIndexOf("/bcfgitem")) + "/bcfgitem[@label='" + propertyLabel + "']"; XmlElement propertyValue = (XmlElement)property.FirstChild; switch (propertyValue.LocalName) { case "string": // store the way in Xml to this element wayInXml += "/string[@value]"; AddStringItem(vbox, propertyLabel, propertyValue.GetAttribute("value"), propertyHint, wayInXml); break; case "bool": // store the way in Xml to this element wayInXml += "/bool[@value]"; AddBoolItem(vbox, propertyLabel, propertyValue.GetAttribute("value"), propertyHint, wayInXml); break; case "int": // store the way in Xml to this element wayInXml += "/int[@value]"; AddIntItem(vbox, propertyLabel, propertyValue.GetAttribute("value"), propertyHint, propertyValue.GetAttribute("minimum"), propertyValue.GetAttribute("maximum"), propertyValue.GetAttribute("step"), wayInXml); break; case "select": // store the way in Xml to this element wayInXml += "/select[@selected]"; ArrayList options = new ArrayList(propertyValue.ChildNodes.Count); foreach (XmlElement option in propertyValue.ChildNodes) { // prepair array for an AddComboItem method XmlElement optionElement = (XmlElement)option; options.Add(optionElement.GetAttribute("text")); } AddComboItem(vbox, propertyLabel, propertyValue.GetAttribute("selected"), propertyHint, options, wayInXml); break; } // switch } // for each properties } // for each headings // add new tab to the notebook nbProperties.AppendPage(vbox, tabLabel); } }
/// <summary>Load new module's configuration from global and then from local config file</summary> public BConfigItem LoadModuleConfig(string aFileName) { if (moduleConf.Count == capacity) throw new Exception("Maximum count of configuration items reached."); BConfigItem retval = new BConfigItem(Path.Combine(BConfigManager.GlobalModulesPath,aFileName)); retval.ImportConfig(Path.Combine(BConfigManager.LocalModulesPath, aFileName)); moduleConf.Add(retval.OID, retval); return retval; }