コード例 #1
0
        private void RandomDeviceType()
        {
            Random rand           = new Random();
            int    typeRandomized = rand.Next(0, 10); //Depend of number of type of device

            switch (typeRandomized)
            {
            case 0:
                Device_Type = TypeOfDevice.Presence;
                PresenceData();
                break;

            case 1:
                Device_Type = TypeOfDevice.Temperature;
                TemperatureData();
                break;

            case 2:
                Device_Type = TypeOfDevice.Light;
                LightData();
                break;

            case 3:
                Device_Type = TypeOfDevice.AtmosphericPressure;
                AtmosphericPressureData();
                break;

            case 4:
                Device_Type = TypeOfDevice.Humidity;
                HumidityData();
                break;

            case 5:
                Device_Type = TypeOfDevice.SoundLevel;
                SoundLevelData();
                break;

            case 6:
                Device_Type = TypeOfDevice.GPS;
                GPSData();
                break;

            case 7:
                Device_Type = TypeOfDevice.CO2;
                CO2Data();
                break;

            case 8:
                Device_Type  = TypeOfDevice.LED;
                GenerateData = (object obj) => { };
                break;

            case 9:
                Device_Type  = TypeOfDevice.Beeper;
                GenerateData = (object obj) => { };
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Find type of device by an article number. Be careful!! this method is slow because it opens the xml file!
        /// </summary>
        /// <param name="articleNumber">Article number</param>
        /// <returns>Type of device.</returns>
        public TypeOfDevice CurentDevice(int articleNumber)
        {
            TypeOfDevice currentDevice = TypeOfDevice.Unknow;

            try
            {
                XDocument devices = XDocument.Load(_stream);
                var       query   = from top in devices.Descendants("Device")
                                    from art in top.Elements("Article")
                                    select new
                {
                    Name    = top.Attribute("name").Value.ToString(),
                    Article = int.Parse(art.Value)
                };

                string deviceName = query.Single(x => x.Article == articleNumber).Name;
                switch (deviceName)
                {
                case "Doprimo":
                    currentDevice = TypeOfDevice.Doprimo;
                    break;

                case "Water":
                    currentDevice = TypeOfDevice.Water;
                    break;

                case "Pulsonic":
                    currentDevice = TypeOfDevice.Pulsonic;
                    break;

                case "Optosonic":
                    currentDevice = TypeOfDevice.Optosonic;
                    break;

                case "PowerSonic":
                    currentDevice = TypeOfDevice.PowerSonic;
                    break;

                case "Repeater":
                    currentDevice = TypeOfDevice.Repeater;
                    break;

                default:
                    currentDevice = TypeOfDevice.Unknow;
                    break;
                }
            }
            catch (Exception ex)
            {
            }

            return(currentDevice);
        }
コード例 #3
0
        /// <summary>
        /// Create a dictionnary with the article number and the type of device.
        /// </summary>
        /// <returns>Dictionnary with the type of device.</returns>
        public /*static*/ Dictionary <int, TypeOfDevice> DeviceDictionnay()
        {
            Dictionary <int, TypeOfDevice> deviceDectionnary = new Dictionary <int, TypeOfDevice>();
            TypeOfDevice currentDevice = TypeOfDevice.Unknow;

            XDocument devices = XDocument.Load(_stream);
            var       query   = from top in devices.Descendants("Device")
                                from art in top.Elements("Article")
                                select new
            {
                Name    = top.Attribute("name").Value.ToString(),
                Article = int.Parse(art.Value)
            };

            foreach (var item in query)
            {
                switch (item.Name)
                {
                case "Doprimo":
                    currentDevice = TypeOfDevice.Doprimo;
                    break;

                case "Water":
                    currentDevice = TypeOfDevice.Water;
                    break;

                case "Pulsonic":
                    currentDevice = TypeOfDevice.Pulsonic;
                    break;

                case "Optosonic":
                    currentDevice = TypeOfDevice.Optosonic;
                    break;

                case "PowerSonic":
                    currentDevice = TypeOfDevice.PowerSonic;
                    break;

                case "Repeater":
                    currentDevice = TypeOfDevice.Repeater;
                    break;

                default:
                    currentDevice = TypeOfDevice.Unknow;
                    break;
                }
                deviceDectionnary.Add(item.Article, currentDevice);
            }
            return(deviceDectionnary);
        }