/// <summary> /// 处理巡更控制器的自动上报数据 /// </summary> /// <param name="remoteIP"></param> /// <param name="address"></param> /// <param name="innerDatas"></param> /// <returns></returns> public XGData ProcessXGARD(string remoteIP, int address, byte[] innerDatas) { Record r = Record.Analyze(innerDatas); //return new XGData( r.CardSN, address, r.DateTime, true ); if (r != null) { XGData xgData = new XGData(r.CardSN, address, r.DateTime, true); // TODO: save xg ard and Match XgTask with the xgdata // // insert ard xg data to db // XGDB.InsertXGData(remoteIP, xgData); // insert a new task to taskScheduler, the task remove the last ard xgdata // XGStation xgst = Singles.S.GetXGStation(remoteIP, address); if (xgst == null) { xgst = new XGStation("xgst" + DateTime.Now, remoteIP, address); } CommCmdBase cmd = new AutoReportCommand(xgst); Task task = new Task(cmd, new ImmediateTaskStrategy()); Singles.S.TaskScheduler.Tasks.Add(task); return(xgData); } return(null); }
// static public void InsertXGData( XGData data ) // { // //2007.03.11 replace with InsertXGData ( string remoteIP, XGData data ) // throw new NotImplementedException ( "insertXGData( XGData data" ); // // ArgumentChecker.CheckNotNull( data ); // string s = string.Format( @"insert into tbl_xgdata(station_address, card_sn, station_time, // computer_time, isAuto) // values({0}, '{1}', '{2}', '{3}', {4})", data.FromAddress, data.CardSN, data.XGStationDateTime, // data.DateTime, data.IsAutoReport ? 1 : 0 ); // // DbClient.ExecuteNonQuery( s ); // } /// <summary> /// insert a xg data to tbl_xgdata /// </summary> /// <param name="remoteIP"> form gprs station ip</param> /// <param name="data"> xg data </param> static public void InsertXGData(string remoteIP, XGData data) { ArgumentChecker.CheckNotNull(data); // find xgstation_id with remoteIP, id not find xgstation_id then return // int xgStId = XGDB.GetXGStaionID(remoteIP, data.FromAddress); // 2007-10-25 Added not find xgStId // if (xgStId == 0) { return; } // find card_id and person with card sn, if not find // card sn then the sn to tbl_card and return the id // int cardId; string person; bool b = XGDB.GetCardIdAndPerson(data.CardSN, true, out cardId, out person); if (b) { // insert xgdata to tbl_xgdata // string sql = string.Format(@"insert into tbl_xgdata ( xgstation_id, card_id, xgtime, person ) values ( {0}, {1}, '{2}', '{3}')", xgStId, cardId, data.XGStationDateTime, person); DbClient.ExecuteNonQuery(sql); } }
//public int MatchRecord( XGAutoReportData record ) public int MatchRecord(XGData data) { ArgumentChecker.CheckNotNull(data); if (_tasks == null) { return(0); } int matchedCount = 0; for (int i = 0; i < _tasks.Count; i++) { XGTask task = _tasks[i]; if (task.IsActive && !task.IsComplete && task.MatchXGData(data)) { //task.XgTaskResult = XGTaskResult.CreateSuccessResult( task, record.DateTime ); task.XgTaskResult = data; task.IsComplete = true; matchedCount++; } } return(matchedCount); }
public bool MatchXGData(XGData data) { ArgumentChecker.CheckNotNull(data); return(!IsComplete && (_card.SerialNumber == data.CardSN) && (_xgStation.Address == data.FromAddress) && (MatchXgTime(data.XGStationDateTime))); }
/// <summary> /// reutrn xgdata or null /// </summary> /// <returns></returns> public override object ToValue() { byte[] data = _bytes; CommResultState state = XGCommandMaker.CheckReceivedData(// this.Station.Address, XGDefinition.DEVICE_TYPE, XGDefinition.FC_READ_RECORD, data); _commResultState = state; // 正确时处理记录数据,错误时保留上次读取的数据不变。 // if (state == CommResultState.Correct) { int address = data[XGDefinition.ADDRESS_POS]; byte[] innerDatas = XGCommandMaker.GetReceivedInnerData(data); int innerDataLen = innerDatas.Length; // if (innerDataLen == XGDefinition.RECODE_DATA_LENGTH) { // analyse recode data // Record record = Record.Analyze(innerDatas); if (record == null) { return(null); } XGData xgdata = new XGData(record.CardSN, address, record.DateTime, false); _value = xgdata; return(xgdata); } else if (innerDataLen == 1) // recode index error { //_recordTotalCount = innerDatas[0]; return(null); } else { //throw new Exception("Read recode inner data error."); return(null); } } else { return(null); } }
/// <summary> /// /// </summary> /// <param name="fromIP"></param> /// <param name="bs"></param> public void Process(string fromIP, byte[] bs) { GrDataPicker grdp = new GrDataPicker(); byte[][] grdatas = grdp.Picker(bs); if (grdatas != null) { foreach (byte[] aGrData in grdatas) { if (GRCommandMaker.IsRealData(aGrData)) { GrRealDataParser grrdparser = new GrRealDataParser(aGrData); GRRealData rd = grrdparser.ToValue() as GRRealData; if (rd != null) { CommTaskResultProcessor.Default.ProcessGRRealData( fromIP, rd.FromAddress, rd ); } } } } XgDataPicker xgdp = new XgDataPicker(); byte[][] xgdatas = xgdp.Picker(bs); if (xgdatas != null) { foreach (byte[] aXgData in xgdatas) { if (XGCommandMaker.IsXgRecord(aXgData)) { XgRecordParser xgrp = new XgRecordParser(aXgData); XGData xgdata = xgrp.ToValue() as XGData; if (xgdata != null) { XGDB.InsertXGData( fromIP, //cmd.Station.DestinationIP, xgdata ); } } } } }
/// <summary> /// /// </summary> /// <param name="cmd"></param> private void ProcessReadRecordCmd(ReadRecordCommand cmd) { XGData xgData = cmd.XGData; if (xgData != null) { // XGDB.InsertXGData ( cmd.XGData ); // XGTask[] matchedXgTasks = Singles.S.XGScheduler.Tasks.MatchXGData( cmd.XGData ); // foreach ( XGTask t in matchedXgTasks ) // { // t.IsComplete = true; // ?TODO: save complete task to db // XGDB.InsertXGData(cmd.Station.DestinationIP, xgData); } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> public XGTask[] MatchXGData(XGData data) { System.Collections.ArrayList list = new System.Collections.ArrayList(); if (data == null) { return(null); } for (int i = 0; i < Count; i++) { XGTask task = this[i]; if (task.MatchXGData(data)) { task.XgTaskResult = data; task.IsComplete = true; list.Add(task); } } return((XGTask[])list.ToArray(typeof(XGTask))); }
public int Add(XGData xgData) { return(base.InternalAdd(xgData)); }
/// <summary> /// /// </summary> public void Reset() { _isComplete = false; _isWatingLocalXgData = false; _xgTaskResult = null; }