static MOTD() { CMOptions = new MOTDOptions(); Messages = new XmlDataStore<string, MOTDMessage>(VitaNexCore.SavesDirectory + "/MOTD", "Messages") { OnSerialize = Serialize, OnDeserialize = Deserialize }; }
static CentralGump() { CSOptions = new CentralGumpOptions(); PlayerProfiles = new BinaryDataStore<PlayerMobile, CentralGumpProfile>( VitaNexCore.SavesDirectory + "/CentralGump", "PlayerProfiles") { Async = true, OnSerialize = SerializePlayerProfiles, OnDeserialize = DeserializePlayerProfiles }; Adventurers = new List<PlayerMobile>(); Messages = new XmlDataStore<string, Message>( VitaNexCore.SavesDirectory + "/CentralGump", "NewsMessages") { OnSerialize = SerializeMessages, OnDeserialize = DeserializeMessages }; }
public static FileInfo Export(ClilocLNG lng) { if (lng == ClilocLNG.NULL) { lng = DefaultLanguage; } var list = new XmlDataStore<int, ClilocData>(VitaNexCore.DataDirectory + "/Exported Clilocs/", lng.ToString()); ClilocTable table = Tables[lng]; list.OnSerialize = doc => { XmlNode node; XmlCDataSection cdata; ClilocInfo info; XmlNode root = doc.CreateElement("clilocs"); XmlAttribute attr = doc.CreateAttribute("len"); attr.Value = table.Count.ToString(CultureInfo.InvariantCulture); if (root.Attributes != null) { root.Attributes.Append(attr); } attr = doc.CreateAttribute("lng"); attr.Value = table.Language.ToString(); if (root.Attributes != null) { root.Attributes.Append(attr); } foreach (ClilocData d in table.Where(d => d.Length > 0)) { info = d.Lookup(table.InputFile, true); if (info == null || String.IsNullOrWhiteSpace(info.Text)) { continue; } node = doc.CreateElement("cliloc"); attr = doc.CreateAttribute("idx"); attr.Value = d.Index.ToString(CultureInfo.InvariantCulture); if (node.Attributes != null) { node.Attributes.Append(attr); } attr = doc.CreateAttribute("len"); attr.Value = d.Length.ToString(CultureInfo.InvariantCulture); if (node.Attributes != null) { node.Attributes.Append(attr); } cdata = doc.CreateCDataSection(info.Text); node.AppendChild(cdata); root.AppendChild(node); } doc.AppendChild(root); table.Clear(); return true; }; list.Export(); list.Clear(); return list.Document; }
public static void ImportXML(string path, string file) { using (var xml = new XmlDataStore<ConquestSerial, Conquest>(path, file)) { xml.OnDeserialize = doc => { XmlElement root = doc.DocumentElement; if (root == null) { return true; } foreach (XmlElement conquestNode in root.ChildNodes.OfType<XmlElement>()) { string typeAttr = conquestNode.GetAttribute("type"); var type = new TypeSelectProperty<Conquest>(typeAttr); if (!type.IsNotNull) { continue; } var conquest = type.CreateInstance<Conquest>(); PropertyList<Conquest> pList = conquest.GetProperties( BindingFlags.Instance | BindingFlags.Public, p => p.CanWrite && p.Name != "Enabled" && p.Name != "InvokeReset" && p.Name != "InvokeClear"); foreach (XmlElement conquestPropNode in conquestNode.ChildNodes.OfType<XmlElement>()) { string pName = conquestPropNode.Name; string dType = conquestPropNode.GetAttribute("type"); string data = conquestPropNode.GetAttribute("value"); switch (dType) { case "Type": { Type t = null; if (!String.IsNullOrWhiteSpace(data)) { t = Type.GetType(data, false, true) ?? ScriptCompiler.FindTypeByName(data, true) ?? ScriptCompiler.FindTypeByFullName(data); } pList.Set(pName, t); } break; default: { DataType dataType; if (!Enum.TryParse(dType, out dataType)) { continue; } SimpleType sType; if (SimpleType.TryParse(data, dataType, out sType) && sType.Flag != DataType.Null) { pList.Set(pName, sType.Value); } } break; } } pList.Serialize(conquest); xml.AddOrReplace(conquest.UID, conquest); } return true; }; if (xml.Import() == DataStoreResult.OK) { xml.CopyTo(ConquestRegistry); xml.Document.Delete(); } foreach (Exception e in xml.Errors) { e.ToConsole(); } } }
public Customer CreateCustomer(Customer instance) { return(XmlDataStore.CreateCustomer(instance)); }
public static void ExportXML(string path, string file) { using (var xml = new XmlDataStore<ConquestSerial, Conquest>(path, file)) { xml.OnSerialize = doc => { XmlElement root = doc.CreateElement("Conquests"); foreach (Conquest conquest in xml.Values) { PropertyList<Conquest> pList = conquest.GetProperties( BindingFlags.Instance | BindingFlags.Public, p => p.CanWrite && p.Name != "Enabled" && p.Name != "InvokeReset" && p.Name != "InvokeClear"); XmlElement conquestNode = doc.CreateElement("Conquest"); conquestNode.SetAttribute("type", conquest.GetType().Name); foreach (KeyValuePair<string, object> kv in pList.Where(kv => SimpleType.IsSimpleType(kv.Value)) ) { string flag; string value; if (SimpleType.IsSimpleType(kv.Value)) { SimpleType sType = SimpleType.FromObject(kv.Value); flag = sType.Flag.ToString(); value = sType.Value.ToString(); } else if (kv.Value is Type) { flag = "Type"; value = ((Type) kv.Value).Name; } else if (kv.Value is ITypeSelectProperty) { flag = "Type"; value = ((ITypeSelectProperty) kv.Value).TypeName ?? String.Empty; } else { continue; } XmlElement conquestPropNode = doc.CreateElement(kv.Key); conquestPropNode.SetAttribute("type", flag); conquestPropNode.SetAttribute("value", value); conquestNode.AppendChild(conquestPropNode); } root.AppendChild(conquestNode); } doc.AppendChild(root); return true; }; ConquestRegistry.CopyTo(xml, true); xml.Export(); foreach (Exception e in xml.Errors) { e.ToConsole(); } } }
public Contact GetContact(string customer, string contact) { return(XmlDataStore.GetContact(customer, contact)); }
public List <Contact> GetContacts(string customer) { return(XmlDataStore.GetContacts(customer)); }
public static FileInfo Export(ClilocLNG lng) { if (lng == ClilocLNG.NULL) { lng = DefaultLanguage; } var list = new XmlDataStore <int, ClilocData>(VitaNexCore.DataDirectory + "/Exported Clilocs/", lng.ToString()); ClilocTable table = Tables[lng]; list.OnSerialize = doc => { XmlNode node; XmlCDataSection cdata; ClilocInfo info; XmlNode root = doc.CreateElement("clilocs"); XmlAttribute attr = doc.CreateAttribute("len"); attr.Value = table.Count.ToString(CultureInfo.InvariantCulture); if (root.Attributes != null) { root.Attributes.Append(attr); } attr = doc.CreateAttribute("lng"); attr.Value = table.Language.ToString(); if (root.Attributes != null) { root.Attributes.Append(attr); } foreach (ClilocData d in table.Where(d => d.Length > 0)) { info = d.Lookup(table.InputFile, true); if (info == null || String.IsNullOrWhiteSpace(info.Text)) { continue; } node = doc.CreateElement("cliloc"); attr = doc.CreateAttribute("idx"); attr.Value = d.Index.ToString(CultureInfo.InvariantCulture); if (node.Attributes != null) { node.Attributes.Append(attr); } attr = doc.CreateAttribute("len"); attr.Value = d.Length.ToString(CultureInfo.InvariantCulture); if (node.Attributes != null) { node.Attributes.Append(attr); } cdata = doc.CreateCDataSection(info.Text); node.AppendChild(cdata); root.AppendChild(node); } doc.AppendChild(root); table.Clear(); return(true); }; list.Export(); list.Clear(); return(list.Document); }
static void Main(string[] args) { IData <Person> myDataLayer = null; //read an argument from the command line that allows you to select a JsonDataStore or a XmlDataStore //polymorphism if (DateTime.Now.Second > 30) { myDataLayer = new JsonDataStore(); } else { myDataLayer = new XmlDataStore(); } if (myDataLayer == null) { Console.WriteLine("myDataLayer is null"); } else { var data = myDataLayer.Get(); //the database is empty or has not been created yet if (data?.Count == 0) { var dad = new Person() { FirstName = "Pa", LastName = "Bear", DOB = new DateTime(1969, 6, 6), Sex = "M" }; var mom = new Person() { FirstName = "Ma", LastName = "Bear", DOB = new DateTime(1968, 4, 8), Sex = "F" }; var girl = new Person() { FirstName = "Sister", LastName = "Bear", DOB = new DateTime(1992, 3, 29), Sex = "F" }; girl.Parents.AddRange(new Person[] { dad, mom }); var boy = new Person() { FirstName = "Brother", LastName = "Bear", DOB = new DateTime(2000, 3, 24), Sex = "M" }; boy.Parents.AddRange(new Person[] { dad, mom }); myDataLayer.Save(new Person[] { dad, mom, girl, boy }); data = myDataLayer.Get(); } //some random CRUD actions var numberOfBears = data.Count; var oldestChild = myDataLayer.GetByQuery((rows) => { return(rows.Where(p => p.FirstName.ToUpper() == "SISTER").FirstOrDefault()); }); Console.WriteLine($"There are {numberOfBears} Bears"); if (oldestChild != null) { Console.WriteLine($"The first-born is {oldestChild.FirstName} and {(oldestChild.Sex.ToUpper() == "F" ? "She" : "He")} is {DateTime.Now.Year - oldestChild.DOB.Year} old."); } oldestChild.LastName += " III"; //save some type of change myDataLayer.SaveOne(oldestChild, (rows) => { return(rows.ToList().FindIndex(p => p.FirstName.ToUpper() == "SISTER")); }); } Console.WriteLine("enter to exit..."); Console.ReadLine(); }
//zapis całego drzewa do xml public void SaveToXml(string filePath) { var nodes = SaveRec(_rootNode); XmlDataStore.Save(nodes, filePath); }