private void AddNode(Tag parent,string name,Node node) { if (node.Value==null) return; switch (((IList<Type>)supported).IndexOf(node.Value.GetType())) { case 8: List<Node> l = (List<Node>)node.Value; Tag list; if (name==null) list = parent.AddList(ListType(l)); else list = parent.AddList(name,ListType(l)); foreach (Node n in l) AddNode(list,n); break; case 9: Dictionary<string,Node> dict = (Dictionary<string,Node>)node.Value; Tag compound; if (name==null) compound = parent.AddCompound(); else compound = parent.AddCompound(name); foreach (KeyValuePair<string,Node> kvp in dict) AddNode(compound,kvp.Key,kvp.Value); break; default: if (name==null) parent.Add(node.Value); else parent.Add(name, node.Value); break; } }
public void Add(Node value) { if (value==null) { throw new ArgumentNullException("node"); } if (this.value==null) { this.value = new List<Node>(); } List<Node> list = this.value as List<Node>; if (list==null) { throw new Exception("Value isn't a List<Node>."); } list.Add(value); }
public override void Save(string filename,Node root,string name) { if (filename==null) { throw new ArgumentNullException("filename"); } if (root==null) { throw new ArgumentNullException("root"); } if (name==null) { throw new ArgumentNullException("name"); } Tag tag = Tag.Create(name); foreach (KeyValuePair<string,Node> kvp in (Dictionary<string,Node>)root.Value) AddNode(tag,kvp.Key,kvp.Value); tag.Save(filename); }
public override void Save(string filename,Node root,string name) { if (filename==null) { throw new ArgumentNullException("filename"); } if (root==null) { throw new ArgumentNullException("root"); } if (name==null) { throw new ArgumentNullException("name"); } Check(root,new LinkedList<Node>()); XElement element = NodeToElement(root); element.SetAttributeValue("name",name); XmlWriterSettings settings = new XmlWriterSettings(){ Indent=true, OmitXmlDeclaration=true }; using (XmlWriter writer = XmlWriter.Create(filename,settings)) element.Save(writer); }
private Node ElementToNode(XElement element) { Node node = new Node(); switch (element.Name.LocalName) { case "bool": node.Value = bool.Parse(element.Value); break; case "byte": node.Value = byte.Parse(element.Value); break; case "short": node.Value = short.Parse(element.Value); break; case "int": node.Value = int.Parse(element.Value); break; case "long": node.Value = long.Parse(element.Value); break; case "float": node.Value = float.Parse(element.Value); break; case "double": node.Value = double.Parse(element.Value); break; case "string": node.Value = element.Value; break; case "list": foreach (XElement e in element.Elements()) node.Add(ElementToNode(e)); break; case "compound": foreach (XElement e in element.Elements()) node[GetElementName(e)] = ElementToNode(e); break; default: throw new FormatException("Can't parse '"+element.Name.LocalName+"'."); } return node; }
private XElement NodeToElement(Node node) { int index = ((IList<Type>)supported).IndexOf(node.Value.GetType()); switch (index) { case 8: XElement list = new XElement("list"); foreach (Node n in (List<Node>)node.Value) { if (n.Value==null) { continue; } list.Add(NodeToElement(n)); } return list; case 9: XElement compound = new XElement("compound"); foreach (KeyValuePair<string,Node> kvp in (Dictionary<string,Node>)node.Value) { if (kvp.Value.Value==null) { continue; } XElement e = NodeToElement(kvp.Value); e.SetAttributeValue("name",kvp.Key); compound.Add(e); } return compound; default: return new XElement(names[index],node.Value); } }
internal static Node SavePermissionList(List<Command> cmds) { Node node = new Node(); foreach (Command command in cmds) { node.Add(new Node(command.name)); } return node; }
private void AddNode(Tag parent,Node node) { AddNode(parent,null,node); }
private void SetIndex(object index,Node value) { if (index==null) { throw new ArgumentNullException("index"); } if (value==null) { throw new ArgumentNullException("value"); } if (index is string) { DictSet((string)index,value); return; } if (index is IConvertible) { ListSet(Convert.ToInt32(index),value); return; } throw new ArgumentException("Indexer isn't string or int compatible.","index"); }
public void Save(string name) { if (name==null) { throw new ArgumentNullException("name"); } if (name=="") { throw new ArgumentException("Name musn't be an empty string.","name"); } if (!RegexHelper.IsAlphaNumeric(name)) { throw new ArgumentException("Only alphanumerical characters allowed.","name"); } Node node = new Node(); node["width"] = new Node(width); node["depth"] = new Node(depth); node["height"] = new Node(height); Node spawnNode = new Node(); node["spawn"] = spawnNode; spawnNode["x"] = new Node((short)spawn.X); spawnNode["y"] = new Node((short)spawn.Y); spawnNode["z"] = new Node((short)spawn.Z); spawnNode["rotx"] = new Node(spawn.RotX); spawnNode["roty"] = new Node(spawn.RotY); node["mapdata"] = new Node(mapdata); node["blockdata"] = new Node(blockdata); node["custom"] = custom; Saving.Raise(server,this); if (!Directory.Exists("levels")) { Directory.CreateDirectory("levels"); } host.Save("levels/"+name+".lvl",node,"obsidian-level"); }
protected override void CheckNode(Node node) { List<Node> list = node.Value as List<Node>; if (list!=null) { ListType(list); } }
private void ListSet(int index,Node value) { if (this.value==null && index==0) { this.value = new List<Node>(); } List<Node> list = this.value as List<Node>; if (list==null) { throw new Exception("Value isn't a List<Node>."); } if (index<0 || index>=list.Count) { throw new ArgumentOutOfRangeException("index"); } else { list[index] = value; } }
private Node TagToNode(Tag tag) { Node node = new Node(); switch (tag.Type) { case TagType.Byte: node.Value = (byte)tag; break; case TagType.Short: node.Value = (short)tag; break; case TagType.Int: node.Value = (int)tag; break; case TagType.Long: node.Value = (long)tag; break; case TagType.Float: node.Value = (float)tag; break; case TagType.Double: node.Value = (double)tag; break; case TagType.Byte_Array: node.Value = (byte[])tag; break; case TagType.String: node.Value = (string)tag; break; case TagType.List: foreach (Tag t in tag) node.Add(TagToNode(t)); break; case TagType.Compound: foreach (Tag t in tag) node[t.Name] = TagToNode(t); break; } return node; }
protected override void CheckNode(Node node) { }
private Node SavePrivileges() { Node node = new Node(); node.MakeList(); if (canJoin) { node.Add(new Node("join")); } if (canJoinFull) { node.Add(new Node("joinfull")); } if (canBuild) { node.Add(new Node("build")); } if (canChat) { node.Add(new Node("chat")); } return node; }
private void LoadPrivilege(Node node) { switch ((string)node.Value) { case "join": canJoin = true; break; case "joinfull": canJoinFull = true; break; case "chat": canChat = true; break; case "build": canBuild = true; break; } }
public void Save() { Node node = new Node(); node["name"] = new Node(name); node["standard"] = new Node(standard.ToString()); node["prefix"] = new Node(prefix); node["postfix"] = new Node(postfix); node["privileges"] = SavePrivileges(); node["commands"] = Command.List.SavePermissionList(commands); node["custom"] = custom; if (!Directory.Exists("groups")) { Directory.CreateDirectory("groups"); } host.Save("groups/"+name+"."+host.Extension,node,"group"); }
public void Save() { Node node = new Node(); node["name"] = new Node(name); node["group"] = new Node(group.Name); Node statistics = new Node(); node["statistics"] = statistics; statistics["logins"] = new Node(logins); statistics["total"] = new Node(total.ToString()); statistics["lastLogin"] = new Node(lastLogin.ToString()); statistics["lastLogout"] = new Node(lastLogout.ToString()); statistics["lastIP"] = new Node(lastIP); node["custom"] = custom; if (!Directory.Exists("accounts")) { Directory.CreateDirectory("accounts"); } host.Save("accounts/"+name+"."+host.Extension,node,"account"); }
internal List<Command> LoadPermissionList(Node node) { List<Command> cmds = new List<Command>(); foreach (Node n in (List<Node>)node.Value) { Command command = this[(string)n.Value]; if (command!=null) { cmds.Add(command); } } return cmds; }
private void DictSet(string key,Node value) { if (this.value==null) { this.value = new Dictionary<string,Node>(StringComparer.OrdinalIgnoreCase); } Dictionary<string,Node> dict = this.value as Dictionary<string,Node>; if (dict==null) { throw new Exception("Value isn't a Dictionary<string,Node>."); } if (!dict.ContainsKey(key)) { dict.Add(key,value); } else { dict[key] = value; } }