// Private methods. /// <summary> /// A callback method called when the control completes an asynchrnous request for a PlanetLab resource. /// </summary> /// <param name="result">The result of the asynchronous operation.</param> private void OnCallback(AsyncWebResult result) { lock (this.sync) { // If the current request is null, do nothing. if (null == this.request) return; try { // The asynchronous web result. AsyncWebResult asyncResult = null; // Complete the asyncrhonous request. XmlRpcResponse response = this.request.End(result, out asyncResult); // If no fault occurred during the XML-RPC request. if (response.Fault == null) { // Display a success notification message. this.ShowMessage( Resources.GlobeSuccess_48, "PlanetLab Update", "Refreshing the PlanetLab information completed successfully.", false, (int)ApplicationConfig.MessageCloseDelay.TotalMilliseconds, (object[] parameters) => { // Call the complete request event handler. this.OnRequestResult(response, asyncResult.AsyncState as RequestState); // Call the end request event handler. this.OnRequestFinished(asyncResult.AsyncState as RequestState); }); } else { // Display an error notification message. this.ShowMessage( Resources.GlobeWarning_48, "PlanetLab Error", "Refreshing the PlanetLab information has failed (RPC code {0} {1})".FormatWith(response.Fault.FaultCode, response.Fault.FaultString), false, (int)ApplicationConfig.MessageCloseDelay.TotalMilliseconds, (object[] paremeters) => { // Call the complete request event handler. this.OnRequestResult(response, asyncResult.AsyncState as RequestState); // Call the end request event handler. this.OnRequestFinished(asyncResult.AsyncState as RequestState); }); } // Set the current request to null. this.request = null; this.result = null; } catch (WebException exception) { // Set the current request to null. this.request = null; this.result = null; // If the exception status is canceled. if (exception.Status == WebExceptionStatus.RequestCanceled) { // Hide the notification message. this.HideMessage((object[] parameters) => { // Call the cancel request handler. this.OnRequestCanceled(result.AsyncState as RequestState); // Call the end request handler. this.OnRequestFinished(result.AsyncState as RequestState); }); // Begin a pending request, if any. this.BeginRequest(); } else { // Display an error notification message. this.ShowMessage( Resources.GlobeError_48, "PlanetLab Update", "Refreshing the PlanetLab information has failed. {0}".FormatWith(exception.Message), false, (int)ApplicationConfig.MessageCloseDelay.TotalMilliseconds, (object[] parameters) => { // Call the exception handler. this.OnRequestException(exception, result.AsyncState as RequestState); // Call the request finished event handler. this.OnRequestFinished(result.AsyncState as RequestState); }); } } catch (Exception exception) { // Set the current request to null. this.request = null; this.result = null; // Display an error notification message. this.ShowMessage( Resources.GlobeError_48, "PlanetLab Update", "Refreshing the PlanetLab information has failed. {0}".FormatWith(exception.Message), false, (int)ApplicationConfig.MessageCloseDelay.TotalMilliseconds, (object[] parameters) => { // Call the exception handler. this.OnRequestException(exception, result.AsyncState as RequestState); // Call the request finished event handler. this.OnRequestFinished(result.AsyncState as RequestState); }); } } }
/// <summary> /// Begins a new asynchronous PlanetLab request. /// </summary> /// <param name="request">The PlanetLab request.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="parameters">The request parameters.</param> /// <param name="state">The request state.</param> protected void BeginRequest(PlRequest request, string username, SecureString password, object[] parameters, RequestState state = null) { // Set the pending values to null. this.pendingRequest = null; this.pendingUsername = null; this.pendingPassword = null; this.pendingParameters = null; this.pendingState = null; lock (this.sync) { // If a request is already in progress. if (null != this.request) { // Set the pending values. this.pendingRequest = request; this.pendingUsername = username; this.pendingPassword = password; this.pendingParameters = parameters; this.pendingState = state; // Cancel the current request this.request.Cancel(this.result); // Return. return; } // Save the new request. this.request = request; try { // Show the notification box. this.ShowMessage( Resources.GlobeClock_48, "PlanetLab Update", "Refreshing the PlanetLab information...", true, -1, (object[] param) => { this.OnRequestStarted(state); }); // If the parameter is not null. if (null != parameters) { // Begin the request with a parameter. this.result = request.Begin( username, password, parameters, this.OnCallback, state ); } else { // Begin the request without a parameter. this.result = request.Begin( username, password, this.OnCallback, state ); } } catch (Exception exception) { // Set the current request and result to null. this.request = null; this.result = null; // Show the notification box. this.ShowMessage( Resources.GlobeError_48, "PlanetLab Update", "Refreshing the PlanetLab information failed. {0}".FormatWith(exception.Message), false, (int)ApplicationConfig.MessageCloseDelay.TotalMilliseconds, (object[] param) => { // Call the request exception event handler. this.OnRequestException(exception, state); // Call the request finished event handler. this.OnRequestFinished(state); }); } } }
/// <summary> /// Cancels the current request, if any. /// </summary> protected void CancelRequest() { lock (sync) { // If there is no current request, do nothing. if (null == this.request) return; // Cancel the current request this.request.Cancel(this.result); // Set the pending values to null. this.pendingRequest = null; this.pendingUsername = null; this.pendingPassword = null; this.pendingParameters = null; this.pendingState = null; } }
/// <summary> /// Begins a new asynchronous PlanetLab request. /// </summary> /// <param name="request">The PlanetLab request.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="parameter">The request parameter.</param> /// <param name="state">The request state.</param> protected void BeginRequest(PlRequest request, string username, SecureString password, object parameter = null, RequestState state = null) { this.BeginRequest( request, username, password, parameter != null ? new object[] { parameter } : null, state); }