public static enumErrorCode WaittingSendForResp(string strKey) { int intResp = 0; string strTempKey = PRE_RESP_DOWN_INFO + strKey; enumErrorCode sendResult; int i = 0, iMax = 50; for (; i < iMax; i++) { intResp = client.Get <int>(strTempKey); if (intResp == 0) { Thread.Sleep(100); continue; } else { break; } } if (intResp == 0) { sendResult = enumErrorCode.DeviceReciveTimeOut; } else { sendResult = (enumErrorCode)intResp; client.Remove(strTempKey); } return(sendResult); }
private enumErrorCode SendScheduleHandler(int machineId, byte[] buff, int userId, string infoType) { string strUserKey = string.Format("{0}-{1}", userId, DateTime.Now.ToString("yyyyMMddHHmmssFFF")); client.EnqueueItemOnList(PAGE_SEND_CONTENT, strUserKey); client.Set <int>(PRE_DOWN_INFO_MACHINE + strUserKey, machineId); client.Set(PRE_DOWN_INFO + strUserKey, buff); client.Set <string>(infoType + machineId.ToString(), strUserKey); enumErrorCode result = App_Start.TcpProtocolClient.WaittingSendForResp(strUserKey); client.Remove(PRE_DOWN_INFO_MACHINE + strUserKey); client.Remove(PRE_DOWN_INFO + strUserKey); client.Remove(infoType + machineId.ToString()); return(result); }
private List <DeviceStatus> RefreshMachineStatus(bool refresh = false) { List <DeviceStatus> deviceStatusList = new List <DeviceStatus>(); if (!refresh) {//数据自刷新 HashSet <string> roomList = client.GetAllItemsFromSet(ONLINE_FACTRORY_ROOM); foreach (string room in roomList) { FactoryRoom roomItem = db.FactoryRoom.FirstOrDefault(item => item.RoomNumber == room); DeviceStatus tempStatus = new DeviceStatus() { RoomName = client.Get <string>(PRE_ROOM_NAME_NUMBER + room), MachineList = new Dictionary <string, DateTime>() }; HashSet <string> machineList = client.GetAllItemsFromSet(PRE_ONLINE_MACHINE + room); foreach (string machine in machineList) { DateTime lastTime = new DateTime(client.Get <long>(PRE_ONLINE_TIME + machine)); if (CheckValidTime(lastTime)) { string strName = client.Get <string>(PRE_MACHINE_NAME_NUMBER + machine); tempStatus.MachineList.Add(strName ?? machine, lastTime); } else { client.Remove(PRE_ONLINE_TIME + machine); client.RemoveItemFromSet(PRE_ONLINE_MACHINE + room, machine); } } if (tempStatus.MachineList.Count < 1) { client.RemoveItemFromSet(ONLINE_FACTRORY_ROOM, room); } IEnumerable <Machines> roomMachines = from item in db.Machines where item.RoomID == roomItem.RoomID select item; List <string> freeMachineList = new List <string>(); foreach (Machines item in roomMachines) { if (!tempStatus.MachineList.Keys.Contains(item.Name) && !tempStatus.MachineList.Keys.Contains(item.Number)) { freeMachineList.Add(item.Name); } } tempStatus.OfflineMachines = freeMachineList.ToArray(); tempStatus.MachineCount = tempStatus.OfflineMachines.Count() + tempStatus.MachineList.Count; deviceStatusList.Add(tempStatus); } } else {//重新加载数据 foreach (FactoryRoom room in db.FactoryRoom) { DeviceStatus device = new DeviceStatus() { RoomID = room.RoomID, RoomName = room.RoomName, MachineCount = room.MachineCount, FactoryName = room.FactoryName, MachineList = new Dictionary <string, DateTime>() }; deviceStatusList.Add(device); } foreach (DeviceStatus device in GlobalVariable.deviceStatusList) { IEnumerable <LastHeartBreak> lastItemList = from tempMachine in db.LastHeartBreak where tempMachine.RoomID == device.RoomID select tempMachine; List <string> freeMachineList = new List <string>(); foreach (LastHeartBreak item in lastItemList) { if (CheckValidTime(item.DateRefresh)) { device.MachineList.Add(item.MachineName, item.DateRefresh); } else { freeMachineList.Add(item.MachineName); } } device.OfflineMachines = freeMachineList.ToArray(); } } return(deviceStatusList); }