Exemplo n.º 1
0
        public Device getDeviceByID(string id, List <Device> devices)
        {
            if (id == null || id == "")
            {
                return(null);
            }

            Device returnDev = null;

            foreach (Device dev in devices)
            {
                if (dev.Id == id)
                {
                    return(dev);
                }

                if (RepositoryRepresentation.isRepo(dev))
                {
                    RepositoryRepresentation repo = (RepositoryRepresentation)dev;

                    returnDev = getDeviceByID(id, repo.getDevices());

                    if (returnDev != null)
                    {
                        return(returnDev);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public string AddDevice(string type, string id, string name, string path, RepositoryRepresentation repoDevice)
        {
            if (checkForSameDevID(id))
            {
                return(Properties.Resources.SameDevIDEx);
            }

            if (name == null)
            {
                name = "";
            }

            if (repoDevice.hasParent())
            {
                return("Device cant be added to a childDevice"); //TODO: Create good Response and localize it
            }
            Device newDevice = deviceProducer.produceDevice(type, id, name, path, getCompleteDeviceList());

            if (newDevice == null)
            {
                return(Properties.Resources.UnknownError);
            }

            checkAndWriteColorForNewDevice(newDevice);
            newDevice.addParent(repoDevice);
            repoDevice.getDevices().Add(newDevice);
            return(newDevice.Id);
        }