static void ExecuteCommand_Insert(CKey arr_key, CTokenLine line, ITreeBuildSupport inSupport) { string file_name = line.CommandParams["file"]; string key_path = line.CommandParams["key"]; if (string.IsNullOrEmpty(file_name) && string.IsNullOrEmpty(key_path)) { inSupport.GetLogger().LogError(EErrorCode.PathEmpty, line); } CKey root = null; if (!string.IsNullOrEmpty(file_name)) { root = (CKey)inSupport.GetTree(file_name); } else { root = arr_key.GetRoot(); } if (root == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindInsertFile, line); return; } if (root.KeyCount == 1 && root.GetKey(0).IsArrayKey()) { root = root.GetKey(0); } CKey key = root; if (!string.IsNullOrEmpty(key_path)) { key = (CKey)root.FindKey(key_path); if (key == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line); return; } } bool insert_parent = line.CommandParams.ContainsKey("parent"); CKey copy_key = key.GetCopy() as CKey; if (insert_parent) { copy_key.SetParent(arr_key); } else { arr_key.TakeAllElements(copy_key, false); } arr_key.CheckOnOneArray(); }
public CKey FindKey(IList <string> path, int index = 0) { string need_name = path[index]; CKey key = FindChildKey(need_name); if (key == null) { return(null); } if (index == path.Count - 1) { return(key); } return(key.FindKey(path, index + 1)); }
static bool RemoveKeysByPath(CKey inParent, IList <string> inPath) { CKey key = inParent.FindKey(inPath); if (key == null) { return(false); } CKey parent = key.Parent; key.SetParent(null); while (parent != inParent && parent.IsEmpty) { CKey prev = parent; parent = parent.Parent; prev.SetParent(null); } return(true); }
static void ExecuteCommand_Insert(CKey inParent, CTokenLine line, ITreeBuildSupport inSupport, CKey inRoot) { string file_name = line.CommandParams["file"]; string key_path = line.CommandParams["key"]; if (string.IsNullOrEmpty(file_name) && string.IsNullOrEmpty(key_path)) { inSupport.GetLogger().LogError(EErrorCode.PathEmpty, line); } CKey root = inRoot; if (!string.IsNullOrEmpty(file_name)) { root = (CKey)inSupport.GetTree(file_name); } //else // root = inParent.GetRoot(); if (root == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindInsertFile, line); return; } if (root.KeyCount == 1 && root.GetKey(0).IsArrayKey()) { root = root.GetKey(0); } CKey key = root; if (!string.IsNullOrEmpty(key_path)) { key = (CKey)root.FindKey(key_path); if (key == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line); return; } } CKey destination_key = inParent; bool insert_in_parent = line.CommandParams.ContainsKey("insert_in_parent"); if (insert_in_parent) { if (inParent.Parent != null) { destination_key = inParent.Parent; } else { inSupport.GetLogger().LogError(EErrorCode.KeyMustHaveParent, line); } } bool add_key = line.CommandParams.ContainsKey("add_key"); CKey copy_key = key.GetCopy() as CKey; if (add_key) { copy_key.SetParent(destination_key); } else { destination_key.TakeAllElements(copy_key, false); } destination_key.CheckOnOneArray(); }