Пример #1
0
        private void RefreshOnlineInfo(Machines machine)
        {
            const string ONLINE_FACTRORY_ROOM = "ONLINEFACTORYROOM", PRE_ROOM_NAME_NUMBER = "PREROOMNAMENUMBER", PRE_ONLINE_MACHINE = "PREONLINEMACHINE",
                         PRE_MACHINE_NAME_NUMBER = "PREMACHINENAMENUMBER", PRE_ONLINE_TIME = "PREONLINETIME";

            using (ServiceStack.Redis.IRedisClient client = GlobalVariable.RedisClient)
            {
                HashSet <string> roomList = client.GetAllItemsFromSet(ONLINE_FACTRORY_ROOM);
                if (!roomList.Contains(machine.RoomNumber))
                {
                    client.AddItemToSet(ONLINE_FACTRORY_ROOM, machine.RoomNumber);
                    client.Set <string>(PRE_ROOM_NAME_NUMBER + machine.RoomNumber, machine.RoomName);
                }
                string           strMachineValue = PRE_ONLINE_MACHINE + machine.RoomNumber;
                HashSet <string> machineList     = client.GetAllItemsFromSet(strMachineValue);
                if (!machineList.Contains(machine.Number))
                {
                    client.AddItemToSet(strMachineValue, machine.Number);
                    client.Set <string>(PRE_MACHINE_NAME_NUMBER + machine.Number, machine.Name);
                }
                client.Set <long>(PRE_ONLINE_TIME + machine.Number, DateTime.Now.Ticks);
            }
        }
Пример #2
0
        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);
        }