public string addDeviceCoord(string devId, Ball ball)
        {
            List <Device> devices = readDevices();

            if (devices == null || devices.Count == 0)
            {
                return(Properties.Resources.SpecifiedDeviceNotFound);
            }

            foreach (Device dev in devices)
            {
                if (dev.Id == devId)
                {
                    dev.Form.Add(ball);
                    writeDevicesToFile(devices);
                    return(Properties.Resources.CoordinatesAdded);
                }
                else if (RepositoryRepresentation.isRepo(dev))
                {
                    foreach (Device repoDev in ((RepositoryRepresentation)dev).getDevices())
                    {
                    }
                }
            }



            return(Properties.Resources.NoCoordAdded);
        }
Example #2
0
        public Device getDeviceByID(String id)
        {
            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 = repo.deviceHolder.getDeviceByID(id);

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

            return(null);
        }
Example #3
0
        public List <RepositoryRepresentation> getAllRepos()
        {
            List <RepositoryRepresentation> repos = new List <RepositoryRepresentation>();

            foreach (Device dev in devices)
            {
                if (RepositoryRepresentation.isRepo(dev))
                {
                    repos.Add((RepositoryRepresentation)dev);
                }
            }

            return(repos);
        }
        public static String MakeDeviceString(IEnumerable <Device> devices)
        {
            List <leanDevRepresentation> d = new List <leanDevRepresentation>();

            if (devices != null)
            {
                List <Device> deviceList = devices.Where(dev => RepositoryRepresentation.isRepo(dev) == false).ToList();

                deviceList.ForEach(x => d.Add(new leanDevRepresentation(x)));
            }

            String result = JsonConvert.SerializeObject(d, Formatting.Indented);

            return(result);
        }
Example #5
0
        public List <Device> getCompleteDeviceList()
        {
            List <Device> returnList = new List <Device>();

            foreach (Device dev in devices)
            {
                if (RepositoryRepresentation.isRepo(dev))
                {
                    ((RepositoryRepresentation)dev).getDevices().ForEach(x => returnList.Add(x));
                }
                else
                {
                    returnList.Add(dev);
                }
            }

            return(returnList);
        }
Example #6
0
        public String addDeviceCoordinates(String devId, String radius, Point3D position)
        {
            Ball   coord = new Ball(position, double.Parse(radius));
            Device dev   = getDeviceByID(devId);

            dev.Form.Add(coord);

            if (dev.hasParent())
            {
                Device parent = getDeviceByID(dev.parentID);
                if (RepositoryRepresentation.isRepo(parent))
                {
                    return(storageFileHandler.updateDevice(parent));
                }
            }


            return(storageFileHandler.addDeviceCoord(devId, coord));
        }
Example #7
0
        public string AddDevice(string type, string id, string name, string path, string repoID)
        {
            if (checkForSameDevID(id))
            {
                return(Properties.Resources.SameDevIDEx);
            }

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

            Device repoDevice = getDeviceByID(repoID);



            if (repoDevice == null || !RepositoryRepresentation.isRepo(repoDevice))
            {
                return("RepoDevice not found"); //TODO: Create good response and localize ist
            }

            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);
            ((RepositoryRepresentation)repoDevice).getDevices().Add(newDevice);
            storageFileHandler.updateDevice(repoDevice);
            return(newDevice.Id);
        }
        public string changeDeviceCoord(string devId, Ball ball)
        {
            List <Device> devices = readDevices();

            if (devices == null || devices.Count == 0 || devices.Exists(d => d.Id == devId))
            {
                return(Properties.Resources.SpecifiedDeviceNotFound);
            }

            foreach (Device dev in devices)
            {
                if (dev.Id == devId)
                {
                    dev.Form.Clear();
                    dev.Form.Add(ball);
                    writeDevicesToFile(devices);
                    return(Properties.Resources.CoordinatesAdded);
                }

                if (RepositoryRepresentation.isRepo(dev))
                {
                    List <Device> tmpList  = ((RepositoryRepresentation)dev).getDevices();
                    int           tmpIndex = -1;

                    tmpIndex = tmpList.FindIndex(d => d.Id == devId);

                    if (tmpIndex != -1)
                    {
                        tmpList[tmpIndex].Form.Clear();
                        tmpList[tmpIndex].Form.Add(ball);
                        updateDevice(dev);
                        return(Properties.Resources.CoordinatesAdded);
                    }
                }
            }
            return(Properties.Resources.NoCoordAdded);
        }
        public string updateDevice(Device dev)
        {
            List <Device> devices = readDevices();

            if (devices == null || devices.Count == 0)
            {
                return(Properties.Resources.SpecifiedDeviceNotFound);
            }
            ;
            int mainIndex = -1;
            int subIndex  = -1;

            mainIndex = devices.FindIndex(d => d.Id == dev.Id);

            if (mainIndex != -1)
            {
                devices[mainIndex] = dev;
            }
            else
            {
                foreach (Device searchDev in devices)
                {
                    if (RepositoryRepresentation.isRepo(searchDev))
                    {
                        mainIndex = devices.IndexOf(searchDev);
                        subIndex  = ((RepositoryRepresentation)searchDev).getDevices().FindIndex(d => d.Id == dev.Id);

                        if (subIndex != -1)
                        {
                            ((RepositoryRepresentation)devices[mainIndex]).getDevices()[subIndex] = dev;
                        }
                    }
                }
            }
            writeDevicesToFile(devices);
            return("");
        }