Example #1
0
        public static Matrix GenerateMap(DeviceGroup[] deviceGroups, Device[] devices)
        {
            Node rootNode = new Node("Default", "", "Red");

            DeviceGroup[] orderedDeviceGroups = deviceGroups.OrderBy(g => g.Level).ToArray();

            List<Node> nodes = new List<Node>();
            nodes.Add(rootNode);

            foreach (DeviceGroup deviceGroup in orderedDeviceGroups)
            {
                AddGroup(rootNode, deviceGroup, nodes, devices);
            }

            Matrix matrix = RoomGenerator.Generate(rootNode);

            matrix.Tiles[matrix.Tiles.Count/2][3].Add(new Tile(TileType.Player));

            //Closing the front door
            foreach (var tiles in matrix.Tiles)
            {
                if (tiles[0].Any(t => t.TileType == TileType.Door))
                {
                    tiles[0].RemoveAll(t => t.TileType == TileType.Door);
                    tiles[0].Add(new Tile(TileType.Wall));
                }
            }

            return matrix;
        }
        public Device[] GetDevices()
        {
            List<Device> devices = new List<Device>();

            TextAsset devicesResponse = Resources.Load("GetDevicesResponse") as TextAsset;

            var root = JSON.Parse(devicesResponse.text);

            foreach (var deviceNode in root.Childs)
            {
                Device device = new Device
                {
                    Name = deviceNode["DeviceName"].Value,
                    Path = deviceNode["Path"].Value,
                    DeviceId = deviceNode["DeviceId"].Value,
                    MacAddress = deviceNode["MACAddress"].Value,
                    Manufacturer = deviceNode["Manufacturer"].Value,
                    Model = deviceNode["Model"].Value,
                    BatteryStatus = deviceNode["BatteryStatus"].Value,
                    AgentVersion = deviceNode["AgentVersion"].Value
                };

                devices.Add(device);
            }

            return devices.ToArray();
        }
Example #3
0
        private static void AddGroup(Node topNode, DeviceGroup deviceGroup, List<Node> processedNodes, Device[] devices)
        {
            string[] paths = deviceGroup.Path.Split(new[] {@"\", @"\\"}, StringSplitOptions.RemoveEmptyEntries);

            Node groupNode = null;

            if (paths.Length == 1)
            {
                groupNode = new Node(topNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

                groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
                {
                    DeviceId = d.DeviceId
                }));

                topNode.Nodes.Add(groupNode);
                processedNodes.Add(groupNode);

                return;
            }

            int indexOfName = deviceGroup.Path.LastIndexOf(@"\", StringComparison.Ordinal);

            string parentPath = deviceGroup.Path.Remove(indexOfName);

            Node parentNode = processedNodes.Single(n => n.Path == parentPath);

            groupNode = new Node(parentNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

            groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
            {
                DeviceId = d.DeviceId
            }));

            parentNode.Nodes.Add(groupNode);
            processedNodes.Add(groupNode);
        }
        public Device[] GetDevices()
        {
            string accessToken = Login();

            List<Device> devices = new List<Device>();

            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("Authorization", "Bearer " + accessToken);
            headers.Add("Accept", "application/json");

            WWW www = new WWW(_url + Devices, null, headers);

            while (!www.isDone)
            { }

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("Error during retrieving devices. " + www.error);
            }

            var root = JSON.Parse(www.text);

            foreach (var deviceNode in root.Childs)
            {
                Device deviceGroup = new Device
                {
                    Name = deviceNode["DeviceName"].Value,
                    Path = deviceNode["Path"].Value,
                    DeviceId = deviceNode["DeviceId"].Value,
                    MacAddress = deviceNode["MACAddress"].Value,
                    Manufacturer = deviceNode["Manufacturer"].Value,
                    Model = deviceNode["Model"].Value,
                    BatteryStatus = deviceNode["BatteryStatus"].Value,
                    AgentVersion = deviceNode["AgentVersion"].Value
                };

                devices.Add(deviceGroup);
            }

            return devices.ToArray();
        }