Visual C#を使用して、ショッピングカートのエクスポートによって生成されたxmlファイルをx12 850EDItxtファイルに変更するファイル変換コンソールアプリを作成しています。作成中のtxtファイルに1つずつ番号を付けて、この新しい番号をアプリ自体に保存し、変換された次のファイルが最後に作成されたファイルを1つ超えて増分し、追加のファイルが変換されるたびに続行する必要があります。これを達成するための過去の方法は何ですか?ありがとうございました。
タイレル
Visual C#を使用して、ショッピングカートのエクスポートによって生成されたxmlファイルをx12 850EDItxtファイルに変更するファイル変換コンソールアプリを作成しています。作成中のtxtファイルに1つずつ番号を付けて、この新しい番号をアプリ自体に保存し、変換された次のファイルが最後に作成されたファイルを1つ超えて増分し、追加のファイルが変換されるたびに続行する必要があります。これを達成するための過去の方法は何ですか?ありがとうございました。
タイレル
プログラムのインスタンスが 1 つあり、アプリケーション (および場合によってはコンピューター) の再起動後も値を保持する必要があると仮定します。
intまたは使用するもので)Well it depends on a lot of things.
The main issue is going to be one of efficiency.
The file system watcher MSDN HERE will get you the events of the files being created, but then you will have to deal with all of the potential scenarios, like someone putting in files another type in the directory, multiple files at once, etc.
If I were designing such a thing I would consider a multithreaded app and some queueing.
Part#2...
It will not modify the integer, it will notify you when the files are created / deleted etc. Keeping count of those events will allow you to keep track of the files themselves. Persisting the setting would require something external to the running application such as a registry key or disk file. By queuing events from the file system watcher, you can control access to that persisted file in a clean organized manner ensuring that it always corresponds to the operation at hand, not just a file creation or deletion event.
Essentially every time the app loads get the last value from the file, as an operation process increment / decrement the value that is in memory and write it back out to that file. The value would be an integer in memory and simply incremented or decremented with a ++ or – as detailed here