public static FingerResult MakeFailed(Exception e, double time, string value = "") { var retval = new FingerResult() { Succeeded = false, ExtendedError = e, Value = value, TimeInSeconds = time }; return(retval); }
public static FingerResult MakeSucceeded(string value, double time) { var retval = new FingerResult() { Succeeded = true, ExtendedError = null, Value = value, TimeInSeconds = time }; return(retval); }
public static FingerResult MakeFailed(SocketErrorStatus status, double time, string value = "") { var retval = new FingerResult() { Succeeded = false, ExtendedError = null, _ManuallySetStatus = status, Value = value, TimeInSeconds = time }; return(retval); }
/// <summary> /// 指纹添加 /// </summary> /// <param name="fingerResult"></param> public static void AddFingerPrintByUser(FingerResult fingerResult) { UserInfos userInfo = PoliceInfos.Find(p => p.UserID.Equals(fingerResult.UserID)); if (userInfo == null) { return; } userInfo.Fingers.Add(new Finger() { FingerID = fingerResult.FingerID, FingerName = fingerResult.FingerName }); userInfo.FingerNumber = userInfo.Fingers.Count; }
/// <summary> /// 指纹采集结果 /// </summary> /// <param name="value"></param> private void AnalyzeCollectFingerPrint(string value) { App.Current.Dispatcher.Invoke(new Action(() => { FingerResult fingerResult = XmlUnityConvert.XmlDeserialize <FingerResult>(value); CollectFingerWindow collectFingerWindow = WindowsHelper.GetWindow <CollectFingerWindow>(); if (collectFingerWindow == null || !(collectFingerWindow.CurrentUser.UserID.Equals(fingerResult.UserID))) { return; } collectFingerWindow.FingerImage = fingerResult.FingerImage; collectFingerWindow.FingerStatus = fingerResult.ResultCode == 0 ? FingerStatus.RecordSuccess : FingerStatus.RecordFail; })); }
/// <summary> /// 编辑结果修改 /// </summary> /// <param name="fingerResult"></param> public static void EditorFingerPrintByUserID(FingerResult fingerResult) { UserInfos userInfo = PoliceInfos.Find(p => p.UserID.Equals(fingerResult.UserID)); if (userInfo == null) { return; } if (!string.IsNullOrEmpty(fingerResult.FingersEditor)) { string[] fingers = fingerResult.FingersEditor.Split(','); foreach (var item in fingers) { string[] fingerInfo = item.Split(':'); if (fingerInfo.Length != 2) { continue; } Finger finger = userInfo.Fingers.Find(p => p.FingerID.Equals(fingerInfo[0])); if (finger != null) { finger.FingerName = fingerInfo[1]; } } } if (!string.IsNullOrEmpty(fingerResult.FingersDelete)) { string[] fingerIds = fingerResult.FingersDelete.Split(','); foreach (var item in fingerIds) { Finger finger = userInfo.Fingers.Find(p => p.FingerID.Equals(item)); if (finger != null) { userInfo.Fingers.Remove(finger); } } userInfo.FingerNumber = userInfo.Fingers.Count; } }
/// <summary> /// 采集指纹保存 /// </summary> /// <param name="value"></param> /// <param name="msgType"></param> private void AnalyzeSaveFingerPrint(string value, MsgType msgType) { App.Current.Dispatcher.Invoke(new Action(() => { FingerResult fingerResult = XmlUnityConvert.XmlDeserialize <FingerResult>(value); ResultWindow resultWindow = CheckResultMsg(msgType); if (resultWindow == null) { return; } if (fingerResult.ResultCode == 0) { resultWindow.SuccessCloseWindow(); FingerViewModel.AddFingerPrintByUser(fingerResult); } else { resultWindow.FailedCloseWindow(fingerResult); } })); }
/// <summary> /// 点击确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, RoutedEventArgs e) { tbMsg.Text = string.Empty; if (FingerStatus == FingerStatus.RecordSuccess) { Conditions con = new Conditions(); con.AddItem("UserID", CurrentUser.UserID); con.AddItem("FingerName", btnEditor.Text); con.AddItem("FingerImage", FingerImage); // 发送配对消息 ResultWindow resultWindow = WindowsHelper.ShowDialogWindow <ResultWindow>(this, MsgType.FingerSaveRequest, MsgType.FingerSaveRespond, con, TryFindResource("FingerSaveData").ToString()); MessageBoxResult msgBoxResult = resultWindow.MessageBoxResult; if (msgBoxResult == MessageBoxResult.Cancel) { tbMsg.Text = TryFindResource("FingerSaveOverTime").ToString(); } else if (msgBoxResult == MessageBoxResult.Yes) { ModelResponsible.Instance.SendOperationLog("CollectFingerGather"); FingerStatus = FingerStatus.Finish; this.Close(); NewMessageBox.ShowTip(TryFindResource("FingerSaveSuccess").ToString(), ModelResponsible.Instance.ParentWindow); } else if (msgBoxResult == MessageBoxResult.No) { FingerResult fingerResult = resultWindow.ResultValue as FingerResult; tbMsg.Text = (TryFindResource("FingerCollectCode_" + fingerResult.ResultCode) ?? string.Empty).ToString(); } } else if (FingerStatus == FingerStatus.RecordFail) { SendStartCollectFinger(); FingerStatus = FingerStatus.Recording; } }
public async Task <FingerResult> WriteAsync(ParsedFingerCommand request) { var data = request.ToString(); var datanice = data.Replace("\r\n", ""); datanice = string.IsNullOrEmpty(datanice) ? "<blank string>" : datanice; var startTime = DateTime.UtcNow; try { var tcpSocket = new StreamSocket(); var connectTask = tcpSocket.ConnectAsync(request.SendToHost, request.SendToPort); var taskList = new Task[] { connectTask.AsTask(), Task.Delay(Options.MaxConnectTimeInMilliseconds) }; var waitResult = await Task.WhenAny(taskList); if (waitResult == taskList[1]) { Stats.NExceptions++; // mark it as an exception -- it would have failed if we didn't time out Log($"TIMEOUT while connecting to {request.SendToHost} {request.SendToPort}"); Log($"Unable to send command {datanice}\n"); var faildelta = DateTime.UtcNow.Subtract(startTime).TotalSeconds; return(FingerResult.MakeFailed(SocketErrorStatus.ConnectionTimedOut, faildelta)); } else { // Connect is OK if (!string.IsNullOrEmpty(data)) { var dw = new DataWriter(tcpSocket.OutputStream); dw.WriteString(data); await dw.StoreAsync(); Log(ClientOptions.Verbosity.Normal, $"Finger sending command {datanice}\n"); } Stats.NWrites++; // Now read everything var s = tcpSocket.InputStream; var buffer = new Windows.Storage.Streams.Buffer(1024 * 64); // read in lots of the data string stringresult = ""; var keepGoing = true; while (keepGoing) { try { var read = s.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial); /* This is the syntax that the editor will suggest. There's a * much simpler syntax (below) that's syntactic sugar over this. * read.Progress = new AsyncOperationProgressHandler<IBuffer, uint>( * (operation, progress) => * { * var err = operation.ErrorCode == null ? "null" : operation.ErrorCode.ToString(); * Log(ClientOptions.Verbosity.Verbose, $"Daytime Progress count={progress} status={operation.Status} errorcode={err}"); * }); */ read.Progress = (operation, progress) => { var err = operation.ErrorCode == null ? "null" : operation.ErrorCode.ToString(); Log(ClientOptions.Verbosity.Verbose, $"Finger Progress count={progress} status={operation.Status} errorcode={err}"); }; var result = await read; if (result.Length != 0) { var options = BufferToString.ToStringOptions.ProcessCrLf | BufferToString.ToStringOptions.ProcessTab; var partialresult = BufferToString.ToString(result, options); stringresult += partialresult; Log($"{partialresult}"); // This will be printed on the user's screen. } else { keepGoing = false; Log(ClientOptions.Verbosity.Verbose, $"Read completed with zero bytes; closing"); } } catch (Exception ex2) { keepGoing = false; Stats.NExceptions++; Log($"EXCEPTION while reading: {ex2.Message} {ex2.HResult:X}"); var faildelta = DateTime.UtcNow.Subtract(startTime).TotalSeconds; return(FingerResult.MakeFailed(ex2, faildelta)); } } var delta = DateTime.UtcNow.Subtract(startTime).TotalSeconds; return(FingerResult.MakeSucceeded(stringresult, delta)); } } catch (Exception ex) { Stats.NExceptions++; Log($"ERROR: Client: Writing {datanice} to {request.SendToHost} exception {ex.Message}"); var delta = DateTime.UtcNow.Subtract(startTime).TotalSeconds; return(FingerResult.MakeFailed(ex, delta)); } }