Exemplo n.º 1
0
        private ThingsOfFoi LoadDevices(Configuration configuration)
        {
            ThingsOfFoi thingsOfFoi = new ThingsOfFoi();

            List <Dictionary <string, string> > sensorsList   = Csv.Parse(configuration.SensorsFilePath);
            List <Dictionary <string, string> > actuatorsList = Csv.Parse(configuration.ActuatorsFilePath);

            DeviceCreator deviceCreator = new DeviceCreator();

            foreach (var row in sensorsList)
            {
                Sensor sensor = (Sensor)deviceCreator.CreateDevice(row, DeviceType.Sensor, thingsOfFoi);
                if (sensor.IsDeviceValid())
                {
                    if (!thingsOfFoi.Sensors.Exists(s => s.ModelIdentifier == sensor.ModelIdentifier))
                    {
                        thingsOfFoi.AddSensor(sensor);
                    }
                    else
                    {
                        Data.Add("Model senzora sa ID-jem: '" + sensor.UniqueIdentifier + " (" + sensor.Name + ") " + "' vec postoji. Preskacem!");
                    }
                }
                else
                {
                    Data.Add("Unos za uredaj: '" + sensor.Name + "' nije dobar. Preskacem!");
                }
            }

            if (sensorsList.Count == 0 || thingsOfFoi.Sensors.Count == 0)
            {
                Data.Add("Nije ucitan nijedan senzor. Program ne moze nastaviti!");
                return(null);
            }

            foreach (var row in actuatorsList)
            {
                Actuator actuator = (Actuator)deviceCreator.CreateDevice(row, DeviceType.Actuator, thingsOfFoi);
                if (actuator.IsDeviceValid())
                {
                    if (!thingsOfFoi.Actuators.Exists(a => a.ModelIdentifier == actuator.ModelIdentifier))
                    {
                        thingsOfFoi.AddActuator(actuator);
                    }
                    else
                    {
                        Data.Add("Aktuator sa ID-jem: " + actuator.UniqueIdentifier + " (" + actuator.Name + ") " + " vec postoji. Preskacem!");
                    }
                }
                else
                {
                    Data.Add("Unos za uredaj: '" + actuator.Name + "' nije dobar. Preskacem!");
                }
            }

            if (actuatorsList.Count == 0 || thingsOfFoi.Actuators.Count == 0)
            {
                Data.Add("Nije ucitan nijedan aktuator. Program ne moze nastaviti!");
                return(null);
            }

            return(thingsOfFoi);
        }