/// <summary> /// Saves the watch rules. /// </summary> /// <param name="list">The list.</param> public void SaveWatchRules(WatchRuleSet list) { Stream fileStream = null; try { fileStream = File.Open(configFileName, FileMode.Create, FileAccess.Write); } catch (Exception ex) { log.Debug("Error during opening the config file for write.", ex); return; } try { xmlFormatter.Serialize(fileStream, list); } catch (Exception ex) { log.Debug("Error during serializing the watch rule data to config file.", ex); } finally { fileStream.Flush(); fileStream.Close(); fileStream.Dispose(); } }
public RemResMessage GetWatchRules(RemResMessage message) { if (!(message is GetWatchRules)) { throw new InvalidOperationException("The message type for this messagehandler method is invalid."); } //no possible in one line because of problem with convert from list<watchrule> to WatchRuleSet var ruleset = new WatchRuleSet(); ruleset.AddRange(lstAktivWatchTasks.Select(t => t.Rule).ToList()); return(new GetWatchRuleResult() { WatchRuleSet = ruleset }); }
/// <summary> /// Loads the watch rules from the config xml file. /// </summary> /// <returns></returns> public IList <WatchRule> LoadWatchRules() { Stream fileStream = null; List <WatchRule> ruleSet = new WatchRuleSet(); if (!File.Exists(configFileName)) { log.Debug("No config file found."); //eturn emtpy list return(ruleSet); } try { fileStream = File.OpenRead(configFileName); } catch (Exception ex) { log.Debug("Error during opening the config file for read.", ex); //return empty list return(ruleSet); } try { ruleSet = (WatchRuleSet)xmlFormatter.Deserialize(fileStream); } catch (Exception ex) { log.Debug("Error during deserializing the config file data to watch rules.", ex); //return empty list return(ruleSet); } finally { fileStream.Close(); fileStream.Dispose(); } return(ruleSet); }
/// <summary> /// Saves the configuration rules. /// </summary> private void SaveConfigRules() { lock (lockSaveWatchTask) { var rules = lstAktivWatchTasks.Select(t => t.Rule).ToList(); var ruleset = new WatchRuleSet(); foreach (var rule in rules) { //dont save the collected values - only temporay watching rule.WatchField.WatchFieldValues = null; ruleset.Add(rule); } configDataServiceObj.SaveWatchRules(ruleset); //no use of direct cast due problem with the convert from List<WatchRule> to WatchRuleSet //configDataServiceObj.SaveWatchRules(lstAktivWatchTasks.Select(t => t.Rule).ToList() as WatchRuleSet); } }