public static void LoadConquestRegistry() { DataStoreResult result = ConquestRegistry.Import(); CMOptions.ToConsole("Result: {0}", result.ToString()); switch (result) { case DataStoreResult.Null: case DataStoreResult.Busy: case DataStoreResult.Error: { if (ConquestRegistry.HasErrors) { CMOptions.ToConsole("Conquest database has errors..."); ConquestRegistry.Errors.ForEach(CMOptions.ToConsole); } } break; case DataStoreResult.OK: CMOptions.ToConsole("Conquest count: {0:#,0}", ConquestRegistry.Count); break; } }
private static void Defragment() { ConquestRegistry.RemoveValueRange(c => c == null || c.Deleted); foreach (ConquestProfile p in Profiles.Values) { p.Where(s => s != null && !s.ConquestExists).ForEach(s => p.Registry.Remove(s)); } Profiles.RemoveValueRange(p => p == null || p.Count == 0 || p.Owner == null || p.Owner.Deleted); }
public static Conquest ReadConquest(GenericReader reader) { if (!reader.ReadBool()) { return(null); } var uid = new ConquestSerial(reader); Conquest c; return(ConquestRegistry.TryGetValue(uid, out c) ? c : null); }
public static void Register(Conquest c) { if (c == null || c.Deleted) { return; } if (ConquestRegistry.ContainsKey(c.UID)) { ConquestRegistry[c.UID] = c; } else { ConquestRegistry.Add(c.UID, c); } }
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(); } } }