[Quantproject-developers] QuantProject/b1_ADT/FileManaging ObjectArchiver.cs,1.1,1.2
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-02-04 00:03:04
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/FileManaging In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4618/b1_ADT/FileManaging Modified Files: ObjectArchiver.cs Log Message: Fixed bugs and simplified code Index: ObjectArchiver.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/FileManaging/ObjectArchiver.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ObjectArchiver.cs 30 Jan 2005 19:55:36 -0000 1.1 --- ObjectArchiver.cs 4 Feb 2005 00:02:53 -0000 1.2 *************** *** 34,110 **** public class ObjectArchiver { ! private static Stream stream; ! private static BinaryFormatter formatter; ! private static Object archive; ! private static string fileName; ! private static string directoryPath; public static void Archive(Object objectToArchive, ! string fileName, ! string directoryPath) { ! ! try ! { ! ObjectArchiver.archive = objectToArchive; ! ObjectArchiver.setDiskPosition(fileName, directoryPath); ! ObjectArchiver.setVariables(); ! ObjectArchiver.formatter.Serialize(ObjectArchiver.stream, ! objectToArchive); ! } ! catch(Exception ex) ! { ! System.Windows.Forms.MessageBox.Show(ex.ToString()); ! } ! ! finally ! { ! ObjectArchiver.stream.Close(); } ! ! ! } ! ! private static void setDiskPosition(string fileName, ! string directoryPath) ! { ! ObjectArchiver.fileName = fileName; ! ObjectArchiver.directoryPath = directoryPath; ! ! } ! private static void setVariables() ! { ! ObjectArchiver.stream = new FileStream( ! ObjectArchiver.directoryPath + ! ObjectArchiver.fileName, ! FileMode.Create, ! FileAccess.Write, ! FileShare.None); ! ObjectArchiver.formatter = new BinaryFormatter(); ! } ! ! public static object Extract(string fileName, ! string directoryPath) { ! try ! { ! ObjectArchiver.setDiskPosition(fileName, directoryPath); ! ObjectArchiver.setVariables(); ! return ObjectArchiver.formatter.Deserialize(ObjectArchiver.stream); ! } ! catch(Exception ex) ! { ! System.Windows.Forms.MessageBox.Show(ex.ToString()); ! return new Object(); //just to avoid compiling error ! //throw new Exception("Extracting object failed!"); ! } ! finally ! { ! ObjectArchiver.stream.Close(); ! } } - } --- 34,82 ---- public class ObjectArchiver { ! private static Stream stream; ! private static BinaryFormatter formatter = ! new BinaryFormatter(); public static void Archive(Object objectToArchive, ! string fullPath) { ! try ! { ! ObjectArchiver.stream = new FileStream( ! fullPath, ! FileMode.Create, ! FileAccess.Write, ! FileShare.None); ! ! ObjectArchiver.formatter.Serialize(ObjectArchiver.stream, ! objectToArchive); } ! finally ! { ! ObjectArchiver.stream.Close(); ! } } ! ! ! public static object Extract(string fullPath) { ! object returnValue = null; ! ! try ! { ! ObjectArchiver.stream = new FileStream( ! fullPath, ! FileMode.Open, ! FileAccess.Read, ! FileShare.None); ! returnValue = ObjectArchiver.formatter.Deserialize(stream); ! } ! finally ! { ! ObjectArchiver.stream.Close(); ! } ! return returnValue; } } |