/// <summary> /// Check driver id is unique /// </summary> public void CheckDriverId() { var dict = new Dictionary <string, int>();//Driver Id with Count foreach (var driver in this.manifest.Drivers) { var key = driver.DriverId; if (!dict.ContainsKey(key)) { dict[key] = 0; } dict[key]++; } var duplicates = (from row in dict where row.Value > 1 select row).ToList(); foreach (var did in duplicates) { MvLog.WarnNs(this, "Duplicate driver id: {0}", did.Key); } if (duplicates.Count != 0) { var did = duplicates.FirstOrDefault().Key; throw new MacWrongDriverException("Exist non-unique driver id " + did); } }
public int HalClose() { //關閉所有HAL foreach (var kv in this.HalDevices) { try { this.HalClose(kv.Value); } catch (Exception ex) { MvLog.WarnNs(this, ex); } } //釋放資源 foreach (var kv in this.Resources) { try { if (kv.Value == null) { continue; } kv.Value.Dispose(); } catch (Exception ex) { MvLog.WarnNs(this, ex); } } return(0); }
protected virtual void DisposeSelf() { if (this.Task != null) { this.Task.Dispose(); } if (this.Task != null) { //預期Task是能在迴圈開始時, 自己確認是否終止 //一般會以 disposed 和 IsCancellationRequested 作為持續的判斷 try { using (this.Task) if (!this.Task.Wait(3 * 1000)) { if (this.Task.Status < TaskStatus.Running) { MvLog.WarnNs(this, "MvTask is no start"); } else if (this.Task.Status == TaskStatus.Running) { MvLog.WarnNs(this, "MvTask can not cancel"); } } } catch (OperationCanceledException) { } this.Task = null; } }
public void ResourceDispose() { foreach (var rsc in this.Resources) { try { rsc.Value.Dispose(); } catch (Exception ex) { MvLog.WarnNs(this, ex); } } }
public void Close() { try { if (this.TcpClient != null) { using (var obj = this.TcpClient) { obj.Disconnect(); } } } catch (Exception ex) { MvLog.WarnNs(this, ex); } }
public int Close() { // 若 mobjCore 不為空 if (mobjCore != null) { // 將 mobjCore 斷開連線 try { mobjCore.Disconnect(); } catch (Exception ex) { MvLog.WarnNs(this, ex); } mobjCore = null; } return(0); }