Search code examples
c#timelannas

C# Get Time from Network Attached Storage on Small LAN


I don't know if this is something that can be done or not, so please be patient with me. First I will describe the environment.

We have 8 laptops that will be used offline to do work in a stand-alone Access database. We have a large wired router. A NAS drive is connected to the router. When the laptop users come in from the field, they will connect their laptops to the router. The front-end to the Access database is a C# program. A master copy of the database exists on the NAS. The LAN is not connected to the Internet.

When the users connect their laptops to the LAN, we want a full SYNC to occur. So, any new records that exist on the NAS database will be downloaded to their laptops. Any new records that they have created on their laptops will be uploaded to the NAS.

All primary keys are GUID's. I have added a DateTime field to each table. Anytime any record in any table is added or changed, the timestamp is updated. No records will ever be deleted.

Each users laptop will know the datetime of their last snc. So the download to the users laptop will get all records where the timestamp is newer than the last sync. The upload to the NAS will be based on time as well.

So, I cannot guarantee that all users laptops will be time synced with each other. These laptops will never be connected to the Internet or to a server. So I do not want to use the times from the users laptops to record the timestamps. I want the time to come from the NAS if possible. If I know the MAC address or IP address of the NAS, is it possible to query the current time from the NAS? Is this feasible? If so, can someone point me in the right direction?


Solution

  • Don't use time because its a horrible analog for what you're really after. Time can go backwards, time can be inaccurate, it can be changed by the user. Even if you use time from the NAS box, it can still be a mess.

    What you're really after is some form of transaction system, akin to what git does.

    If you're willing to store a field per record, why not store some sort of commit ID? I'd have two columns - the global commit ID and the local commit ID.

    The global commit ID stores the database record's last commit ID when it was synced with the NAS. The local commit ID stores changes that were made to a record by the client.

    • NAS starts up empty.
    • Client1 syncs with the empty NAS.
    • Client1 initializes the local commit ID for each record by copying it from the global commit ID for that record.
    • Client1 goes offline.
    • Client1 changes a record, and thus increments its local commit ID.
    • Client1 attaches to the NAS.
    • Client1 examines its copy of the database - its sees that some record has a local commit ID greater than the global commit ID for that record in its copy of the database (this is not the NAS's version of the global commit ID).
    • Client1 sends that record to the NAS database.
    • Client1 updates its copy of the global commit ID for that record in its local copy.
    • NAS increments the global commit ID for that record.
    • Client1 scans the NAS database for records that have a global commit ID greater than the client's global commit ID, updating these records in its local copy of the database.