protected BinaryCapsule(SerializationInfo info, StreamingContext context) { try { this.mBinaryAmbiance = info.GetValue("mBinaryAmbiance", typeof(BinaryAmbiance)) as BinaryAmbiance; } catch (Exception exc) { Trace.WriteLine(exc.Message, "BinaryCapsule.DeserializationConstructor"); //trying to recover the old binaries this.mBinaryAmbiance = info.GetValue("mBinaryAmbience", typeof(BinaryAmbiance)) as BinaryAmbiance; } this.mGraphAbstract = info.GetValue("mGraphAbstract", typeof(GraphAbstract)) as GraphAbstract; if (mGraphAbstract != null && mGraphAbstract.Layers != null) { foreach (GraphLayer tLayer in mGraphAbstract.Layers) { if (tLayer.Name != "Default" && tLayer.Visible) { mGraphAbstract.ActiveLayer(tLayer.Name); break; } } if (mGraphAbstract.CurrentLayer == null) { mGraphAbstract.ActiveLayer("Default"); } } this.mThumbnail = info.GetValue("mThumbnail", typeof(Image)) as Image; }
/// <summary> /// Opens the binary-saved diagram /// </summary> /// <param name="fileName"></param> /// <param name="site"></param> public static void Open(string fileName, GraphControl site) { FileStream fs = null; try { fs = File.OpenRead(fileName); } 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); } //donnot open anything if filestream is not there if (fs == null) { return; } try { BinaryFormatter f = new BinaryFormatter(); //this added for temporarily solving the open file issue //of different namespace of customed shapes: SequenceShape, IfShape etc. //if save flowchart data file using one version, open with another version, //exception raised: "无法找到程序集..." //TODO: remove below statement for release version f.Binder = new UBinder(); BinaryCapsule capsule = (BinaryCapsule)f.Deserialize(fs); //so simple, so powerful GraphAbstract tmp = capsule.Abstract; foreach (GraphLayer tLayer in tmp.Layers) { if (tLayer.Visible && tLayer.Name != "Default") { tmp.ActiveLayer(tLayer.Name); break; } } if (tmp.CurrentLayer == null) { tmp.ActiveLayer("Default"); } SetControlAmbiance(site, capsule.Ambiance); tmp.Site = site; //site.extract = new GraphAbstract(); site.extract = tmp; //the paintables are not serialized and need to be filled site.extract.paintables.AddRange(site.extract.Shapes); site.extract.paintables.AddRange(site.extract.Connections); site.extract.SortPaintables(); UnwrapBundle(tmp, site); } catch (SerializationException exc) { System.Windows.Forms.MessageBox.Show(exc.Message); } catch (System.Reflection.TargetInvocationException exc) { site.OutputInfo(exc.Message, "BinarySerializer.Open", OutputInfoLevels.Exception); } catch (Exception exc) { site.OutputInfo(exc.Message, "BinarySerializer.Open", OutputInfoLevels.Exception); } catch { site.OutputInfo("Non-CLS exception caught.", "BinarySerializer.Open", OutputInfoLevels.Exception); } finally { if (fs != null) { fs.Close(); } } }