///<param name="currentForm">The form to activate once the progress is done. If you cannot possibly pass in a form, it is okay to pass in null. ///</param> public ODProgressExtended(ODEventType odEventType, IODEvent odEvent, Form currentForm, object tag = null, ProgBarStyle progBarStyle = ProgBarStyle.Blocks, string lanThis = "ProgressExtended", string cancelButtonText = null) { _actionCloser = ODProgress.ShowExtended(odEventType, odEvent.GetType(), currentForm, tag, new ProgressCanceledHandler((object sender, EventArgs e) => { IsCanceled = true; }), new ProgressPausedHandler((object sender, ProgressPausedArgs e) => { IsPaused = e.IsPaused; }), cancelButtonText); _event = odEvent; _progBarStyle = progBarStyle; _odEventType = odEventType; LanThis = lanThis; }
///<summary>Sends a requests to ODCloudClient and waits for a response. Throws any exception that ODCloudClient returns.</summary> private static string SendToODCloudClientSynchronously(ODCloudClientData cloudClientData, CloudClientAction cloudClientAction, int timeoutSecs = 30) { bool hasReceivedResponse = false; string odCloudClientResponse = ""; Exception exFromThread = null; void onReceivedResponse(string response) { hasReceivedResponse = true; odCloudClientResponse = response; } ODThread thread = new ODThread(o => { SendToODCloudClient(cloudClientData, cloudClientAction, onReceivedResponse); }); thread.Name = "SendToODCloudClient"; thread.AddExceptionHandler(e => exFromThread = e); thread.Start(); DateTime start = DateTime.Now; ODProgress.ShowAction(() => { while (!hasReceivedResponse && exFromThread == null && (DateTime.Now - start).TotalSeconds < timeoutSecs) { Thread.Sleep(100); } }); if (exFromThread != null) { throw exFromThread; } if (!hasReceivedResponse) { throw new ODException("Unable to communicate with OD Cloud Client.", ODException.ErrorCodes.ODCloudClientTimeout); } CloudClientResult result = JsonConvert.DeserializeObject <CloudClientResult>(odCloudClientResponse); if (result.ResultCodeEnum == CloudClientResultCode.ODException) { ODException odEx = JsonConvert.DeserializeObject <ODException>(result.ResultData); throw odEx; } if (result.ResultCodeEnum == CloudClientResultCode.Error) { throw new Exception(result.ResultData); } return(result.ResultData); }