| 1 |
/* |
| 2 |
* FeliCa2Money |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2008 Takuya Murakami |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
using System; |
| 22 |
using System.Collections.Generic; |
| 23 |
using System.Text; |
| 24 |
using FelicaLib; |
| 25 |
|
| 26 |
namespace FeliCa2Money |
| 27 |
{ |
| 28 |
abstract class Card |
| 29 |
{ |
| 30 |
protected string org; // 組織名 |
| 31 |
protected int bankId = 0; // 銀行番号 |
| 32 |
protected string branchId = "0"; // 支店番号 |
| 33 |
protected string accountId = ""; // 口座番号 |
| 34 |
protected string cardName; // カード名 |
| 35 |
|
| 36 |
public abstract List<Transaction> ReadCard(); |
| 37 |
|
| 38 |
public string Org |
| 39 |
{ |
| 40 |
get { return this.org; } |
| 41 |
} |
| 42 |
|
| 43 |
public int BankId |
| 44 |
{ |
| 45 |
get { return this.bankId; } |
| 46 |
} |
| 47 |
public string BranchId |
| 48 |
{ |
| 49 |
get { return this.branchId; } |
| 50 |
} |
| 51 |
public string CardName |
| 52 |
{ |
| 53 |
get { return this.cardName; } |
| 54 |
} |
| 55 |
|
| 56 |
public string AccountId |
| 57 |
{ |
| 58 |
set { this.accountId = value; } |
| 59 |
get { return this.accountId; } |
| 60 |
} |
| 61 |
|
| 62 |
protected string[] ParseLine(string line) |
| 63 |
{ |
| 64 |
return line.Split('\t'); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
abstract class CardWithFelicaLib : Card, IDisposable |
| 69 |
{ |
| 70 |
protected int systemCode; // システムコード |
| 71 |
protected int serviceCode; // サービスコード |
| 72 |
protected bool needReverse; // レコード順序を逆転するかどうか |
| 73 |
|
| 74 |
// カード ID 取得 |
| 75 |
public abstract void analyzeCardId(Felica f); |
| 76 |
|
| 77 |
// Transaction 解析 |
| 78 |
public abstract bool analyzeTransaction(Transaction t, byte[] data); |
| 79 |
|
| 80 |
public override List<Transaction> ReadCard() |
| 81 |
{ |
| 82 |
List<Transaction> list = new List<Transaction>(); |
| 83 |
|
| 84 |
using (Felica f = new Felica()) |
| 85 |
{ |
| 86 |
f.Polling(systemCode); |
| 87 |
analyzeCardId(f); |
| 88 |
|
| 89 |
for (int i = 0; ; i++) |
| 90 |
{ |
| 91 |
byte[] data = f.ReadWithoutEncryption(serviceCode, i); |
| 92 |
if (data == null) break; |
| 93 |
|
| 94 |
Transaction t = new Transaction(); |
| 95 |
|
| 96 |
// データが全0かどうかチェック |
| 97 |
int x = 0; |
| 98 |
foreach (int xx in data) |
| 99 |
{ |
| 100 |
x |= xx; |
| 101 |
} |
| 102 |
if (x == 0) |
| 103 |
{ |
| 104 |
// データが全0なら無視(空エントリ) |
| 105 |
t.Invalidate(); |
| 106 |
} |
| 107 |
|
| 108 |
// トランザクション解析 |
| 109 |
else if (!analyzeTransaction(t, data)) |
| 110 |
{ |
| 111 |
t.Invalidate(); |
| 112 |
} |
| 113 |
list.Add(t); |
| 114 |
} |
| 115 |
} |
| 116 |
if (needReverse) |
| 117 |
{ |
| 118 |
list.Reverse(); |
| 119 |
} |
| 120 |
PostProcess(list); |
| 121 |
|
| 122 |
return list; |
| 123 |
} |
| 124 |
|
| 125 |
protected virtual void PostProcess(List<Transaction> list) |
| 126 |
{ |
| 127 |
// do nothing |
| 128 |
} |
| 129 |
|
| 130 |
public virtual void Dispose() |
| 131 |
{ |
| 132 |
} |
| 133 |
} |
| 134 |
} |