/* * private void Processing() * { * TimeSpan ts; * while (null != _th && IsRunning && * !ApplicationManager.Instance.IsExit) * { * ts = DateTime.Now - _lastUpdate; * if (ts.TotalMilliseconds > _timeout) * { * UpdateConfig(); * _lastUpdate = DateTime.Now; * } * } * Shutdown(); * } */ /* * private void UpdateConfig() * { * lock (this) * { * MethodBase med = MethodBase.GetCurrentMethod(); * try * { * var oldCfg = _plazaCfg; * if (!NJson.ConfigExists(_fileName)) * { * _plazaCfg = null; * } * else * { * _plazaCfg = NJson.LoadFromFile<PlazaConfig>(_fileName); * if (null != oldCfg) * { * // some thing error * } * } * * // save back to file. * if (null == _plazaCfg) * { * Console.WriteLine("Config create new."); * _plazaCfg = (null != oldCfg ) ? oldCfg : new PlazaConfig(); * NJson.SaveToFile(_plazaCfg, _fileName); * // Raise event. * ConfigChanged.Call(this, EventArgs.Empty); * } * else * { * if (!_plazaCfg.IsEquals(oldCfg)) * { * Console.WriteLine("Config changed by external."); * NJson.SaveToFile(_plazaCfg, _fileName); * // Raise event. * ConfigChanged.Call(this, EventArgs.Empty); * } * else * { * Console.WriteLine("Config not changed."); * } * } * } * catch (Exception ex) * { * med.Err(ex); * } * } * } */ #endregion #region Public Methods /* * /// <summary> * /// Start Service. * /// </summary> * public void Start() * { * if (null == _th) * { * _th = new Thread(Processing); * _th.Priority = ThreadPriority.BelowNormal; * _th.Name = "DMT Config Manager Thread"; * _th.IsBackground = true; * IsRunning = true; * _th.Start(); * } * } * /// <summary> * /// Shutdown Service. * /// </summary> * public void Shutdown() * { * IsRunning = false; * if (null != _th) * { * try { _th.Abort(); } * catch (ThreadAbortException) { } * } * _th = null; * } */ /// <summary> /// Load Config from file. /// </summary> public void LoadConfig() { lock (this) { MethodBase med = MethodBase.GetCurrentMethod(); try { // save back to file. if (!NJson.ConfigExists(_fileName)) { if (null == _plazaCfg) { _plazaCfg = new PlazaConfig(); } NJson.SaveToFile(_plazaCfg, _fileName); } else { // Check When file is exists but size is zero so config is null. _plazaCfg = NJson.LoadFromFile <PlazaConfig>(_fileName); } // Raise event. ConfigChanged.Call(this, EventArgs.Empty); } catch (Exception ex) { med.Err(ex); } } }