public void SetCallback(OnProgressHandler onProgress, OnErrorHandler onError, OnSuccHandler onSucc, OnURLRedirectHandler onRedirect) { m_onProgressHandler = onProgress; m_onErrorHandler = onError; m_onSuccHandler = onSucc; m_onRedirectHandler = onRedirect; }
public override void OnError(CameraDevice camera, [GeneratedEnum] CameraError error) { var e = Tuple.Create <CameraDevice, CameraError>(camera, error); // throw new NotImplementedException(); OnErrorHandler?.Invoke(this, e); }
/// <summary> /// Called by the DataProviders to invoke the OnError event handler /// </summary> /// <param name="packet">The esEntityPacket in error</param> /// <param name="ex">The exception that was thrown</param> public void FireOnError(esEntitySavePacket packet, string error) { OnErrorHandler handler = OnError; if (handler != null) { handler(packet, error); } }
public static void WsAddOnError(uint objectId, OnErrorHandler callback) { if (!JslibInterop.onErrorHandlers.ContainsKey(objectId)) { JslibInterop.onErrorHandlers[objectId] = null; } JslibInterop.onErrorHandlers[objectId] += callback; }
public static void WsRemoveOnError(uint objectId, OnErrorHandler callback) { if (!JslibInterop.onErrorHandlers.ContainsKey(objectId)) { return; } JslibInterop.onErrorHandlers[objectId] -= callback; }
/// <summary> /// Simple mockup for performing a operation for SQL-Server /// </summary> /// <returns></returns> public static async Task <bool> ProcessData(System.Threading.CancellationToken token) { return(await Task.Run(async() => { using (var cn = new SqlConnection() { ConnectionString = ConnectionString }) { await cn.OpenAsync(token); var trans = cn.BeginTransaction("operation1"); using (var cmd = new SqlCommand() { Connection = cn, Transaction = trans }) { cmd.CommandText = "Place first SQL here"; try { await cmd.ExecuteNonQueryAsync(token); cmd.CommandText = "Next SQL goes here"; await cmd.ExecuteNonQueryAsync(token); return true; } catch (Exception e) { try { trans.Rollback(); OnErrorHandler?.Invoke(e); throw; } catch (Exception transEx) { OnErrorHandler?.Invoke(transEx); return false; } } } } }, token)); }
/// <summary> /// Read csv file /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static List <Person> ReadFile(string fileName) { var people = new List <Person>(); var currentLineNumber = 0; if (!File.Exists(fileName)) { return(people); } var lines = File.ReadAllLines(fileName); LineCount = lines.Length; foreach (var line in lines) { currentLineNumber += 1; try { var parts = line.Split(','); /* * The proper way to deal with this is to assert there are two elements, * in this case the developer simply assumed there is a comma. */ var person = new Person() { FirstName = parts[0], LastName = parts[1] }; people.Add(person); OnPersonAddedEvent?.Invoke(person); } catch (Exception ex) { OnErrorHandler?.Invoke(ex, currentLineNumber); Exceptions.Write(ex); SkippedLineCount += 1; } } return(people); }
/// <summary>Event Error(904)</summary> /// <param name="reply">回覆的訊息(執行結果)</param> /// <remarks> /// <para>除非規格書有異動, 否則</para> /// <para>1. 函式名稱不得修改</para> /// <para>2. 函式不得刪除</para> /// </remarks> public void ERROR(ReplyMessage reply) { ReplyErrorCode replyErrorCode = (ReplyErrorCode)((int)reply.Value); if (OnErrorHandler != null) { var args = new OnErrorEventArgs(replyErrorCode); OnErrorHandler.Invoke(this, args); } if (OnERRORRecoveryHandler != null && replyErrorCode == ReplyErrorCode.Recovery) { OnERRORRecoveryHandler.Invoke(this, EventArgs.Empty); } if (OnERRORErrorHandler != null && replyErrorCode == ReplyErrorCode.Error) { OnERRORErrorHandler.Invoke(this, EventArgs.Empty); } }
public bool DownLoadFile(string url, string saveFile, OnProgressHandler onProgress, OnErrorHandler onError, OnSuccHandler onSucc, OnURLRedirectHandler onRedirect) { bool hasTask = m_httpWorker != null; m_downLoadContent = null; m_onProgressHandler = onProgress; m_onErrorHandler = onError; m_onSuccHandler = onSucc; m_onRedirectHandler = onRedirect; m_fileName = saveFile; m_httpWorker = new HttpClientHelper(saveFile, url, ++m_workerSerNum); m_loopCheckHelper.SetActive(true); m_httpWorker.SetCallback(new OnProgressHandler(this.OnProgress), new OnErrorHandler(this.OnError), new OnSuccHandler(this.OnSucc), new OnURLRedirectHandler(this.OnReidrect)); m_httpWorker.Start(); return(hasTask); }
internal void Send(string method, string path, IDictionary<string, object> parameters, object body, OnErrorHandler onError, OnHttpSuccessHandler onSuccess) { var req = this.CreateRequest(method, path, parameters, body); if (body != null) { req.ContentType = "application/json"; var str = JsonConvert.SerializeObject(body); byte[] byteArray = Encoding.UTF8.GetBytes(str); req.ContentLength = byteArray.Length; var requestStream = req.GetRequestStream(); requestStream.Write(byteArray, 0, byteArray.Length); requestStream.Close(); } var StreamDecode = Encoding.UTF8.GetDecoder(); var res = req.GetResponse(); var stream = res.GetResponseStream(); JObject result = null; using(var reader = new StreamReader(stream)) { var str = reader.ReadToEnd(); Console.WriteLine("result : " + str); result = JObject.Parse(str); var code = result["response"]["code"].Value<int>(); var message = result["response"]["message"].Value<string>(); var tmp = result["result"]; var resultData = tmp != null ? tmp.ToString() : null; if (result["response"]["code"].Value<int>() == 100) { onSuccess(resultData); } else { onError(new Exceptions.KPIException(code, message)); } } res.Close(); }
/// <summary> /// Returns the next time a tuning done event fires. /// </summary> /// <param name="timeout">The number of milliseconds to wait before timing out.</param> /// <returns>The wavelength/lambda returned from the tuning done event.</returns> /// <exception cref="TimeoutException">Thrown when the elapsed time exceeds the specified timeout.</exception> /// <exception cref="LCTFBusyException">Thrown when the LCTF sends a busy interrupt to signify that it was busy and can't handle the request at this time.</exception> /// <exception cref="InvalidOperationException">Thrown when the LCTF throws an error.</exception> public Task <int> WaitForTune(int timeout = 30000) { TaskCompletionSource <int> tcs = new TaskCompletionSource <int>(); OnErrorHandler errorHandler = null; OnBusyHandler busyHandler = null; OnTuningDoneHandler tuningDoneHandler = null; // Hook up for error events this.OnError += errorHandler = (state, lambda) => { this.OnError -= errorHandler; tcs.TrySetException(new InvalidOperationException("LCTF threw an error while trying to tune.")); }; // Hook up for busy events this.OnBusy += busyHandler = (state, lambda) => { this.OnBusy -= busyHandler; tcs.TrySetException(new LCTFBusyException("LCTF was busy and not able to handle the last request.")); }; // Hook up for tuning done events this.OnTuningDone += tuningDoneHandler = (lambda) => { // Remove the handler so we don't run on the next one this.OnTuningDone -= tuningDoneHandler; tcs.TrySetResult(lambda); }; Task.Delay(timeout).ContinueWith( (delayTask) => { this.OnError -= errorHandler; this.OnTuningDone -= tuningDoneHandler; tcs.TrySetException(new TimeoutException($"{nameof(this.WaitForTune)} timed out after {timeout}ms")); }, TaskScheduler.Default); return(tcs.Task); }
public void AddData(object data, OnErrorHandler onError = null, OnDataAddedHandler onSuccess = null) { if (onError == null) { onError = this.OnError; } if (onSuccess == null) { onSuccess = this.OnSuccess; } DataItem item = null; try { item = new DataItem(data, onError, onSuccess); } catch (Exception exc) { onError(exc); return; } this.queue.Enqueue(item); this.Send(this.Config.BatchSize); }
public MainForm() { Updater updater = new Updater(); string link = updater.CheckForNewestVersion(RBTVSendeplanCS.Properties.Settings.Default.Version); if (link != null) { MyMessageBox.ShowDialog("New Version", "New Version available", link); } if (CheckForSettingsFile() == true) { LoadSettings(); } else { SaveSettings(); } InitializeComponent(); Event_OnEventsLoaded += new OnEventsLoadedHandler(AddEventsToPanel); Event_OnError += new OnErrorHandler(DisplayErrorPopup); this.Show(); }
/// <summary> /// Set the message handler to be called when errors are encountered subscribing to the topic. /// </summary> /// <param name="callback"></param> public void OnSubscriptionError(OnErrorHandler callback) { _errorCallback = callback; }
public BaseRequestBuilder <T> SetCompletion(OnErrorHandler errorHandler) { onError = errorHandler; return(this); }
internal DataItem(object data, OnErrorHandler onError, OnDataAddedHandler onSuccess) { if (data == null) { throw new ArgumentNullException("data"); } var type = data.GetType(); if (!(type.IsClass && !type.IsPrimitive)) { throw new Exception("Invalid parameter"); } this.Data = data; this.OnError = onError; this.OnSuccess = onSuccess; }
public void Send(string collection, object data, OnErrorHandler onError = null, OnDataAddedHandler onSuccess = null) { var command = this.Command(collection); command.AddData(data, onError, onSuccess); }