private void del(IJSONObject node) { node.clear(); var childs = node.__getChildsNames(); foreach (var c in childs) { del(node.__getChild(c)); } childs.Clear(); /* * var parentNodesNames = node.parent.__getChildsNames(); * for (int cont = 0; cont < parentNodesNames.Count; cont++) * { * if (parentNodesNames[cont] == node) * { * //if parent is an array, pull the elements forward backwards * if (node.parent.isArray()) * { * for (int cont2 = cont; cont2 < parentNodes.Count - 1; cont2++) * parentNodes[parentNodes.ElementAt(cont2).Key] = parentNodes[parentNodes.ElementAt(cont2 + 1).Key]; * * parentNodes.Remove(parentNodes.Last().Key); * } * else * { * parentNodes.Remove(parentNodes.ElementAt(cont).Key); * } * break; * } * }*/ }
public override void setChild(string name, IJSONObject child) { //checks if exists a file if (File.Exists(this.fileName)) { File.Delete(this.fileName); } }
private IJSONObject find(string objectName, bool autoCreateTree, IJSONObject currentParent, SOType forceType = SOType.Undefined) { //quebra o nome em um array objectName = objectName.Replace("]", "").Replace("[", "."); string currentName = objectName; string childsNames = ""; IJSONObject childOnParent; if (objectName.IndexOf('.') > -1) { currentName = objectName.Substring(0, objectName.IndexOf('.')); childsNames = objectName.Substring(objectName.IndexOf('.') + 1); } if (!(currentParent.__containsChild(currentName))) { if (autoCreateTree) { IJSONObject tempObj; string currentParentRelativeName = currentParent.getRelativeName(); if (currentParent is InMemoryJsonObject) { tempObj = new InMemoryJsonObject((InMemoryJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName); } else { tempObj = new FileSystemJsonObject((FileSystemJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName, (string)JsonObjectArguments); } if (forceType != SOType.Undefined) { tempObj.forceType(forceType); } currentParent.setChild(currentName, tempObj); } else { return(null); } } childOnParent = currentParent.__getChild(currentName); if (childsNames == "") { return(childOnParent); } else { return(this.find(childsNames, autoCreateTree, childOnParent)); } }
private void internalInitialize(JsonType type, object arguments) { JsonObjectArguments = arguments; if (type == JsonType.Memory) { root = new InMemoryJsonObject(null, ""); } else { root = new FileSystemJsonObject(null, "", (string)JsonObjectArguments); } }
/// <summary> /// Removes an object from JSON three /// </summary> /// <param name="objectName">The object name</param> public void del(string objectName) { interfaceSemaphore.WaitOne(); IJSONObject temp = this.find(objectName, false, this.root); if (temp != null) { del(temp); } interfaceSemaphore.Release(); }
public void clearChilds(string objectName) { IJSONObject temp = this.find(objectName, false, this.root); if (temp != null) { //var childs = temp.__getChilds(); var names = temp.__getChildsNames(); foreach (var c in names) { del(temp.__getChild(c)); } } }
public SOType getJSONType(string objectName) { interfaceSemaphore.WaitOne(); IJSONObject temp = this.find(objectName, false, this.root); interfaceSemaphore.Release(); if (temp != null) { return(temp.getJSONType()); } else { return(SOType.Undefined); } }
/// <summary> /// returns the value of an json object as a json string (Serialize an object) /// </summary> /// <param name="objectName">The object name</param> /// <param name="quotesOnNames">User '"' in names</param> /// <returns></returns> public string get(string objectName, bool format = false, bool quotesOnNames = true, string valueOnNotFound = "undefined") { interfaceSemaphore.WaitOne(); IJSONObject temp = this.find(objectName, false, this.root); interfaceSemaphore.Release(); if (temp != null) { return(temp.ToJson(quotesOnNames, format)); } else { return(valueOnNotFound); } }
private List <string> getChildsNames(IJSONObject currentItem = null) { List <string> retorno = new List <string>(); if (currentItem == null) { currentItem = this.root; } var chieldsNames = currentItem.__getChildsNames(); for (int cont = 0; cont < chieldsNames.Count; cont++) { retorno.Add(chieldsNames[cont]); } return(retorno); }
private void _set(string objectName, string value) { if (isAJson(value)) { this.parseJson(value, objectName); return; } IJSONObject temp = this.find(objectName, true, this.root); /*if (value[0] == '\"') * value = value.Substring(1, value.Length - 2);*/ //value = value.Replace("\"", "\\\""); temp.setSingleValue(value); }
/// <summary> /// Return the childNames of an json object /// </summary> /// <param name="objectName">The name of object</param> /// <returns></returns> public List <string> getChildsNames(string objectName = "") { if (objectName == "") { IJSONObject nullo = null; return(this.getChildsNames(nullo)); } else { var finded = this.find(objectName, false, this.root); List <string> retorno = new List <string>(); if (finded != null) { retorno = this.getChildsNames(finded); } return(retorno); } }
private List <string> getObjectsNames(IJSONObject currentItem = null) { List <string> retorno = new List <string>(); if (currentItem == null) { currentItem = this.root; } string parentName = ""; List <string> childsNames; var chieldsNames = currentItem.__getChildsNames(); for (int cont = 0; cont < chieldsNames.Count; cont++) { childsNames = getObjectsNames(currentItem.__getChild(chieldsNames[cont])); parentName = chieldsNames[cont]; //adiciona os filhos ao resultado //verifica se o nome atual atende ao filtro foreach (var att in childsNames) { string nAtt = att; if (nAtt != "") { nAtt = parentName + '.' + nAtt; } retorno.Add(nAtt); } retorno.Add(chieldsNames[cont]); } return(retorno); }
public override void setChild(string name, IJSONObject child) { childs[name] = child; }
public abstract void setChild(string name, IJSONObject child);