public VersaCell() { try { _clsHRecord = new VersaCellHeaderRecord(); _clsPRecord = new VersaCellPatientRecord(); _clsORecord = new VersaCellOrderRecord(); _clsQRecord = new VersaCellQueryRecord(); _clsRRecord = new VersaCellResultRecord(); _clsTRecord = new VersaCellTerminationRecord(); PrvRequestArray = new Queue <List <string> >(); objService = new ExternalDataExchangeService(); InstanceId = Guid.NewGuid(); objWorkFlowRuntime.AddService(objService); objASTM = new clsASTM(); objService.AddService(objASTM); objASTM.SendACKEvent += objASTM_SendACKEvent; objASTM.SendNAKEvent += objASTM_SendNAKEvent; objASTM.SendENQEvent += objASTM_SendENQEvent; objASTM.SendEOTEvent += objASTM_SendEOTEvent; objWorkFlowInstance = objWorkFlowRuntime.CreateWorkflow(typeof(ASTMWorkflow), null, InstanceId); objWorkFlowInstance.Start(); Console.WriteLine(@"Work flow started"); objDataEventArgs = new ExternalDataEventArgs(InstanceId); objDataEventArgs.WaitForIdle = true; DumpStateMachine(objWorkFlowRuntime, InstanceId); } catch (Exception ex) { Log.FatalException("Fatal Error: ", ex); } }
/// <summary> /// Xử lý sau kkhi nhận được dữ liệu /// </summary> public override void ProcessRawData() { try { var arrRecords = new string[] {}; var listRecords = new ArrayList(); var listFields = new ArrayList(); if (BufferData != string.Empty) { arrRecords = BufferData.Split(new[] { _clsRRecord.RecordDelimiter }, StringSplitOptions.RemoveEmptyEntries); } int i = 0; while (i < arrRecords.Length) { string[] arrFields = arrRecords[i].Split(_clsPRecord.FieldDelimiter); if (arrFields[0].Equals(_clsPRecord.RecordType)) { listFields.Clear(); listFields.Add(arrFields); listRecords.Add(listFields); do { if (++i > arrRecords.Length - 1) { break; } arrFields = arrRecords[i].Split(_clsPRecord.FieldDelimiter); if (arrFields[0].Equals(_clsORecord.RecordType) || arrFields[0].Equals(_clsRRecord.RecordType)) { listFields.Add(arrFields); } } while (!arrFields[0].Equals(_clsPRecord.RecordType)); foreach (ArrayList l in listRecords) { foreach (string[] fields in l) { if (fields[0].StartsWith(_clsPRecord.RecordType)) { _clsPRecord = new VersaCellPatientRecord(fields); } else if (fields[0].StartsWith(_clsORecord.RecordType)) { _clsORecord = new VersaCellOrderRecord(fields); TestResult.Barcode = _clsORecord.Barcode; } else if (fields[0].StartsWith(_clsRRecord.RecordType)) { _clsRRecord = new VersaCellResultRecord(fields); AddResult(new ResultItem(_clsRRecord.TestId, _clsRRecord.DataValue.PubFieldData)); TestResult.TestDate = _clsRRecord.TestDate; _newResult = true; } } } if (_newResult) { ImportResults(); _newResult = false; } } else if (arrFields[0].Equals(_clsQRecord.RecordType)) { _clsQRecord = new VersaCellQueryRecord(arrFields); _sQBarcode = _clsQRecord.QueryBarcode; _newQuery = true; List <string> regList = GetRegList(_clsQRecord.QueryBarcode); PrvRequestArray.Enqueue(CreateOrderFrame(regList)); ++i; } else { ++i; } } if (_newQuery) { //Send((int)EventID.OpenNewOutputSession, _sQBarcode); objASTM.CallGetQuery(objDataEventArgs); if ((PrvRequestArray != null) && (PrvRequestArray.Count != 0)) { currentOrder.Clear(); currentOrder = PrvRequestArray.Dequeue(); currentOrderIdx = 0; } //SendByte((byte)DeviceHelper.ENQ); _newQuery = false; } } catch (Exception ex) { Log.Error("Fatal Error:{0}", ex.ToString()); } }