0

I have a requirement where in I am processing some XML on server in a web application
Assume there is a button on a asp.net page. When the user clicks the button, I call a function say button_click() -> which in turns calls some service method to process XML.

Problem scenario::
Now lets say I am processing the XML and I am done with 50% of the processing. I notice that I have to get confirmation of user since some value in the XML is invalid. At this point I want to show a prompt to user to say yes or no ( may be a javascript prompt ) and then:
1. if the user clicks OK -> I want to continue processing the remaining 50% of the XML
2. if the user clicks NO -> I want to stop processing and display an error message.

After lot of trial and error and my knowledge of developing web application, I felt that there is no way to do this, unless I start execution of my service again with some flags when the user clicks OK. But my colleagues are not convinced and they say there must be a way to do that and I lack the knowledge for it. Its quiet an interesting problem.

**NOTE : We are actually porting an existing desktop application into web hence the problem of dialog boxes !

I request you to kindly help me regarding this experts ! Also I would like to know is there any other way to do handle such scenarios ?

EDIT : Adding more info.
Actually what I mean here by XML processing is every user has some XML created by server using a WINDOWS service. When the user clicks on some button , we have to process that XML and if everything is correct, we have to call third party service and get results and update the DB.
What happens sometimes is, the WINDOWS service that creates the XML puts some invalid values ( we cant correct them since its not under our control ) . So, we need to get a confirmation to the user that some values are invalid and if he wants to proceed. In this way we want to be doubly sure that we are sending invalid values by the consent of user. The problem is we identify the value is invalid sometimes at the end of the XML file (we cant change this) , so we dont want to process the XMl once again !

  • 2
    I suppose the first question would be - can the *processing* (whatever that may be) itself be paused? This seems more like the question you should be asking as the confirmation dialog/continue part is pretty trivial. – James Dec 14 '12 at 11:44
  • @James - Ya gud input ! Modified my question using your inputs :) – Gurucharan Balakuntla Maheshku Dec 14 '12 at 11:49
  • have a look at this: http://stackoverflow.com/questions/10462839/javascript-confirmation-dialog-on-href-link – matpol Dec 14 '12 at 11:55
  • @GuruC I updated your question title so it's a bit more specific. For me to understand what's going on at the server side, could you elaborate on what "*processing the XML*" is actually doing? Would be worth updating your question so other people get a good understanding. – James Dec 14 '12 at 11:55
  • @GuruC: So the processing is asynchronous, and is not completed before the response is sent? – Bergi Dec 14 '12 at 11:58
  • @James - I have added more info to the question. I hope I have made it more clear. Please let me know if any1 needs more details! This is a critical problem for me and I need to find a solution by end of tomorrow :( – Gurucharan Balakuntla Maheshku Dec 14 '12 at 12:13
  • @Bergi - the processing is synchronous and it is not completed before the response is sent ! I know the problem is little out of actual way a web application works. Its just that I want to rule out any other way in which we could achieve this and may be I have missed it ! – Gurucharan Balakuntla Maheshku Dec 14 '12 at 12:15
  • @GuruC: What does not work with just storing the current state of the process and sending the dialogue box instead of a result view? – Bergi Dec 14 '12 at 12:18

2 Answers2

0

You should setup a process whereby the frontend (jquery/JavaScript) continually polls for status updates from the long running process. A typical use of this would be where you want to update a percent done gauge so the user can see that progress is being made, except in this case instead of retrieving the %done value, you retrieve a status code and/or message. If there is a message, show it to the user and update back to the server; the backed process will enter a wait state once the status code is sent to the front end, and will also need to poll the flag (which could be as simple as a value in a db table for example) for the users response.

Here is an example of a %done type polling proceSs:

http://sudhirmurthy.blogspot.com/2011/12/update-on-long-running-server-tasks.html

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • @Brennan - the problem is the process itself is not very long. Just that we want some confirmation in between while we are processing from user thats all. Also we need not show the dialog always . We have to show it only if there is invalid value in XML. I have added more info to my question ! – Gurucharan Balakuntla Maheshku Dec 14 '12 at 12:12
  • Doesn't matter how long it is, once the front-end kicks off the process, it should immediately start polling a value on the server that indicates process, not % done, but some user-defined value that would indicate a conformation is needed. You need to look at the code in the linked article and adpat it from reporting the % done, to reporting a status code instead, i.e. 'running', 'waiting on user confirmation', 'done' - you need to think of this as the front-end is polling the back-end for updates, as opposed to the back-end needs to send an exception to the front-end. – E.J. Brennan Dec 14 '12 at 12:15
0

As you haven't detailed the actual specifics of what your "XML processing" is I am going to assume it's uploading/parsing of an XML Document (perhaps an import of some sort).

The first step is to actually get your server being able to pause execution (or processing) of the XML at a specific state. The only way you are going to be able to do this is to store the current state of the processing e.g. line number, segments processed etc. This state would then need to be stored somewhere that would allow the server to pick up where it left off i.e. temp file on server, memory cache, backend database - it's up to you to pick storage that will best suit your application.

The next step is notifying the client when processing has paused. As this is supposed to be an atomic operation you could use a technique called Long Polling to stay connected to the server for longer periods (less polling) and would make the notification feel more instantaneous. Alternatively you could use regular polling and query the state at regular intervals - either way, it's that particular response from the server that would trigger the client to throw up the dialog.

Finally, you want to tell the server how to proceed - this could be done via a simple API call as server has all it needs to know in order to continue processing.

An example, API for this could look like:

public void ConfirmProcessing(Guid processingInstanceId, bool cancel)
{
     var processingState = GetProcessingStateFromStorage(processingInstanceId);
     if (!cancel)
     {
         // resume processing
     }
     else
     {
         // discard processing
     }
}

When you get the notification from the server for confirmation it could send down a unique id (i.e. processingInstanceId) which you then send back up via the API with a flag indicating how you want to proceed e.g. Continue/Cancel.

James
  • 80,725
  • 18
  • 167
  • 237