internal static Layer FromXml(System.Xml.XmlNode layerNode, bool someFlag) { string layerClassName = layerNode.Attributes["Type"].Value.ToString(); Type overLayType = Type.GetType(layerClassName); Layer newLayer = (Layer)System.Activator.CreateInstance(overLayType); newLayer.FromXml(layerNode); return(newLayer); }
public static TourDocument FromXml(string filename) { TourDocument newTour = new TourDocument(); newTour.filename = filename; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["Tour"]; newTour.id = root.Attributes["ID"].Value.ToString(); newTour.Title = root.Attributes["Title"].Value.ToString(); newTour.Author = root.Attributes["Author"].Value.ToString(); if (root.Attributes["Descirption"] != null) { newTour.Description = root.Attributes["Descirption"].Value; } if (root.Attributes["Description"] != null) { newTour.Description = root.Attributes["Description"].Value; } if (root.Attributes["AuthorEmail"] != null) { newTour.authorEmail = root.Attributes["AuthorEmail"].Value; } if (root.Attributes["Keywords"] != null) { newTour.Keywords = root.Attributes["Keywords"].Value; } if (root.Attributes["OrganizationName"] != null) { newTour.OrgName = root.Attributes["OrganizationName"].Value; } if (root.Attributes["DomeMode"] != null) { newTour.DomeMode = bool.Parse(root.Attributes["DomeMode"].Value); } newTour.organizationUrl = root.Attributes["OrganizationUrl"].Value.ToString(); newTour.level = (UserLevel)Enum.Parse(typeof(UserLevel), root.Attributes["UserLevel"].Value.ToString()); newTour.type = (Classification)Enum.Parse(typeof(Classification), root.Attributes["Classification"].Value.ToString()); newTour.taxonomy = root.Attributes["Taxonomy"].Value.ToString(); bool timeLineTour = false; if (root.Attributes["TimeLineTour"] != null) { timeLineTour = bool.Parse(root.Attributes["TimeLineTour"].Value); } XmlNode TourStops = null; if (timeLineTour) { TourStops = root["TimeLineTourStops"]; } else { TourStops = root["TourStops"]; } foreach (XmlNode tourStop in TourStops) { newTour.AddTourStop(TourStop.FromXml(newTour, tourStop)); } XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; map.LoadedFromTour = true; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = root["Layers"]; if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = newTour.WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); // Overwite ISS layer if in a tour using the authored ISS details if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID == ISSLayer.ISSGuid) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } // Ask about merging other layers. if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID != ISSLayer.ISSGuid) { if (!newTour.CollisionChecked) { if (UiTools.ShowMessageBox(Language.GetLocalizedText(958, "There are layers with the same name. Overwrite existing layers?"), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { newTour.OverWrite = true; } else { newTour.OverWrite = false; } newTour.CollisionChecked = true; } if (newTour.OverWrite) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } } try { newLayer.LoadedFromTour = true; newLayer.LoadData(fileName); LayerManager.Add(newLayer, false); } catch { } } LayerManager.LoadTree(); } if (File.Exists(newTour.WorkingDirectory + "Author.png")) { newTour.authorImage = UiTools.LoadBitmap(newTour.WorkingDirectory + "Author.png"); } newTour.tourDirty = 0; return(newTour); }
public void MergeTourStopsFromXml(string filename) { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["Tour"]; bool timeLineTour = false; if (root.Attributes["TimeLineTour"] != null) { timeLineTour = bool.Parse(root.Attributes["TimeLineTour"].Value); } XmlNode TourStops = null; if (timeLineTour) { TourStops = root["TimeLineTourStops"]; } else { TourStops = root["TourStops"]; } foreach (XmlNode tourStop in TourStops) { currentTourstopIndex++; InsertTourStop(TourStop.FromXml(this, tourStop)); } XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = root["Layers"]; if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); newLayer.LoadData(fileName); LayerManager.Add(newLayer, false); } LayerManager.LoadTree(); } }
public static LayerContainer FromXml(string filename, string parentFrame, bool referenceFrameRightClick) { LayerContainer newDoc = new LayerContainer(); newDoc.filename = filename; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["LayerContainer"]; newDoc.id = root.Attributes["ID"].Value.ToString(); XmlNode Layers = root["Layers"]; bool loadAtNewParent = false; if (!referenceFrameRightClick || Layers.ChildNodes.Count != 1) { XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } } else { loadAtNewParent = true; } if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = newDoc.WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID != ISSLayer.ISSGuid) { if (!newDoc.CollisionChecked) { if (UiTools.ShowMessageBox(Language.GetLocalizedText(958, "There are layers with the same name. Overwrite existing layers?"), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { newDoc.OverWrite = true; } else { newDoc.OverWrite = false; } newDoc.CollisionChecked = true; } if (newDoc.OverWrite) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } } newLayer.LoadData(fileName); if (loadAtNewParent) { newLayer.ReferenceFrame = parentFrame; } LayerManager.Add(newLayer, false); newDoc.LastLoadedLayer = newLayer; } LayerManager.LoadTree(); } newDoc.tourDirty = 0; return(newDoc); }