public void FromXml(XmlDocument doc) { XmlNode root = Util.SelectSingleNode(doc, "Tour"); id = root.Attributes.GetNamedItem("ID").Value.ToString(); Title = root.Attributes.GetNamedItem("Title").Value.ToString(); Author = root.Attributes.GetNamedItem("Author").Value.ToString(); if (root.Attributes.GetNamedItem("Descirption") != null) { Description = root.Attributes.GetNamedItem("Descirption").Value; } if (root.Attributes.GetNamedItem("AuthorEmail") != null) { authorEmail = root.Attributes.GetNamedItem("AuthorEmail").Value; } if (root.Attributes.GetNamedItem("Keywords") != null) { Keywords = root.Attributes.GetNamedItem("Keywords").Value; } if (root.Attributes.GetNamedItem("OrganizationName") != null) { OrgName = root.Attributes.GetNamedItem("OrganizationName").Value; } organizationUrl = root.Attributes.GetNamedItem("OrganizationUrl").Value.ToString(); switch (root.Attributes.GetNamedItem("UserLevel").Value) { case "Beginner": level = UserLevel.Beginner; break; case "Intermediate": level = UserLevel.Intermediate; break; case "Advanced": level = UserLevel.Advanced; break; case "Educator": level = UserLevel.Educator; break; case "Professional": level = UserLevel.Professional; break; default: break; } switch (root.Attributes.GetNamedItem("Classification").Value) { case "Star": type = Classification.Star; break; case "Supernova": type = Classification.Supernova; break; case "BlackHole": type = Classification.BlackHole; break; case "NeutronStar": type = Classification.NeutronStar; break; case "DoubleStar": type = Classification.DoubleStar; break; case "MultipleStars": type = Classification.MultipleStars; break; case "Asterism": type = Classification.Asterism; break; case "Constellation": type = Classification.Constellation; break; case "OpenCluster": type = Classification.OpenCluster; break; case "GlobularCluster": type = Classification.GlobularCluster; break; case "NebulousCluster": type = Classification.NebulousCluster; break; case "Nebula": type = Classification.Nebula; break; case "EmissionNebula": type = Classification.EmissionNebula; break; case "PlanetaryNebula": type = Classification.PlanetaryNebula; break; case "ReflectionNebula": type = Classification.ReflectionNebula; break; case "DarkNebula": type = Classification.DarkNebula; break; case "GiantMolecularCloud": type = Classification.GiantMolecularCloud; break; case "SupernovaRemnant": type = Classification.SupernovaRemnant; break; case "InterstellarDust": type = Classification.InterstellarDust; break; case "Quasar": type = Classification.Quasar; break; case "Galaxy": type = Classification.Galaxy; break; case "SpiralGalaxy": type = Classification.SpiralGalaxy; break; case "IrregularGalaxy": type = Classification.IrregularGalaxy; break; case "EllipticalGalaxy": type = Classification.EllipticalGalaxy; break; case "Knot": type = Classification.Knot; break; case "PlateDefect": type = Classification.PlateDefect; break; case "ClusterOfGalaxies": type = Classification.ClusterOfGalaxies; break; case "OtherNGC": type = Classification.OtherNGC; break; case "Unidentified": type = Classification.Unidentified; break; case "SolarSystem": type = Classification.SolarSystem; break; case "Unfiltered": type = Classification.Unfiltered; break; case "Stellar": type = Classification.Stellar; break; case "StellarGroupings": type = Classification.StellarGroupings; break; case "Nebulae": type = Classification.Nebulae; break; case "Galactic": type = Classification.Galactic; break; case "Other": type = Classification.Other; break; default: break; } taxonomy = root.Attributes.GetNamedItem("Taxonomy").Value.ToString(); XmlNode TourStops = Util.SelectSingleNode(root, "TourStops"); foreach (XmlNode tourStop in TourStops.ChildNodes) { if (tourStop.Name == "TourStop") { AddTourStop(TourStop.FromXml(this, tourStop)); } } XmlNode Frames = Util.SelectSingleNode(root, "ReferenceFrames"); if (Frames != null) { foreach (XmlNode frame in Frames.ChildNodes) { if (frame.Name == "ReferenceFrame") { 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[newFrame.Name] = map; } } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = Util.SelectSingleNode(root, "Layers"); if (Layers != null) { foreach (XmlNode layer in Layers.ChildNodes) { if (layer.Name == "Layer") { Layer newLayer = new Layer().FromXml(layer, true);//.Layer.FromXml(layer, true); if (newLayer != null) { string fileName = string.Format("{0}.txt", newLayer.ID.ToString()); if (LayerManager.LayerList.ContainsKey(newLayer.ID)) // && newLayer.ID != ISSLayer.ISSGuid) { //if (!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) // { // OverWrite = true; // } // else // { // OverWrite = false; // } // CollisionChecked = true; //} //if (OverWrite) //{ LayerManager.DeleteLayerByID(newLayer.ID, true, false); //} } try { newLayer.LoadedFromTour = true; newLayer.LoadData(GetFileStream(fileName)); LayerManager.Add(newLayer, false); } catch { } } } } LayerManager.LoadTree(); } //todo author //if (File.Exists(WorkingDirectory + "Author.png")) //{ // authorImage = UiTools.LoadBitmap(WorkingDirectory + "Author.png"); //} tourDirty = 0; }
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 TourDocument FromUrl(string url, Action callMe) //{ // TourDocument temp = new TourDocument(); // temp.Url = url; // temp.callMe = callMe; // temp.webFile = new WebFile(Util.GetTourComponent(url, "master")); // temp.webFile.OnStateChange = temp.LoadXmlDocument; // temp.webFile.Send(); // return temp; //} //private void LoadXmlDocument() //{ // if (webFile.State == StateType.Error) // { // Script.Literal("alert({0})", webFile.Message); // } // else if (webFile.State == StateType.Received) // { // FromXml(webFile.GetXml()); // callMe(); // } //} public void FromXml(XmlDocument doc) { XmlNode root = Util.SelectSingleNode(doc, "Tour"); id = root.Attributes.GetNamedItem("ID").Value.ToString(); Title = root.Attributes.GetNamedItem("Title").Value.ToString(); Author = root.Attributes.GetNamedItem("Author").Value.ToString(); if (root.Attributes.GetNamedItem("Descirption") != null) { Description = root.Attributes.GetNamedItem("Descirption").Value; } if (root.Attributes.GetNamedItem("AuthorEmail") != null) { authorEmail = root.Attributes.GetNamedItem("AuthorEmail").Value; } if (root.Attributes.GetNamedItem("Keywords") != null) { Keywords = root.Attributes.GetNamedItem("Keywords").Value; } if (root.Attributes.GetNamedItem("OrganizationName") != null) { OrgName = root.Attributes.GetNamedItem("OrganizationName").Value; } organizationUrl = root.Attributes.GetNamedItem("OrganizationUrl").Value; level = (UserLevel)Enums.Parse("UserLevel", root.Attributes.GetNamedItem("UserLevel").Value); type = (Classification)Enums.Parse("Classification", root.Attributes.GetNamedItem("Classification").Value); taxonomy = root.Attributes.GetNamedItem("Taxonomy").Value.ToString(); XmlNode TourStops = Util.SelectSingleNode(root, "TourStops"); foreach (XmlNode tourStop in TourStops.ChildNodes) { if (tourStop.Name == "TourStop") { AddTourStop(TourStop.FromXml(this, tourStop)); } } XmlNode Frames = Util.SelectSingleNode(root, "ReferenceFrames"); if (Frames != null) { foreach (XmlNode frame in Frames.ChildNodes) { if (frame.Name == "ReferenceFrame") { 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[newFrame.Name] = map; } } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = Util.SelectSingleNode(root, "Layers"); if (Layers != null) { foreach (XmlNode layer in Layers.ChildNodes) { if (layer.Name == "Layer") { Layer newLayer = Layer.FromXml(layer, true);//.Layer.FromXml(layer, true); if (newLayer != null) { string fileName = string.Format("{0}.txt", newLayer.ID.ToString()); if (LayerManager.LayerList.ContainsKey(newLayer.ID)) // && newLayer.ID != ISSLayer.ISSGuid) { //if (!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) // { // OverWrite = true; // } // else // { // OverWrite = false; // } // CollisionChecked = true; //} //if (OverWrite) //{ LayerManager.DeleteLayerByID(newLayer.ID, true, false); //} } try { newLayer.LoadedFromTour = true; newLayer.LoadData(this, fileName); LayerManager.Add(newLayer, false); } catch { } } } } LayerManager.LoadTree(); } //todo author //if (File.Exists(WorkingDirectory + "Author.png")) //{ // authorImage = UiTools.LoadBitmap(WorkingDirectory + "Author.png"); //} tourDirty = 0; }
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); }