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> /// 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); } }