Esempio n. 1
0
        private void AddDeviceHierarchal(Graph graph, BaseDevice device, out string deviceKey, out string anotherCenter, string restrictCenterKey = null)
        {
            anotherCenter = null;
            if (device is Device)
            {
                deviceKey = "Device_" + device.Id;
            }
            else if (device is Passive)
            {
                deviceKey = "Passive_" + device.Id;
            }
            else
            {
                throw new NotImplementedException();
            }

            if (graph.ContainsNodeKey(deviceKey))
            {
                return;
            }

            var rackKey = "Rack_" + device.Place;

            graph.AddNode(new GraphNode {
                key = deviceKey, text = device.ToString(), group = rackKey
            });
            if (graph.ContainsNodeKey(rackKey))
            {
                return;
            }

            var rack    = db.FindById <Rack>(device.Place);
            var roomKey = "Room_" + rack.Parent;

            graph.AddNode(new GraphNode {
                key = rackKey, text = rack.ToString(), group = roomKey, isGroup = true
            });
            if (graph.ContainsNodeKey(roomKey))
            {
                return;
            }

            var room        = db.FindById <Room>(rack.Parent);
            var buildingKey = "Building_" + room.Parent;

            graph.AddNode(new GraphNode {
                key = roomKey, text = "سالن " + room.Name, group = buildingKey, isGroup = true
            });
            if (graph.ContainsNodeKey(buildingKey))
            {
                return;
            }

            var building  = db.FindById <Building>(room.Parent);
            var centerKey = "Center_" + building.Parent;
            var center    = db.FindById <CommCenter>(building.Parent);

            graph.AddNode(new GraphNode {
                key = centerKey, text = "مرکز " + center.Name, isGroup = true
            });
            if (restrictCenterKey != null && centerKey != restrictCenterKey)
            {
                anotherCenter = centerKey;
                graph.RemoveNode(roomKey);
                graph.RemoveNode(rackKey);
                graph.RemoveNode(deviceKey);
                return;
            }

            graph.AddNode(new GraphNode {
                key = buildingKey, text = "ساختمان " + building.Name, group = centerKey, isGroup = true
            });
        }