まず、私はC#にあまり精通していないことを明確にしておきたいと思います。その中で、私が.Net 3.5を使用してC#で作業しているプロジェクトでは、レコードタイプに基づいて複数の固定幅形式を含むファイルを読み取ってエクスポートするクラスを構築しています。
現在、ファイルの各行の最初の文字位置で示される、特定の行形式を示す5種類のレコードがあります。私が抱えている問題は、タイプが互いに異なることです。
Record type 1 has 5 columns, signifies beginning of the file
Record type 3 has 10 columns, signifies beginning of a batch
Record type 5 has 69 columns, signifies a transaction
Record type 7 has 12 columns, signifies end of the batch, summarizes
(these 3 repeat throughout the file to contain each batch)
Record type 9 has 8 columns, signifies end of the file, summarizes
これらの種類の固定幅ファイル用の優れたライブラリはありますか?私は、ファイル全体を1つの仕様としてロードしたいが、それができないいくつかの良いものを見てきました。
これらのファイルのうち約250が月末に読み取られ、合計ファイルサイズは平均で約300メガバイトです。このプロジェクトでは、効率が非常に重要です。
データに関する知識に基づいて、オブジェクトがどのように見えるかを「考える」クラス階層を構築しました...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Extract_Processing
{
class Extract
{
private string mFilePath;
private string mFileName;
private FileHeader mFileHeader;
private FileTrailer mFileTrailer;
private List<Batch> mBatches; // A file can have many batches
public Extract(string filePath)
{ /* Using file path some static method from another class would be called to parse in the file somehow */ }
public string ToString()
{ /* Iterates all objects down the heiarchy to return the file in string format */ }
public void ToFile()
{ /* Calls some method in the file parse static class to export the file back to storage somewhere */ }
}
class FileHeader
{ /* ... contains data types for all fields in this format, ToString etc */ }
class Batch
{
private string mBatchNumber; // Should this be pulled out of the batch header to make LINQ querying simpler for this data set?
private BatchHeader mBatchHeader;
private BatchTrailer mBatchTrailer;
private List<Transaction> mTransactions; // A batch can have multiple transactions
public string ToString()
{ /* Iterates through batches to return what the entire batch would look like in string format */ }
}
class BatchHeader
{ /* ... contains data types for all fields in this format, ToString etc */ }
class Transaction
{ /* ... contains data types for all fields in this format, ToString etc */ }
class BatchTrailer
{ /* ... contains data types for all fields in this format, ToString etc */ }
class FileTrailer
{ /* ... contains data types for all fields in this format, ToString etc */ }
}
私は多くのコンストラクターや他のメソッドを省略しましたが、アイデアはかなりしっかりしているはずだと思います。私は、C#について知識がなく、実行時間が最優先事項である、私が再び検討している方法に対するアイデアと批評を探しています。
いくつかの批評以外の最大の質問は、このファイルをどのように持ち込むべきかということです。FSOメソッドを使用してVBAなどの他の言語で多くのファイルを取り込み、ファイルを読み取るためのMicrosoft Access ImportSpec(5回、仕様ごとに1つ...非効率的でした!)、で「カーソル」オブジェクトを作成しましたvisual foxpro(これはFAAAAAAASTでしたが、5回実行する必要がありました)が、C#で隠された宝石を探しています。
私の小説を読んでくれてありがとう、あなたがそれを理解するのに問題があるかどうか私に知らせてください。私は週末にこのデザインを調べて、購入するかどうかを確認し、この方法で実装するための努力をしたいと思っています。