Пример #1
0
        public NormaStatus GetDeviceStatus(string deviceId)
        {
            bool        found = false;
            NormaStatus stat  = GetDeviceStatusAll();

            if (stat != null && stat.Instances != null && stat.Instances.ReaderStatus != null && stat.Instances.ReaderStatus.Count > 0)
            {
                for (int i = stat.Instances.ReaderStatus.Count; i >= 0; i--)
                {
                    if (stat.Instances.ReaderStatus[i].InstanceName != deviceId)
                    {
                        stat.Instances.ReaderStatus.RemoveAt(i);
                    }
                    else
                    {
                        found = true;
                    }
                }
            }
            if (found)
            {
                return(stat);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public NormaStatus GetDeviceStatusAll()
        {
            string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            if (!File.Exists(path + "/NormaStatus.log"))
            {
                Console.WriteLine("NormaStatus does not exist");
                return(null);
            }

            string      content = File.ReadAllText(path + "/NormaStatus.log");
            NormaStatus ret     = JsonConvert.DeserializeObject <NormaStatus>(content);
            bool        found   = false;

            if (ret != null && ret.Instances.ReaderStatus != null && ret.Instances.ReaderStatus.Count > 0)
            {
                List <Device> configureDevices = GetDevices();
                for (int i = ret.Instances.ReaderStatus.Count - 1; i >= 0; i--)
                {
                    found = false;
                    foreach (Device dev in configureDevices)
                    {
                        Console.WriteLine("GetDeviceStatusAll " + dev.Reader.ReaderAddress + " " + ret.Instances.ReaderStatus[i].InstanceName);
                        if (ret.Instances.ReaderStatus[i].InstanceName.StartsWith(dev.Reader.ReaderAddress))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ret.Instances.ReaderStatus.RemoveAt(i);
                    }
                }
            }

            return(ret);
        }