/// <summary> /// Get Node Value /// </summary> /// <param name="model"></param> /// <returns></returns> public string GetNodeValue(XmlModel model) { try { string val = ""; foreach (XmlElement element in _xmldocument.DocumentElement) { if (element.Name.Equals(model.ElementName)) { foreach (XmlNode node in element.ChildNodes) { if (node.Attributes[model.AttrKeyName].Value == model.NodeKey) { val = node.Attributes[model.AttrValueName].Value; } } } } return val; } catch (Exception ex) { return ex.Message; } }
public XmlValueFactory(string xmlFileLocation) { _xmlmodel = new XmlModel(); _xmldocument = new XmlDocument(); _xmldocument.Load(xmlFileLocation); _xmlFileLocation = xmlFileLocation; }
/// <summary> /// Set Node value /// </summary> /// <param name="model"></param> /// <returns></returns> public void SetNodeValue(XmlModel model) { try { foreach (XmlElement element in _xmldocument.DocumentElement) { if (element.Name.Equals(model.ElementName)) { foreach (XmlNode node in element.ChildNodes) { if (node.Attributes[model.AttrKeyName].Value == model.NodeKey) { node.Attributes[model.AttrValueName].Value = model.NodeValue; } } } } _xmldocument.Save(_xmlFileLocation); } catch (Exception) { throw; } }
public BatteryAlarmForm() { InitializeComponent(); //Registry Model _regModel = new RegistryModel() { KeyName = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", ValueName = "ARTHA.BatteryAlarm.AutoRun", Value = "C:\\Program Files\\ARTHA.BatteryAlarm\\ARTHA.BatteryAlarm.exe\" -autorun", RegValueKind = RegistryValueKind.String }; //registry Factory Instansiate _regFactory = new RegistryFactory(_regModel); //Checked or not if (_regFactory.IsRegistryExist()) { chkAutorun.Checked = true; } else { chkAutorun.Checked = false; } // general seting for xml model and factory _xmlFactory = new XmlValueFactory(XmlConstant.XmlFileLocation); _xmlModel = new XmlModel() { ElementName = XmlConstant.XmlElementName, AttrKeyName = XmlConstant.XmlKey, AttrValueName = XmlConstant.XmlValue }; this.ShowInTaskbar = false; //sound Player _soundPlayer = new SoundPlayer(); //timer _timer = new Timer(); _timer.Tick += new EventHandler(BatteryTimer_Tick); _timer.Interval = Constant.DefaultIntervalTimer; _timer.Start(); //instansiate service and model _batteryService = new BatteryService(); _alarmService = new AlarmService(); _alarmModel = new AlarmModel(); _batteryModel = new BatteryModel(); //populate Batery Level combobox cmbBateryLevel.DataSource = PopulateComboBox(Constant.MinBateryLevel, Constant.MaxBateryLevel, Constant.MultipleIterationValue); InitializeAlarmTrigger(); //button close Event Handler btnMinimize.Click += new EventHandler(btnMinimize_Click); //button open file event Handler btnOpenFile.Click += new EventHandler(btnOpenFile_Click); //button save setting event handler btnSaveSetting.Click += new EventHandler(btnSaveSetting_Click); //label Warning LabelTitle.Text = Constant.AppName; LabelTitle.AutoSize = Constant.LabelSet.AutoSize; LabelTitle.Font = Constant.LabelSet.Font; //button Stop Sound Event Handler btnStopSound.Click += new EventHandler(btnStopSound_Click); //label prosen label2.Text = Constant.Prosen; }