コード例 #1
0
        private void lstDevices_DoubleClick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            // Ignore items that are currently unreachable.
            if (lstDevices.SelectedItem.ToString().Contains("UNREACHABLE") || lstDevices.SelectedItem.ToString().Trim() == "")
            {
                return;
            }
            CoApDiscovery disc = (CoApDiscovery)NetworkInterface.Instance.DiscoveryRequest;

            disc.ServerPort = Convert.ToInt32(cboPort.Text);
            disc.IpAddress  = lstDevices.SelectedItem.ToString();
            CoApResources resources = disc.LoadResources();

            foreach (CoApResource res in resources)
            {
                TreeNode resNode = treeResources.Nodes.Add(res.URI);
                foreach (CoApLinkAttribute a in res.LinkAttributes)
                {
                    TreeNode[] node = new TreeNode[1];
                    node[0] = new TreeNode(a.ToString());
                    resNode.Nodes.AddRange(node);
                }
            }
            disc = null;
            GC.Collect();
            Cursor.Current = Cursors.Default;
            ////////string blat = Serialization.SerializeObject(response);
            ////////blat = Serialization.JSONSerialize(response);
            ////////txtResult.Text = blat;
        }
コード例 #2
0
        /// <summary>
        /// Display a form to load the user's Gateway credentials.
        /// </summary>
        /// <returns>a boolean indicating whether or not we successfully set credentials</returns>
        //private bool SetGatewayCoapApiCredentials()
        //{
        //    FileLogger.Write("Fetch Gateway credentials");

        //    // If we have already established credentials don't display the credentials form.
        //    // If credentials are incorrect or we want to use a different set, then they must be reset via the UI.
        //    if (GatewaySettings.Instance.CoApPassword != "" && GatewaySettings.Instance.CoApId != "")
        //        return true;

        //    frmCoApApiLogin f = new frmCoApApiLogin();
        //    DialogResult r = f.ShowDialog();

        //    // OK and CANCEL are the only dialog results allowed.
        //    // If we get an OK, it is assumed that the credentials have been loaded.
        //    if (r == DialogResult.OK)
        //        return true;

        //    FileLogger.Write("Credentials not loaded");

        //    return false;
        //}

        /// <summary>
        /// Load detalis of all CoAP resources associated with a device
        /// </summary>
        /// <param name="device">The tree node in the device list containing the device</param>
        private CoApResources LoadResources(TreeNode device)
        {
            Cursor.Current = Cursors.WaitCursor;    // Show as buys while loading the resources.

            FileLogger.Write("Loading all known resources for device " + device.Text);
            device.Nodes.Clear();

            CoApDiscovery disc = (CoApDiscovery)NetworkInterface.Instance.DiscoveryRequest;

            disc.ServerPort = GatewaySettings.Instance.CoApPort;
            disc.IpAddress  = device.Text;

            CoApResources resources = disc.LoadResources();

            // Display the error where we would otherwise have displayed the resources.
            if (disc.ErrorResult != "")
            {
                TreeNode[] resNode = new TreeNode[1];
                device.ForeColor = Color.Red;
                resNode[0]       = new TreeNode(disc.ErrorResult);
                device.Nodes.AddRange(resNode);
            }

            if (resources != null && disc.ErrorResult == "")
            {
                FileLogger.Write("Resources returned");
                foreach (CoApResource res in resources)
                {
                    TreeNode[] resNode = new TreeNode[1];
                    resNode[0] = new TreeNode(res.URI);
                    device.Nodes.AddRange(resNode);

                    foreach (CoApLinkAttribute a in res.LinkAttributes)
                    {
                        TreeNode[] node = new TreeNode[1];
                        node[0] = new TreeNode(a.ToString());
                        resNode[0].Nodes.AddRange(node);
                    }
                }
            }
            else
            {
                FileLogger.Write("Resources NOT returned");
            }
            disc = null;
            GC.Collect();
            Cursor.Current = Cursors.Default;   // Clear the "busy" cursor
            return(resources);
        }