Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/10 00:44:01 (14 years ago)
Author:
swagner
Message:

Sorted usings and removed unused usings in entire solution (#1094)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/IO/Binary/BinarySerializer.cs

    r3038 r4068  
    44using System.Runtime.Serialization;
    55using System.Runtime.Serialization.Formatters.Binary;
    6 using System.Xml.Serialization;
    7 using System.Xml;
    86using System.Windows.Forms;
    9 namespace Netron.Diagramming.Core
    10 {
    11   /// <summary>
    12   /// Utility class to binary (de)serialize a diagram (from) to file
    13   /// </summary>
    14   public static class BinarySerializer
    15   {
    16     #region Methods
     7namespace Netron.Diagramming.Core {
     8  /// <summary>
     9  /// Utility class to binary (de)serialize a diagram (from) to file
     10  /// </summary>
     11  public static class BinarySerializer {
     12    #region Methods
    1713
    18         /// <summary>
    19         /// Binary saves the diagram
    20         /// </summary>
    21         /// <param name="fileName">the file-path</param>
    22         /// <param name="control">The control.</param>
    23         /// <returns></returns>
    24     public static  bool SaveAs(string fileName, DiagramControlBase control)
    25     {
     14    /// <summary>
     15    /// Binary saves the diagram
     16    /// </summary>
     17    /// <param name="fileName">the file-path</param>
     18    /// <param name="control">The control.</param>
     19    /// <returns></returns>
     20    public static bool SaveAs(string fileName, DiagramControlBase control) {
    2621
    27       FileStream fs = new FileStream(fileName, FileMode.Create);
     22      FileStream fs = new FileStream(fileName, FileMode.Create);
    2823
    29       GenericFormatter<BinaryFormatter> f = new GenericFormatter<BinaryFormatter>();
     24      GenericFormatter<BinaryFormatter> f = new GenericFormatter<BinaryFormatter>();
    3025
    3126      try {
     
    4439        //DumpInfo();
    4540      }
    46       finally
    47       {
    48         fs.Close();
    49       }
    50       return false;
    51     }
    52         /// <summary>
    53         /// Opens the binary-saved diagram
    54         /// </summary>
    55         /// <param name="fileName">Name of the file.</param>
    56         /// <param name="control">The control.</param>
    57     public static  bool Open (string fileName, DiagramControlBase control)
    58     {
    59       FileStream fs=null;
    60      
    61       try
    62       {
    63         fs= File.OpenRead(fileName);
    64       }
    65       catch (System.IO.DirectoryNotFoundException exc)
    66       {
    67         System.Windows.Forms.MessageBox.Show(exc.Message);
    68       }
    69       catch(System.IO.FileLoadException exc)
    70       {       
    71         System.Windows.Forms.MessageBox.Show(exc.Message);
    72       }
    73       catch (System.IO.FileNotFoundException exc)
    74       {
    75         System.Windows.Forms.MessageBox.Show(exc.Message);
    76       }
    77       catch(Exception exc)
    78       {       
    79         throw new Exception("Non-CLS exception caught.", exc);
    80       }
    81       //donnot open anything if filestream is not there
    82       if (fs==null)
    83             {
    84                 return false;
    85             }
     41      finally {
     42        fs.Close();
     43      }
     44      return false;
     45    }
     46    /// <summary>
     47    /// Opens the binary-saved diagram
     48    /// </summary>
     49    /// <param name="fileName">Name of the file.</param>
     50    /// <param name="control">The control.</param>
     51    public static bool Open(string fileName, DiagramControlBase control) {
     52      FileStream fs = null;
    8653
    87       try
    88       {
     54      try {
     55        fs = File.OpenRead(fileName);
     56      }
     57      catch (System.IO.DirectoryNotFoundException exc) {
     58        System.Windows.Forms.MessageBox.Show(exc.Message);
     59      }
     60      catch (System.IO.FileLoadException exc) {
     61        System.Windows.Forms.MessageBox.Show(exc.Message);
     62      }
     63      catch (System.IO.FileNotFoundException exc) {
     64        System.Windows.Forms.MessageBox.Show(exc.Message);
     65      }
     66      catch (Exception exc) {
     67        throw new Exception("Non-CLS exception caught.", exc);
     68      }
     69      //donnot open anything if filestream is not there
     70      if (fs == null) {
     71        return false;
     72      }
    8973
    90                 GenericFormatter<BinaryFormatter> f = new GenericFormatter<BinaryFormatter>();     
    91                 //one-line deserialization, no bits 'nd bytes necessary....C# is amazing...
    92         Document document =  f.Deserialize<Document>(fs);
     74      try {
    9375
    94                 if(document == null)
    95                     throw new InconsistencyException("The deserialization return 'null'.");
    96                 //call the standard method at the control level to attach a new document
    97                 //In principle you could create a document programmatically and attach it this way as well.
    98                 control.AttachToDocument(document);
    99                 return true;
    100       }
    101       catch(SerializationException exc)     
    102       {
    103         MessageBox.Show(exc.Message);
    104       }
    105       catch(System.Reflection.TargetInvocationException exc)
    106       {
    107         MessageBox.Show(exc.Message, "BinarySerializer.Open");
    108       }
    109       catch(Exception exc)
    110       {
    111                 MessageBox.Show(exc.Message, "BinarySerializer.Open");
    112       }
    113       finally
    114       {
    115                 if (fs != null)
    116                 {
    117                     fs.Close();
    118                 }
    119       }
    120             return false;
    121     }
     76        GenericFormatter<BinaryFormatter> f = new GenericFormatter<BinaryFormatter>();
     77        //one-line deserialization, no bits 'nd bytes necessary....C# is amazing...
     78        Document document = f.Deserialize<Document>(fs);
    12279
    123    
    124     #endregion
    125   }
     80        if (document == null)
     81          throw new InconsistencyException("The deserialization return 'null'.");
     82        //call the standard method at the control level to attach a new document
     83        //In principle you could create a document programmatically and attach it this way as well.
     84        control.AttachToDocument(document);
     85        return true;
     86      }
     87      catch (SerializationException exc) {
     88        MessageBox.Show(exc.Message);
     89      }
     90      catch (System.Reflection.TargetInvocationException exc) {
     91        MessageBox.Show(exc.Message, "BinarySerializer.Open");
     92      }
     93      catch (Exception exc) {
     94        MessageBox.Show(exc.Message, "BinarySerializer.Open");
     95      }
     96      finally {
     97        if (fs != null) {
     98          fs.Close();
     99        }
     100      }
     101      return false;
     102    }
     103
     104
     105    #endregion
     106  }
    126107}
Note: See TracChangeset for help on using the changeset viewer.