async public Task <T> LoadAsync <T>(string key, T objectInstance, T defaultValue = default(T)) where T : IPersistableLoadAsync { if (_parent == null) { return(default(T)); } XmlNode xmlnode = _parent.Next(key); if (xmlnode == null) { return(defaultValue); } if (xmlnode.Attributes["type"] == null) { if (objectInstance != null) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); await objectInstance.LoadAsync(this); _parent = parent; return(objectInstance); } } return(defaultValue); }
public bool ReduceDocument(string xPath) { if (_doc == null) { return(false); } XmlNode node = _doc.SelectSingleNode(xPath); if (node == null) { return(false); } CultureInfo culture = global::System.Globalization.CultureInfo.CurrentCulture; if (_parent.Node.Attributes["culture"] != null) { foreach (CultureInfo cu in global::System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures)) { if (cu.TextInfo.CultureName == _parent.Node.Attributes["culture"].Value) { culture = cu; break; } } } _doc.LoadXml(node.OuterXml); _parent = new XmlNodePlus(_doc.ChildNodes[0]); _parent.Culture = culture; return(true); }
public XmlStream(string rootname) { _doc = new XmlDocument(); _nhi = global::System.Globalization.CultureInfo.CurrentCulture.NumberFormat; if (rootname == "") { rootname = "root"; } _parent = new XmlNodePlus(this.CreateNode(rootname)); _parent.Culture = global::System.Globalization.CultureInfo.InvariantCulture; _doc.AppendChild(_parent.Node); }
async public Task <T> LoadPluginAsync <T>(string key, T unknownPlugin = default(T)) where T : IPersistableLoadAsync { if (_parent == null) { return(default(T)); } XmlNode xmlnode = _parent.Next(key); if (xmlnode == null) { return(default(T)); } if (xmlnode.Attributes["GUID"] != null) { PlugInManager compManager = new PlugInManager(); T comp = (T)compManager.CreateInstance(new Guid(xmlnode.Attributes["GUID"].Value)); if (comp == null) { if (unknownPlugin is IErrorMessage) { ((IErrorMessage)unknownPlugin).LastErrorMessage = "Unknown plugin type: " + xmlnode.Attributes["GUID"].Value; } return(unknownPlugin); } //if (comp is IPersistableLoad) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); //((IPersistable)comp).Load(this); await comp.LoadAsync(this); _parent = parent; } return(comp); } return(unknownPlugin); }
public bool ReadStream(TextReader stream, string cultureName = null) { try { _doc = new XmlDocument(); _doc.Load(stream); // find first Element (== Parent) foreach (XmlNode node in _doc.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { _parent = new XmlNodePlus(node, cultureName); return(true); } } return(false); } catch { return(false); } }
public bool ReadStream(string path) { try { _doc = new XmlDocument(); _doc.Load(path); // find first Element (== Parent) foreach (XmlNode node in _doc.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { _parent = new XmlNodePlus(node); return(true); } } return(false); } catch { return(false); } }
public object Load(string key, object defValue, object objectInstance) { if (_parent == null) { return(null); } XmlNode xmlnode = _parent.Next(key); if (xmlnode == null) { return(defValue); } if (xmlnode.Attributes["GUID"] != null) { PlugInManager compManager = new PlugInManager(); object comp = compManager.CreateInstance(new Guid(xmlnode.Attributes["GUID"].Value)); if (comp == null) { return(defValue); } if (comp is IPersistable) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); ((IPersistable)comp).Load(this); _parent = parent; } else if (comp is IPersistableLoadAsync) { throw new Exception("Can't laod async in this context (" + comp.GetType().ToString() + ")"); } return(comp); } if (xmlnode.Attributes["type"] == null) { if (objectInstance is IPersistable) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); ((IPersistable)objectInstance).Load(this); _parent = parent; return(objectInstance); } else if (objectInstance is IPersistableLoadAsync) { throw new Exception("Can't laod async in this context (" + objectInstance.GetType().ToString() + ")"); } else { return(defValue); } } try { if (xmlnode.Attributes["type"].Value != "System.String") { Type type = global::System.Type.GetType(xmlnode.Attributes["type"].Value, false, true); object obj = Activator.CreateInstance(type); if (obj == null) { return(defValue); } if (obj is XmlStreamObject) { ApplyXmlStreamObjectAttributes(xmlnode, (XmlStreamObject)obj); if (obj is XmlStreamOption) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); List <object> options = new List <object>(); object option; while ((option = Load("Option", null)) != null) { options.Add(option); } ((XmlStreamOption)obj).Options = options.ToArray(); ((XmlStreamOption)obj).Value = Load("Value", null); _parent = parent; } else if (obj is XmlStreamStringArray) { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); List <string> values = new List <string>(); object Value; while ((Value = Load("Value", null)) != null) { values.Add(Value.ToString()); } ((XmlStreamObject)obj).Value = values.ToArray(); _parent = parent; } else { XmlNodePlus parent = _parent; _parent = new XmlNodePlus(xmlnode, _parent.NumberFormat); ((XmlStreamObject)obj).Value = Load("Value", null); _parent = parent; } return(obj); } obj = Convert.ChangeType(xmlnode.Attributes["value"].Value, type, _parent.NumberFormat); return(obj); } else { string v = xmlnode.Attributes["value"].Value; if (xmlnode.Attributes["encryption_type"] != null) { switch (xmlnode.Attributes["encryption_type"].Value) { case "1": v = Crypto.Decrypt(v, "3f9932916f9746e1a3df048cc70dd30a"); break; } } return(v); } } catch/*(Exception ex)*/ { return(defValue); } }