How to detect when a user navigates away from MMC FormView? - mmc

I have an MMC snapin (MMC 3.0) with a ScopeNode that adds a Microsoft.ManagementConsole.FormView. This FormView is used to edit a script. If the script contains syntax errors I need to prevent the user from navigating away from the form until the syntax errors are corrected. I can probably add event handlers to my script editor control to detect lost focus or window visibility change, but is there something in MMC that notifies and allows for cancelling the action?
What's the best way to detect that the user is navigating away from the FormView?

You can detect that the user is navigating away from the FormView by overriding the OnHide method:
protected override void OnHide()
{
System.Diagnostics.Debug.WriteLine("Navigated away from FormView.");
}
Unfortunately, you cannot cancel the navigation.

Related

Programmatically determine if Sagepay card details form is incomplete

I'm looking for some help with regards to the drop-in checkout integration.
https://developer-eu.elavon.com/docs/opayo/integrate-our-drop-checkout
In particular I'm following ‘custom flow’ example - see first code example for the Custom Flow section. https://developer-eu.elavon.com/docs/opayo/spec/api-reference#section/Custom-flow
In summary how can I programmatically determine if the sagepay 'card details' form which is injected into the sp-container (hosted in an iframe) is not valid for submission/tokenisation, when a call ‘tokenise’ link is used?
For example when the user has not completed all the required fields; Name, Card Number, Expiry or CVC.
I'm following the flow calling sagepayCheckout.tokenise() when the user clicks our 'Complete Payment' button (referred to as the tokenise link in the custom flow example).
NB: Implementation is part of a SPA app in my particular case I'm not submitting the (outer) form rather handling things using javascipt and calling the tokenise method.
Normally the onTokenise call back method is called on success or when wrong card details have been entered or merchantKey has expired. But when the injected sagepay form fails its own validity the onTokenise call back is never called.
NB: Due to browser security I can't check the state of the fields inside the iframe.
Ok some good points to note:
The sagepay form does feedback to the user about errors that required fields need to be completed.
And sagepayCheckout.tokenise() doesn't try to submit my (outer) form when these errors exist.
But there doesn't seem to be a programmatic way to know if the required fields need to be complete (or the onTokenise call back wont be called).
The main reason I need to know when the form is incompleted or tokenise has failed would be to re-enable our 'Complete Payment' button. Currently our button is disabled as soon as the user clicks it to prevent multiple clicks.
I am having this exact same problem. The only way I have been able to think of to get around this is to use the message event listener on the window. The sagepay.js library registers a 'message' event on the window object probably when the sagepayCheckout method is called.
Side note: this method is also poorly implemented as anything else that uses the window message event will cause the sagpay.js library to throw errors.
I think the only purpose of sagepay.js' message event hander is to resize the iframe window when its content changes. If you were to assume the content of the iframe will only change when validation fails you might be able use that to reset the state of your 'Complete Payment' button.
I would also suggest making a complaint to Opayo. This library is clunky and in desperate need of improvement.

What is the best approach to handle a Outlook add-in Inspector UI contorl null reference exception caused by cancelling a long running async call?

When user opens Outlook email item, my Outlook add-in creates an new Inspector in Outlook.Inspectors collection. To fill out Inspector form region user controls, few long running async DB calls are called. Generally, user can close email/Inspector window at any time while the async calls are running. The problem is the form region Close event occurs before async call completion. As a result, when async call is completed, my Inspector code tries to update form region user control but, by this moment, the control is null and disposed in form region Close event. Hence, null reference exception is thrown.
I added some code in Inspector Close event where I set up an ad-hoc flag indicating that Inspector is closed. The flag value is checked up in a catch(NullReferenceException) block. If flag shows that email is closed, the null reference exception is ignored and a new OperationCancelledException is thrown to cancel other related running async calls. Although the code works, I am not sure that this is the best approach to handle the error this way. Firstly, although the flag indicates that email is closed, the null reference exception might not be neccessary related to disposed UI user control. Secondly, I need to add catch(NullRefernceException) block to try-catch block in all relevant methods.
If you've had a similar problem, would you be able to advise your solution, please?
Thank you.
Instead of throwing and handling exceptions, I'd recommend keeping a dictionary of opened items, so you could easily detect whether a particular window is still opened. For example, you may develop an inspector wrapper - see Implement a wrapper for inspectors and track item-level events in each inspector.

How to run command when popup shows up?

I need to execute a command when popup shows up, like Loaded event, how can I do that? Do I need to override PopupWindowAction or it's supported already?
An interaction request is normally raised from code - execute the command just before raising the request, if that's possible.
Or you can execute it from the constructor of your popup's view model, that should happen a litte later.
As a last option, you can react to the Loaded event of your popup's content.
Another last option would be to override PopupWindowAction.CreateWindow and attach a handler to execute your command, but I'd prefer one of the code-only options that work without the actual view.

Handling windows button during Async BeginGetResponse in wp7

is there any way to handle the Windows button keypress within the *.Xaml.cs especially when the app is busy getting a request processed using an Asynchronous BeginGetResponse. is there a override handler like OnBackKeyPress?
What's the appropriate way to handle this use case? i'm already handling Application_Activated and deactivated in the App.Xaml.cs file for tombstoning.
You can't stop this from happening. When this happens the current page will get its OnNavigatedFrom override called so you could clean up your page and save state from this method.
Bear in mind that it won't be possible to tell whether this is due to the hardware Start key or if the user just navigated away by say pressing the Back key or tapping a button.
Update:
If you're trying to avoid a crash due to Fast App Switching interrupting your networking call you should rather handle this when you return to the application. Your WebRequest will be cancelled and you should handle this case as shown in this MSDN blog post.

Stop back button during data pull?

Is it possible to stop the back button from working during a data call? For instance, when registering, I don't want someone to press the back button otherwise they may register for my service and not know it (other than confirmation email)? (And the registration will fail the next time they try)
Handle the BackKeyPress event or override the OnBackKeyPress method in your page class, and then set e.Handled = true; when you want to prevent backwards navigation.
Note that if you do this, then you should provide the user with a way to cancel your long-running process so they can back out if they want to.
Please note that if you stop the Back button from working your application will fail marketplace submission.
See section 5.2.4 Use of Back Button.
If a user has the situation where they try to reregister (becuase they don't realise they have registered previously) then you should handle this in your app as the situation may come up anyway.

Resources