public VehicleRecogResult GetVehicleByPic(string imageFileName) { VehicleRecogResult vehicleResults = new VehicleRecogResult(); using (var requester = new ZSocket(context, ZSocketType.REQ)) { requester.Connect("tcp://127.0.0.1:50559"); string imagepath = imageFileName; if (File.Exists(imagepath)) { Guid guid = Guid.NewGuid(); DataTypes.VehicleInfo info = new DataTypes.VehicleInfo(); info.Id = "11111"; info.Imagepath = (imagepath); info.Uuid = guid.ToString().Replace("-", ""); ZMessage zMsg = new ZMessage(); zMsg.Add(new ZFrame(info.ToByteArray())); requester.Send(zMsg); using (ZFrame reply = requester.ReceiveFrame()) { DataTypes.VehicleInfo msg2 = new DataTypes.VehicleInfo(); msg2.MergeFrom(reply.Read()); vehicleResults = JsonConvert.DeserializeObject <VehicleRecogResult>(msg2.Jsonresult); //Console.WriteLine(" Received: {0}!", msg2.Jsonresult); } } } return(vehicleResults); }
private void ReceiveMsg(Object threadContext) { ZError errors; int threadIndex = (int)threadContext; Console.WriteLine("thread {0} ZmqFaceSink Start Receive Message !", threadIndex); while (receiving) { using (ZFrame frame = receiverSocketList[threadIndex].ReceiveFrame(ZSocketFlags.DontWait, out errors)) { if (null != frame) { // Process task string str = System.Text.Encoding.UTF8.GetString(frame.Read()); List <string> mFileNameList = JsonConvert.DeserializeObject <List <string> >(str); LogHelper.WriteLog(typeof(ZmqVehicleSink), "recv count " + mFileNameList.Count); List <VehicleObject> mVehObjectList = new List <VehicleObject>(); foreach (var fileName in mFileNameList) { using (var requester = new ZSocket(context, ZSocketType.REQ)) { requester.Connect("tcp://127.0.0.1:50559"); string imagepath = fileName; if (File.Exists(imagepath)) { Guid guid = Guid.NewGuid(); DataTypes.VehicleInfo info = new DataTypes.VehicleInfo(); info.Id = "11111"; info.Imagepath = (imagepath); info.Uuid = guid.ToString().Replace("-", ""); ZMessage zMsg = new ZMessage(); zMsg.Add(new ZFrame(info.ToByteArray())); requester.Send(zMsg); using (ZFrame reply = requester.ReceiveFrame()) { DataTypes.VehicleInfo msg2 = new DataTypes.VehicleInfo(); msg2.MergeFrom(reply.Read()); VehicleRecogResult vehicleResults = JsonConvert.DeserializeObject <VehicleRecogResult>(msg2.Jsonresult); if (null != vehicleResults.Veh) { foreach (var item in vehicleResults.Veh) { VehicleObject vehicleObj = new VehicleObject(); string FileName = fileName; vehicleObj.ImagePath = FileName; vehicleObj.TaskId = ""; vehicleObj.CreateTime = new BsonDateTime(DateTime.Now); vehicleObj.vehicle = item; mVehObjectList.Add(vehicleObj); } //Console.WriteLine(" Received: {0}!", msg2.Jsonresult); } } } } } if (mVehObjectList.Count > 0) { VehicleMongoDAL.GetInstance().AddVehicleObject(mVehObjectList); } Console.WriteLine("thread {0} receive count:{1}", threadIndex, mFileNameList.Count); } else { if (errors == ZError.ETERM) { return; // Interrupted } if (errors != ZError.EAGAIN) { throw new ZException(errors); } } } Thread.Sleep(10); } Console.WriteLine("thread {0} ZmqVehicleSink End Receive Message !", threadIndex); }