public async Task <ActionResult> Index(string deviceId)
        {
            DeviceModel device = await _deviceLogic.GetDeviceAsync(deviceId);

            if (device.DeviceProperties == null)
            {
                throw new DeviceRequiredPropertyNotFoundException("'DeviceProperties' property is missing");
            }

            IList <SelectListItem> commandListItems = MethodListItems(device);

            bool deviceIsEnabled = device.DeviceProperties.GetHubEnabledState();

            DeviceCommandModel deviceCommandsModel = new DeviceCommandModel
            {
                CommandHistory   = device.CommandHistory.Where(c => c.DeliveryType == DeliveryType.Method).ToList(),
                CommandsJson     = JsonConvert.SerializeObject(device.Commands.Where(c => c.DeliveryType == DeliveryType.Method)),
                SendCommandModel = new SendCommandModel
                {
                    DeviceId              = device.DeviceProperties.DeviceID,
                    CommandSelectList     = commandListItems,
                    CanSendDeviceCommands = deviceIsEnabled && PermsChecker.HasPermission(Permission.SendCommandToDevices)
                },
                DeviceId = device.DeviceProperties.DeviceID
            };

            return(View(deviceCommandsModel));
        }
        public async Task <ActionResult> Index(string filterId)
        {
            ViewBag.FilterId                     = filterId;
            ViewBag.HasManageJobsPerm            = PermsChecker.HasPermission(Permission.ManageJobs);
            ViewBag.HasDeleteSuggestedClausePerm = PermsChecker.HasPermission(Permission.DeleteSuggestedClauses);
            ViewBag.IconBaseUrl                  = await _iconRepository.GetIconStorageUriPrefix();

            ViewBag.IconTagName = Constants.DeviceIconTagName;

            return(View());
        }
Exemple #3
0
        public async Task <ActionResult> Index(string deviceId)
        {
            DeviceModel device = await _deviceLogic.GetDeviceAsync(deviceId);

            if (device.DeviceProperties == null)
            {
                throw new DeviceRequiredPropertyNotFoundException("'DeviceProperties' property is missing");
            }

            IList <SelectListItem> commandListItems = CommandListItems(device);

            bool deviceIsEnabled = device.DeviceProperties.GetHubEnabledState();

            //MDS bae 2017.0615
            var appSettingsReader = new AppSettingsReader();
            var connectionString  = "----";
            CloudStorageAccount storageaccount = CloudStorageAccount.Parse(connectionString);

            blobClient    = storageaccount.CreateCloudBlobClient();
            blobContainer = blobClient.GetContainerReference(blobContainerName);
            await blobContainer.CreateIfNotExistsAsync();

            await blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

            CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(deviceId);

            foreach (IListBlobItem blob in blobDirectory.ListBlobs())
            {
                if (blob.GetType() == typeof(CloudBlockBlob))
                {
                    //string blobfilename = blob.Uri.Segments.Last();
                    //blobfilename = blobfilename.Remove(blobfilename.Length - 4);
                    //if (blobfilename == device.CommandHistory[device.CommandHistory.Count - 1].MessageId)
                    flirimageurl = blob.Uri.ToString();
                }
            }

            DeviceCommandModel deviceCommandsModel = new DeviceCommandModel
            {
                CommandHistory   = device.CommandHistory.Where(c => c.DeliveryType == DeliveryType.Message).ToList(),
                CommandsJson     = JsonConvert.SerializeObject(device.Commands.Where(c => c.DeliveryType == DeliveryType.Message)),
                SendCommandModel = new SendCommandModel
                {
                    DeviceId              = device.DeviceProperties.DeviceID,
                    CommandSelectList     = commandListItems,
                    CanSendDeviceCommands = deviceIsEnabled && PermsChecker.HasPermission(Permission.SendCommandToDevices)
                },
                ImageUrl = flirimageurl,    //MDS bae 2017.0615
                DeviceId = device.DeviceProperties.DeviceID,
            };

            return(View(deviceCommandsModel));
        }
        /// <summary>
        /// Gets the NavigationMenuItem that describe a controller's
        /// subnavigation items.
        /// </summary>
        /// <param name="controllerName">
        /// The name of the controller.
        /// </param>
        /// <returns>
        /// NavigationMenuItems that describe a controller's subnavigation items.
        /// </returns>
        public static List <NavigationMenuItem> GetSubnavigationItemsForController(
            string controllerName)
        {
            var listItems = new List <NavigationMenuItem>();

            if (controllerName == "Advanced")
            {
                listItems = GetAdvancedControllerSubmenuItems();
            }

            listItems = listItems.Where(
                t => (t != null) && PermsChecker.HasPermission(t.MinimumPermission)).ToList();

            return(listItems);
        }
Exemple #5
0
        public async Task <ActionResult> Index(string deviceId)
        {
            dynamic device = await _deviceLogic.GetDeviceAsync(deviceId);

            List <SelectListItem> commandListItems = CommandListItems(device);

            var deviceCommandsModel = new DeviceCommandModel
            {
                CommandHistory   = new List <dynamic>(CommandHistorySchemaHelper.GetCommandHistory(device)),
                CommandsJson     = JsonConvert.SerializeObject(device.Commands),
                SendCommandModel = new SendCommandModel
                {
                    DeviceId              = DeviceSchemaHelper.GetDeviceID(device),
                    CommandSelectList     = commandListItems,
                    CanSendDeviceCommands = DeviceSchemaHelper.GetHubEnabledState(device) == true &&
                                            PermsChecker.HasPermission(Permission.SendCommandToDevices)
                },
                DeviceId = DeviceSchemaHelper.GetDeviceID(device)
            };

            return(View(deviceCommandsModel));
        }
        public async Task <ActionResult> GetChildren(string jstreeNode)
        {
            // This delimiter is used to allow the storing of the OPC UA parent node ID together with the OPC UA child node ID in jstree data structures and provide it as parameter to
            // Ajax calls.
            string[] delimiter       = { "__$__" };
            string[] jstreeNodeSplit = jstreeNode.Split(delimiter, 3, StringSplitOptions.None);
            string   node;

            if (jstreeNodeSplit.Length == 1)
            {
                node = jstreeNodeSplit[0];
            }
            else
            {
                node = jstreeNodeSplit[1];
            }

            List <object> jsonTree    = new List <object>();
            string        endpointId  = Session["EndpointId"].ToString();
            string        endpointUrl = Session["EndpointUrl"].ToString();
            string        ProductUri  = Session["ProductUri"].ToString();

            // read the currently published nodes
            PublishedItemListResponseApiModel publishedNodes = new PublishedItemListResponseApiModel();

            try
            {
                PublishedItemListRequestApiModel publishModel = new PublishedItemListRequestApiModel();
                publishedNodes = await TwinService.GetPublishedNodesAsync(endpointId, publishModel);
            }
            catch (Exception e)
            {
                // do nothing, since we still want to show the tree
                Trace.TraceWarning("Can not read published nodes for endpoint '{0}'.", endpointUrl);
                string errorMessage = string.Format(Strings.BrowserOpcException, e.Message,
                                                    e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                Trace.TraceWarning(errorMessage);
            }

            BrowseResponseApiModel browseData = new BrowseResponseApiModel();

            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                try
                {
                    BrowseRequestApiModel model = new BrowseRequestApiModel();
                    model.NodeId          = node;
                    model.TargetNodesOnly = false;

                    browseData = TwinService.NodeBrowse(endpointId, model);
                }
                catch (Exception e)
                {
                    // skip this node
                    Trace.TraceError("Can not browse node '{0}'", node);
                    string errorMessage = string.Format(Strings.BrowserOpcException, e.Message,
                                                        e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                    Trace.TraceError(errorMessage);
                }

                Trace.TraceInformation("Browsing node '{0}' data took {0} ms", node.ToString(), stopwatch.ElapsedMilliseconds);

                if (browseData.References != null)
                {
                    var idList = new List <string>();
                    foreach (var nodeReference in browseData.References)
                    {
                        bool idFound = false;
                        foreach (var id in idList)
                        {
                            if (id == nodeReference.Target.NodeId.ToString())
                            {
                                idFound = true;
                            }
                        }
                        if (idFound == true)
                        {
                            continue;
                        }

                        Trace.TraceInformation("Browse '{0}' count: {1}", nodeReference.Target.NodeId, jsonTree.Count);

                        NodeApiModel currentNode = nodeReference.Target;

                        currentNode = nodeReference.Target;

                        byte currentNodeAccessLevel   = 0;
                        byte currentNodeEventNotifier = 0;
                        bool currentNodeExecutable    = false;

                        switch (currentNode.NodeClass)
                        {
                        case NodeClass.Variable:
                            currentNodeAccessLevel = (byte)currentNode.UserAccessLevel;
                            if (!PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeAccessLevel = (byte)((uint)currentNodeAccessLevel & ~0x2);
                            }
                            break;

                        case NodeClass.Object:
                            currentNodeEventNotifier = (byte)currentNode.EventNotifier;
                            break;

                        case NodeClass.View:
                            currentNodeEventNotifier = (byte)currentNode.EventNotifier;
                            break;

                        case NodeClass.Method:
                            if (PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeExecutable = (bool)currentNode.UserExecutable;
                            }
                            break;

                        default:
                            break;
                        }

                        var isPublished = false;
                        var isRelevant  = false;
                        if (publishedNodes.Items != null)
                        {
                            foreach (var item in publishedNodes.Items)
                            {
                                if (item.NodeId == nodeReference.Target.NodeId.ToString())
                                {
                                    isPublished = true;
                                    ContosoOpcUaNode contosoOpcUaNode = Startup.Topology.GetOpcUaNode(ProductUri, item.NodeId);
                                    if (contosoOpcUaNode?.Relevance != null)
                                    {
                                        isRelevant = true;
                                    }
                                }
                            }
                        }

                        jsonTree.Add(new
                        {
                            id            = ("__" + node + delimiter[0] + nodeReference.Target.NodeId.ToString()),
                            text          = nodeReference.Target.DisplayName.ToString(),
                            nodeClass     = nodeReference.Target.NodeClass.ToString(),
                            accessLevel   = currentNodeAccessLevel.ToString(),
                            eventNotifier = currentNodeEventNotifier.ToString(),
                            executable    = currentNodeExecutable.ToString(),
                            children      = nodeReference.Target.HasChildren,
                            publishedNode = isPublished,
                            relevantNode  = isRelevant
                        });
                        idList.Add(nodeReference.Target.NodeId.ToString());
                    }
                }

                stopwatch.Stop();
                Trace.TraceInformation("Browing all childeren info of node '{0}' took {0} ms", node, stopwatch.ElapsedMilliseconds);

                return(Json(jsonTree, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Content(CreateOpcExceptionActionString(exception)));
            }
        }
        public async Task <ActionResult> GetChildren(string jstreeNode)
        {
            string[] publishedNodes = await GetListofPublishedNodeIDsforServer();

            // This delimiter is used to allow the storing of the OPC UA parent node ID together with the OPC UA child node ID in jstree data structures and provide it as parameter to
            // Ajax calls.
            string[] delimiter       = { "__$__" };
            string[] jstreeNodeSplit = jstreeNode.Split(delimiter, 3, StringSplitOptions.None);
            string   node;

            if (jstreeNodeSplit.Length == 1)
            {
                node = jstreeNodeSplit[0];
            }
            else
            {
                node = jstreeNodeSplit[1];
            }

            ReferenceDescriptionCollection references;

            Byte[] continuationPoint;
            var    jsonTree = new List <object>();

            bool retry = true;

            while (true)
            {
                try
                {
                    Session session = await OpcSessionHelper.Instance.GetSessionAsync(Session.SessionID, (string)Session["EndpointUrl"]);

                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    session.Browse(
                        null,
                        null,
                        node,
                        0u,
                        BrowseDirection.Forward,
                        ReferenceTypeIds.HierarchicalReferences,
                        true,
                        0,
                        out continuationPoint,
                        out references);

                    Trace.TraceInformation("Browse {0} ms", stopwatch.ElapsedMilliseconds);

                    if (references != null)
                    {
                        var idList = new List <string>();
                        foreach (var nodeReference in references)
                        {
                            bool idFound = false;
                            foreach (var id in idList)
                            {
                                if (id == nodeReference.NodeId.ToString())
                                {
                                    idFound = true;
                                }
                            }
                            if (idFound == true)
                            {
                                continue;
                            }

                            ReferenceDescriptionCollection childReferences = null;
                            Byte[] childContinuationPoint;

                            session.Browse(
                                null,
                                null,
                                ExpandedNodeId.ToNodeId(nodeReference.NodeId, session.NamespaceUris),
                                0u,
                                BrowseDirection.Forward,
                                ReferenceTypeIds.HierarchicalReferences,
                                true,
                                0,
                                out childContinuationPoint,
                                out childReferences);

                            INode currentNode = null;
                            try
                            {
                                currentNode = session.ReadNode(ExpandedNodeId.ToNodeId(nodeReference.NodeId, session.NamespaceUris));
                            }
                            catch (Exception)
                            {
                                // skip this node
                                continue;
                            }

                            byte currentNodeAccessLevel   = 0;
                            byte currentNodeEventNotifier = 0;
                            bool currentNodeExecutable    = false;

                            VariableNode variableNode = currentNode as VariableNode;
                            if (variableNode != null)
                            {
                                currentNodeAccessLevel = variableNode.UserAccessLevel;
                                if (!PermsChecker.HasPermission(Permission.ControlOpcServer))
                                {
                                    currentNodeAccessLevel = (byte)((uint)currentNodeAccessLevel & ~0x2);
                                }
                            }

                            ObjectNode objectNode = currentNode as ObjectNode;
                            if (objectNode != null)
                            {
                                currentNodeEventNotifier = objectNode.EventNotifier;
                            }

                            ViewNode viewNode = currentNode as ViewNode;
                            if (viewNode != null)
                            {
                                currentNodeEventNotifier = viewNode.EventNotifier;
                            }

                            MethodNode methodNode = currentNode as MethodNode;
                            if (methodNode != null && PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeExecutable = methodNode.UserExecutable;
                            }

                            var published = false;
                            foreach (var nodeId in publishedNodes)
                            {
                                if (nodeId == nodeReference.NodeId.ToString())
                                {
                                    published = true;
                                }
                            }

                            jsonTree.Add(new
                            {
                                id            = ("__" + node + delimiter[0] + nodeReference.NodeId.ToString()),
                                text          = nodeReference.DisplayName.ToString(),
                                nodeClass     = nodeReference.NodeClass.ToString(),
                                accessLevel   = currentNodeAccessLevel.ToString(),
                                eventNotifier = currentNodeEventNotifier.ToString(),
                                executable    = currentNodeExecutable.ToString(),
                                children      = (childReferences.Count == 0) ? false : true,
                                publishedNode = published
                            });
                            idList.Add(nodeReference.NodeId.ToString());
                        }

                        // If there are no children, then this is a call to read the properties of the node itself.
                        if (jsonTree.Count == 0)
                        {
                            INode currentNode = session.ReadNode(new NodeId(node));

                            byte currentNodeAccessLevel   = 0;
                            byte currentNodeEventNotifier = 0;
                            bool currentNodeExecutable    = false;

                            VariableNode variableNode = currentNode as VariableNode;

                            if (variableNode != null)
                            {
                                currentNodeAccessLevel = variableNode.UserAccessLevel;
                                if (!PermsChecker.HasPermission(Permission.ControlOpcServer))
                                {
                                    currentNodeAccessLevel = (byte)((uint)currentNodeAccessLevel & ~0x2);
                                }
                            }

                            ObjectNode objectNode = currentNode as ObjectNode;

                            if (objectNode != null)
                            {
                                currentNodeEventNotifier = objectNode.EventNotifier;
                            }

                            ViewNode viewNode = currentNode as ViewNode;

                            if (viewNode != null)
                            {
                                currentNodeEventNotifier = viewNode.EventNotifier;
                            }

                            MethodNode methodNode = currentNode as MethodNode;

                            if (methodNode != null && PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeExecutable = methodNode.UserExecutable;
                            }

                            jsonTree.Add(new
                            {
                                id            = jstreeNode,
                                text          = currentNode.DisplayName.ToString(),
                                nodeClass     = currentNode.NodeClass.ToString(),
                                accessLevel   = currentNodeAccessLevel.ToString(),
                                eventNotifier = currentNodeEventNotifier.ToString(),
                                executable    = currentNodeExecutable.ToString(),
                                children      = false
                            });
                        }
                    }

                    stopwatch.Stop();
                    Trace.TraceInformation("GetChildren took {0} ms", stopwatch.ElapsedMilliseconds);

                    return(Json(jsonTree, JsonRequestBehavior.AllowGet));
                }
                catch (Exception exception)
                {
                    OpcSessionHelper.Instance.Disconnect(Session.SessionID);
                    if (!retry)
                    {
                        return(Content(CreateOpcExceptionActionString(exception)));
                    }
                    retry = false;
                }
            }
        }