/// <summary> /// Extracts node from a specific branch /// </summary> public Node ExtractNode(string branch) { if (!string.IsNullOrEmpty(branch)) { string[] branchPath = branch.Split(DATA_BRANCH_SEPARATOR); var nodes = ExtractNodes(dataRoots, 0, branchPath.Length - 1, branchPath); return(nodes != null && nodes.Count > 0 ? nodes[nodes.Count - 1] : null); } LogWrapper.DebugWarning("[{0}] Error, the request is null or empty, please provide a valid branch, will return null", GetType()); return(null); }
/// <summary> /// Adds and creates the branch if no data branch is defined /// Overrides the data if the data branch is defined /// </summary> private void AddOrOverrideNodeToDataTree(Node insertion, string branch, string[] splittedBranch, bool overrideData) { var extracted = ExtractNode(insertion.branch); if (extracted != null) { if (overrideData) { insertion.parent = extracted.parent; extracted = insertion; } else { LogWrapper.DebugWarning("[{0}] branch {1} found but the data will not change.", GetType(), branch); } } else { AddNodeToDataTree(insertion, splittedBranch); } }
public void AddReadonly(string key, object value, bool persist, bool flush = false) { if (!HasKey(key)) { var data = new DBData(); data.value = value; data.persist = persist; data.isReadonly = true; database.Add(key, data); if (persist && !persistData.ContainsKey(key)) { persistData.Add(key, data); } if (flush) { Flush(); } } else { LogWrapper.DebugWarning("[{0}] Key already in the database {1}", GetType(), key); } }