简体   繁体   中英

How to check if file has been copied to output directory because it was newer than one previously?

I have setup process which persist data onto my database, the data consist of small json which using a json deserializer become an object, and that object is then persisted to the database. My problem here is that it takes time to persist all data in to the database during runtime, and most often I only need to do it case of file has been changed, or something has been added to it.

I know this is the case when a new file is being copied to the output directory, as the file setting for the json files are to copy if the file is newer.

But how do i utilize this in my application, currently I just purge my database, and reinsert everything but since most of the data is stale (meaning it hasn't changed for months) I wont need to reinsert them, but only those which has changed.

So how do check which files has been changed/overwritten in the output directory from my application?

Project setting states, that my files are copied to the output directory if they are newer, but how can I from my application detect whether a file is newer or not?

I have to use the output directory to check whether the file has been changed.

You can not use override time of output directory file as only info to detect if you should sync changes. Output content is created on build and publish actions so if file is overwritten it is done at those points not when you run application. You can build and publish your application multiple times without running it and question is: When is file overwritten?

After that you can run and stop your application multiple times and question is: Is your file overwritten and synced with DB?

You can: (1) use hashes or (2) implement mechanism for versioning your files (File.GetLastWriteTime (path) and log that to DB after syncing data) or (3) implement a mechanism to explicitly say you want to sync those files (some config flag that will be resetted after sync or copy of edited file which will be deleted after sync)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM