/// <summary> /// Returns a BinaryReport of the diagram save in the given path/file /// </summary> /// <param name="filePath"></param> /// <returns></returns> private BinaryReport GetReport(string filePath) { BinaryReport report = new BinaryReport(); BinaryCapsule capsule = LoadCapsule(filePath); if (capsule != null) { report.Thumbnail = capsule.Thumbnail; GraphInformation info = capsule.Abstract.GraphInformation; report.Author = info.Author; report.CreationDate = info.CreationDate; report.Description = info.Description; report.FileSize = new System.IO.FileInfo(filePath).Length; report.Path = filePath; report.Subject = info.Subject; report.Title = info.Title; if (OnReport != null) { OnReport(report, OutputInfoLevels.Info); } return(report); } else { return(null); } }
private BinaryCapsule LoadCapsule(string fileName) { 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 { Trace.WriteLine("Non-CLS exception caught.", "BinarySerializer.SaveAs"); } //donnot open anything if filestream is not there if (fs == null) { return(null); } try { BinaryFormatter f = new BinaryFormatter(); BinaryCapsule capsule = (BinaryCapsule)f.Deserialize(fs); return(capsule); } catch (System.Runtime.Serialization.SerializationException exc) { Trace.WriteLine(exc.Message, "BinaryReporter.LoadCapsule"); return(null); } catch (Exception exc) { Trace.WriteLine(exc.Message, "BinaryReporter.LoadCapsule"); return(null); } }