views:

30

answers:

2

Guys i'm with a big problem.

I'm running a backoffice application, and imagine, i have a form than contains a gridview editable.

  1. 100 Users go to the page
  2. 100 Users view the form page as the data provided from database
  3. 100 Users edit some fields
  4. How control the final data and consistency in this example?
A: 

Before you can plan and implement the technical solution to this, ie. the code, you need to design the overall solution.

In other words, consider that you handed out 100 pieces of paper to 100 different people, each with a copy of that web-form on it. Those 100 people scribble notes on their paper, and then hand it back to you, in a random order.

How do you handle consistency in this scenario? When you can answer that, you can implement it.

Without knowing more about the data you have in that form, it will be practically impossible to give you concrete advice however.

Lasse V. Karlsen
A: 

Depends on what you want really. Do you have requirements? Are you fishing for suggestions?

One possible solution

If you have an explicit save action that is invoked when editing is complete,

  1. User navigates to page,
  2. User modifies table,
  3. User "saves",
  4. Page retrieves current values from datastore (as of time of save)
  5. Page compares current values to modified values
  6. Any conflicts are highlighted and requests user "resolve" the conflict
  7. Goto step 3. until there are no conflicts detected

Another possible solution

If you want to avoid that step 3. to step 7. loop, you could always wrap steps 4. through 6. in a transaction, meaning every other attempt to save blocks until current save is resolved. This is pretty heavy handed and requires a bit more work and may effectively reduce overall concurrency.

Yet another possible solution

Another possible solution is to make the process less discrete and more continuous. Provide a live feed of data.

  1. Create a WindowsService/WCF Service that pushes or allows polling of table data,
  2. Page polls for data or asynchronously receives data from remote service,
  3. Page modifies user's page contents with received data
  4. New values that do not conflict are temporarily highlighted in one colour (indicating conflict-free change), say light green
  5. New values that do conflict are permanently highlighted in red

If you have a save process, no red values may be saved until resolved.

Last (suggested) possible solution

If you have no explicit save action,

  1. User clicks on a cell (effectively requesting to edit a cell)
  2. Page communicates to Windows\WCF service requesting a "lock" on that cell,
  3. If no other user has requested a "lock" on that particular cell, then lock cell to that user and return true. If another user has requested lock on that particular cell, then respect current lock and return false.

If remote service returns false, then use-case ends, and cell cannot be modified. If remote service returns true, then user modifies contents and when they leave the cell or reloads page or whatever, the remote service releases the lock.

Conclusion

Alright, a bit of hand waving, but more than enough fat to chew. Give it some thought, there are many possible solutions.

johnny g