/// <summary> /// Saves the diagram to NML format /// </summary> /// <param name="fileName">the file-path</param> /// <param name="site">the graph-control instance to be serialized</param> /// <returns></returns> public static bool SaveAs(string fileName, GraphControl site) { XmlTextWriter tw = null; try { tw = new XmlTextWriter(fileName,System.Text.Encoding.Unicode); tw.Formatting = System.Xml.Formatting.Indented; IO.NML.NMLSerializer g = new IO.NML.NMLSerializer(); g.Serialize(tw,site.Abstract); return true; } catch(Exception exc) { //TODO: more specific exception handling here Trace.WriteLine(exc.Message, "NMLSerializer.SaveAs"); } catch { Trace.WriteLine("Non-CLS exception caught.","BinarySerializer.SaveAs"); } finally { if(tw!=null) tw.Close(); } return false; }
/// <summary> /// Opens a NML serialized file /// </summary> /// <param name="filename"></param> /// <param name="site"></param> public static void Open(string filename, GraphControl site) { try { XmlTextReader reader = new XmlTextReader(filename); IO.NML.NMLSerializer ser = new IO.NML.NMLSerializer(site); site.extract = ser.Deserialize(reader) as GraphAbstract; reader.Close(); } catch (System.IO.DirectoryNotFoundException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch (System.IO.FileLoadException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch (System.IO.FileNotFoundException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch { site.OutputInfo("Non-CLS exception caught.", "BinarySerializer.SaveAs", OutputInfoLevels.Exception); } }
/// <summary> /// Opens a NML serialized file /// </summary> /// <param name="filename"></param> /// <param name="site"></param> public static void Open(string filename, GraphControl site) { try { XmlTextReader reader = new XmlTextReader(filename); IO.NML.NMLSerializer ser = new IO.NML.NMLSerializer(site); site.Abstract = ser.Deserialize(reader) as GraphAbstract; reader.Close(); } catch (System.IO.DirectoryNotFoundException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch(System.IO.FileLoadException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch (System.IO.FileNotFoundException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch { site.OutputInfo("Non-CLS exception caught.","BinarySerializer.SaveAs", OutputInfoLevels.Exception); } }
/// <summary> /// Saves the diagram to NML format /// </summary> /// <param name="fileName">the file-path</param> /// <param name="site">the graph-control instance to be serialized</param> /// <returns></returns> public static bool SaveAs(string fileName, GraphControl site) { XmlTextWriter tw = null; try { tw = new XmlTextWriter(fileName, System.Text.Encoding.Unicode); tw.Formatting = System.Xml.Formatting.Indented; IO.NML.NMLSerializer g = new IO.NML.NMLSerializer(); g.Serialize(tw, site.Abstract); return(true); } catch (Exception exc) { //TODO: more specific exception handling here Trace.WriteLine(exc.Message, "NMLSerializer.SaveAs"); } catch { Trace.WriteLine("Non-CLS exception caught.", "BinarySerializer.SaveAs"); } finally { if (tw != null) { tw.Close(); } } return(false); }