public void LoadConfig(String file) { flags.loading = true; local.loading_canvas = this; try { XmlDocument xd = new XmlDocument(); if (!System.IO.File.Exists(local.ConfigName)) { return; } xd.Load(local.ConfigName); // the xd loader ends up with a full pathname with successful load // grab this so we can save to the same file. local.ConfigName = xd.BaseURI.Substring(8); XPathNavigator xn = xd.CreateNavigator(); //XPathNavigator xn2 = xn.CreateNavigator(); xn.MoveToFirst(); xn.MoveToFirstChild(); if (xn.NodeType == XPathNodeType.Element) { if (String.Compare(xn.Name, "xperdex") == 0) { bool okay; pages.Clear(); current_page = new page(this); first_page = true; //xn.MoveToFirstChild(); for (okay = xn.MoveToFirstChild(); okay; okay = xn.MoveToNext()) { // local, being static cannot implement persistance... bool loaded = local.Load(xn); if (!loaded) { foreach (object plugin in local.persistant_plugins) { // for all plugins that were loaded, if they have peristance // allow them to load... IReflectorPersistance persis = plugin as IReflectorPersistance; if (persis != null) { loaded = persis.Load(xn); if (loaded) { break; } } } } if (!loaded) { // should be at a place to handle canvas here... loaded = ((IReflectorPersistance)this).Load(xn); } if (!loaded) { Console.WriteLine("Attribute ignored..."); } } // parsing might totally fail, causing no data... // create a default page if one doesn't exist. if (pages.Count == 0) { page new_page; pages.Add(new_page = new page(this)); change_page_context_menu.Items.Add(new ToolStripMenuItem(new_page.Name)); } current_page = pages[0]; // all pages should be loaded from the XML from here.. xn.MoveToParent(); // should be at xperdex again. } } } catch (Exception e) { //e.Data.Values //System.Environment.StackTrace; //e.StackTrace; //Process.GetCurrentProcess(). //Thread.CurrentContext //Thread.CurrentThread. Log.log("XML Parsing faulted... " + e.Message); } local.loading_canvas = null; flags.loading = false; if (pages.Count == 0) { current_page = new page(this); } else { current_page = pages[0]; } foreach (IReflectorPlugin irp in local.persistant_plugins) { try { irp.FinishInit(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
bool IReflectorPersistance.Load(XPathNavigator r) { // okay so the glareset attributes of a PSI_Button are // saved before PSI Button information. gs.Load(r); // just give this a chance... { // glareset will result in the same position as it started (almost) //r.MoveToNext(); if (r.NodeType == XPathNodeType.Element) { if (String.Compare(r.Name, "PSI_Button", true) == 0) { bool ever_okay = false; bool okay; for (okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute()) { ever_okay = true; switch (r.Name.ToLower()) { case "decal": SetDecalName(r.Value); break; case "decal_scale": DecalScale = Convert.ToInt32(r.Value); break; case "text": Text = r.Value; break; //case "font": // FontTracker = FontEditor.GetFontTracker( r.Value ); // break; case "page": if (canvas != null) { NextPage = r.Value; } break; } } if (ever_okay) { r.MoveToParent(); } // child elements within PSI_Button tag... bool everokay2 = false; for (okay = r.MoveToFirstChild(); okay; okay = r.MoveToNext()) { everokay2 = true; switch (r.Name.ToLower()) { case "allow": AllowShow.Add(r.Value); break; case "disallow": DisallowShow.Add(r.Value); break; case "security": { bool okay3; bool everokay3 = false; for (okay3 = r.MoveToFirstAttribute(); okay3; okay3 = r.MoveToNext()) { everokay3 = true; switch (r.Name.ToLower()) { case "type": foreach (TypeName n in core_common.security_modules) { if (String.Compare(n.Name, r.Value) == 0) { object o = Activator.CreateInstance(n.Type); this.security_tags.Add(o); IReflectorPersistance p = o as IReflectorPersistance; if (p != null) { XPathNavigator tmp = r.CreateNavigator(); tmp.MoveToParent(); tmp.MoveToFirstChild(); p.Load(tmp); break; } } } break; } } if (everokay3) { r.MoveToParent(); } } break; } } CheckAllowedShow(); if (everokay2) { r.MoveToParent(); } return(true); } } } return(false); }
bool IReflectorPersistance.Load(XPathNavigator r) { if (String.Compare(r.Name, "Macro") == 0) { Object o; Assembly a = null; bool everokay = false; { // total violation of logic so far... but this is text... if (r.MoveToFirstAttribute()) { if (String.Compare(r.Name, "Text") == 0) { // ignore this, don't save it, would be redundant with button text... // Text = r.Value; } r.MoveToParent(); } } for (bool okay2 = r.MoveToFirstChild(); okay2; okay2 = r.MoveToNext()) { everokay = true; switch (r.Name) { case "Element": for (bool okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute()) { switch (r.Name) { case "Assembly": a = osalot.LoadAssembly(r.Value); break; case "Type": Type t = osalot.findtype(a, r.Value); o = Activator.CreateInstance(t); IReflectorPersistance persis = o as IReflectorPersistance; r.MoveToParent(); // out of attributes... if (persis != null) { r.MoveToFirstChild(); if (persis.Load(r)) { // return from my move to child... r.MoveToParent(); } // return from my move to attribute } osalot.AssemblyObject ao = new osalot.AssemblyObject(t, o); buttons.Add(ao); //r.MoveToParent(); break; } } break; } } // return from my move to child.... if (everokay) { r.MoveToParent(); } return(true); } return(false); }
internal bool Load(XPathNavigator r) { if (r.NodeType == XPathNodeType.Element) { if (String.Compare(r.Name, "page", true) == 0) { bool everokay; bool okay; //page p = new page(canvas); for (okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute()) { switch (r.Name) { case "background": background_name = r.Value; try { if (background_name.Length > 0 && System.IO.File.Exists(background_name)) { background_image = Image.FromFile(background_name); } else { background_image = null; } } catch { background_name = null; } break; case "title": title = r.Value; break; case "color": { try { background_color = Color.FromArgb(Convert.ToInt32(r.Value)); } catch { // probably alright, just bad... // background was already defaulted... } } break; case "x": partsX = r.ValueAsInt; break; case "y": partsY = r.ValueAsInt; break; } } r.MoveToParent(); //return true; //r.ReadEndElement(); everokay = false; for (okay = r.MoveToFirstChild(); okay; okay = r.MoveToNext()) { everokay = true; if (r.NodeType == XPathNodeType.Element) { switch (r.Name) { case "Security": foreach (TypeName module in core_common.security_modules) { IReflectorSecurity o = Activator.CreateInstance(module.Type) as IReflectorSecurity; IReflectorPersistance p = o as IReflectorPersistance; r.MoveToFirstChild(); if (p != null) { if (p.Load(r)) { security_tags.Add(o); } } r.MoveToParent(); } break; case "control": //page p = new page(); Rectangle rect = new Rectangle(); Assembly a; String a_name = null; Type t; font_tracker font = null; String t_name = null; String i_name = null; bool okay2; //page p = new page(canvas); for (okay2 = r.MoveToFirstAttribute(); okay2; okay2 = r.MoveToNextAttribute()) { switch (r.Name) { case "font": font = FontEditor.GetFontTracker(r.Value); break; case "X": rect.X = Convert.ToInt32(r.Value); break; case "Y": rect.Y = Convert.ToInt32(r.Value); break; case "width": rect.Width = Convert.ToInt32(r.Value); break; case "height": rect.Height = Convert.ToInt32(r.Value); break; case "assembly": if (r.Value.Length != 0) { a_name = r.Value; } break; case "type": t_name = r.Value; break; case "interface": if (string.Compare(r.Value, "System.RuntimeType") == 0) { break; } i_name = r.Value; break; } } // go back to element from attributes... r.MoveToParent(); { a = osalot.LoadAssembly(a_name); if (t_name != null && a != null) { t = osalot.findtype(a, t_name); Type[] i_list; Type i = t; if (i_name != null) { if (t == null) { continue; } else { i_list = t.FindInterfaces(osalot.MyInterfaceFilter, i_name); if (i_list.Length > 0) { i = i_list[0]; } } } ControlTracker created_control = MakeControl(t, i, rect); if (font != null && created_control.c != null) { font.Controls.Add(created_control.c); created_control.c.Font = font; } bool success = false; IReflectorPersistance persis; bool okay3; bool everokay3 = false; for (okay3 = r.MoveToFirstChild(); okay3; okay3 = r.MoveToNext()) { everokay3 = true; success = false; persis = created_control.o as IReflectorPersistance; if (persis != null) { try { success = persis.Load(r); } catch (Exception e) { Console.WriteLine(e); } } if (!success) { persis = created_control.c as IReflectorPersistance; if (persis != null) { try { success = persis.Load(r); } catch (Exception e) { Console.WriteLine(e); } } } if (!success) { Console.WriteLine("Ignored Element..."); } } if (everokay3) { r.MoveToParent(); } } } break; } } } if (everokay) { r.MoveToParent(); } return(true); } } return(false); }