Пример #1
0
 public void saveRule(IRule save)
 {
     save.saveToDisk(_rulesPath);
     lock (_ruleLock)
     {
         if (_ruleList == null)
             _ruleList = new List<IRule>(1);
         _ruleList.Add(save);
     }
 }
Пример #2
0
        public void changeRuleName(IRule save, string newName)
        {
            string newRulePath = _rulesPath + newName + RULE_EXT;

            if (File.Exists(newRulePath))
                throw new IOException(newName + " already exists!");
            // if the rule was saved to disk we delete the old file name and recreate it else we just rename the object in memory
            string oldName = save.name;
            string oldRulePath = _rulesPath + oldName + RULE_EXT;
            save.name = newName;
            try
            {
                if (File.Exists(oldRulePath))
                {
                    File.Delete(oldRulePath);
                    save.saveToDisk(newRulePath);
                }
            } // if for some reason this fails we roll back to the previous state
            catch (Exception)
            {
                save.name = oldName;
                if (File.Exists(newRulePath))
                {
                    File.Delete(newRulePath);
                    if (!File.Exists(oldRulePath))
                        save.saveToDisk(oldRulePath);
                }
                throw;
            }
        }