/[msmoney_db_parser]/trunk/libmsmoneyfile/MSMoneyFile.cs
ViewVC logotype

Contents of /trunk/libmsmoneyfile/MSMoneyFile.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Mon Sep 19 05:09:46 2016 UTC (3 years ago) by william
File size: 3008 byte(s)
add some files that were not comitted
1 using System;
2 using System.IO;
3 using Enterprise.Logging;
4 using System.Text;
5 using System.Collections.Generic;
6
7
8 namespace libmsmoneyfile
9 {
10 public static class MSMoneyFile
11 {
12 internal const string MAGIC_MSMONEY_BACKUP_FILE = "MSCF";
13 internal const string MAGIC_MSMONEY_DATABASE = "MSISAM Database";
14 internal const string MAGIC_JETDB_DATABASE = "Standard Jet DB";
15 private static IMSMoneyFile OpenMSMoneyFile(FileInfo file) { return OpenMSMoneyFile (file.FullName); }
16 private static IMSMoneyFile OpenMSMoneyFile(string file)
17 {
18 string magic = "";
19 _MSMoneyFile money_file = new _MSMoneyFile (file);
20 gLog.Info.WriteLine ("Opening MSMoney file: {0}", file);
21
22 if (!File.Exists (file)) {
23 gLog.Error.WriteLine ("Could not find MSMoney file: {0}", file);
24 throw new FileNotFoundException (string.Format("Could not find MSMoney file: {0}", file));
25 }
26
27 using (FileStream fs = new FileStream(file,FileMode.Open,FileAccess.Read, FileShare.Read)) {
28 using (BinaryReader br = new BinaryReader(fs)) {
29 byte[] raw_magic = br.ReadBytes (MAGIC_MSMONEY_BACKUP_FILE.Length);
30 magic = Encoding.ASCII.GetString(raw_magic);
31
32 if (magic != MAGIC_MSMONEY_BACKUP_FILE) {
33 raw_magic = br.ReadBytes (MAGIC_MSMONEY_DATABASE.Length);
34 magic = Encoding.ASCII.GetString(raw_magic);
35 }
36 br.Close ();
37 }
38 fs.Close();
39 }
40
41 switch(magic)
42 {
43 case MAGIC_MSMONEY_BACKUP_FILE:
44 money_file.FileType = MSMONEY_FILE_TYPE.MSMONEY_BACKUP_FILE;
45 break;
46 case MAGIC_MSMONEY_DATABASE:
47 money_file.FileType = MSMONEY_FILE_TYPE.MSMONEY_DATABASE_FILE;
48 break;
49 case MAGIC_JETDB_DATABASE:
50 money_file.FileType = MSMONEY_FILE_TYPE.STANDARDJET_DATABASE_FILE;
51 break;
52 default:
53 money_file.FileType = MSMONEY_FILE_TYPE.INVALID_FILE;
54 break;
55 }
56
57 return money_file;
58 }
59
60 public static IMSMoneyParser ParseMSMoneyFile(FileInfo file)
61 {
62 return ParseMSMoneyFile (file);
63 }
64 public static IMSMoneyParser ParseMSMoneyFile(string file)
65 {
66 var msmoney_file = OpenMSMoneyFile (file);
67 IMSMoneyParser parser = null;
68 // switch (msmoney_file.FileType)
69 // {
70 // case MSMONEY_FILE_TYPE.MSMONEY_BACKUP_FILE:
71 // parser = new MSCF_Parser (msmoney_file);
72 // break;
73 // case MSMONEY_FILE_TYPE.MSMONEY_DATABASE_FILE:
74 // parser = new MSISAM_Parser (msmoney_file);
75 // break;
76 // default:
77 // throw new InvalidOperationException (string.Format("unknown msmoney file: {0}", file));
78 // }
79
80 switch (msmoney_file.FileType) {
81 case MSMONEY_FILE_TYPE.MSMONEY_BACKUP_FILE:
82 case MSMONEY_FILE_TYPE.MSMONEY_DATABASE_FILE:
83 throw new NotImplementedException (string.Format("Parsing for file type: '{0}' has not been implemented.", msmoney_file.FileType.ToString()));
84 case MSMONEY_FILE_TYPE.STANDARDJET_DATABASE_FILE:
85 parser = new jetdb_parser (msmoney_file);
86 break;
87 default:
88 throw new InvalidOperationException (string.Format("unknown file type: {0}", file));
89 }
90
91 return parser;
92 }
93 }
94 }
95

  ViewVC Help
Powered by ViewVC 1.1.22