private XmlNode GetXmlNode(XmlDocument doc, PersistObject obj) { if (obj == null) { return(null); } XmlNode node = doc.CreateNode(XmlNodeType.Element, obj.Name, null); if (obj.Attributes != null) { foreach (KeyValuePair <string, string> att in obj.Attributes) { if (string.IsNullOrEmpty(att.Key)) { continue; } XmlAttribute attNode = doc.CreateAttribute(att.Key); if (att.Value == null) { attNode.Value = string.Empty; } else { attNode.Value = att.Value; } node.Attributes.Append(attNode); } } return(node); }
private void WriteObjectToResponseStream(object obj, HttpContext context) { Stream st = PersistObject.ObjectToStream(obj); using (BinaryReader br = new BinaryReader(st)) { byte[] bs = br.ReadBytes((int)st.Length); context.Response.OutputStream.Write(bs, 0, bs.Length); } }
void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
public void SaveVectorItemShowMethod(ILayerItem item) { if (item.Tag is CodeCell.AgileMap.Core.FeatureLayer) { FeatureLayer layer = item.Tag as FeatureLayer; if (layer != null) { FileDataSource dataSource = layer.Class.DataSource as FileDataSource; if (dataSource == null) { return; } string fileUrl = dataSource.FileUrl; if (string.IsNullOrEmpty(fileUrl)) { return; } string sourceFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"SystemData\MapTemplate.mcd"); if (!File.Exists(sourceFileName)) { return; } string shpName = Path.GetFileNameWithoutExtension(fileUrl); string newFileName = Path.Combine(Path.GetDirectoryName(fileUrl), shpName + ".mcd"); File.Copy(sourceFileName, newFileName, true); XmlDocument doc = new XmlDocument(); doc.Load(newFileName); XmlNode layerNodes = doc.SelectSingleNode("Map").SelectSingleNode("Layers"); if (layerNodes == null) { return; } IPersistable persist = layer as IPersistable; PersistObject layerObj = persist.ToPersistObject(); XmlNode layerNode = GetXmlNode(doc, layerObj); layerNodes.AppendChild(layerNode); if (layerObj.SubNodes != null) { foreach (PersistObject sub in layerObj.SubNodes) { PersistObjectToXmlNode(doc, layerNode, sub); } } doc.Save(newFileName); } } }
private void PersistObjectToXmlNode(XmlDocument doc, XmlNode parentNode, PersistObject obj) { if (obj == null) { return; } XmlNode node = GetXmlNode(doc, obj); parentNode.AppendChild(node); if (obj.SubNodes != null) { foreach (PersistObject subobj in obj.SubNodes) { PersistObjectToXmlNode(doc, node, subobj); } } }