Esempio n. 1
0
 private void DisconnectThread()
 {
     try
     {
         NMPRK_API.Disconnect(ConnectionHandle);
         ConnectionHandle = -1;
         Connected        = false;
         DisconnectThreadComplete();
     }
     catch (Exception ex)
     {
         ErrorLog.LogException(ex);
     }
 }
Esempio n. 2
0
        private void ConnectThread(object data)
        {
            try
            {
                ConnectInfo ci = data as ConnectInfo;

                int handle = -1;
                int status = -1;

                UpdateConnectionStatus("Connecting...");
                if (ci.Remote == true)
                {
                    ErrorLog.WriteLine(string.Format("Connecting to Remote Host ({0}, {1}, {2})...", ci.Ip, ci.User, ci.Pass));
                    NMPRK.nmprk_connect_remote_parameters_t input = new nmprk_connect_remote_parameters_t();
                    input.ipOrHostname = ci.Ip;
                    input.username     = ci.User;
                    input.password     = ci.Pass;
                    status             = NMPRK_API.ConnectRemote(ref input, ref handle);
                }
                else
                {
                    ErrorLog.WriteLine("Connecting to Local Host...");
                    status = NMPRK_API.ConnectLocal(ref handle);
                }

                ErrorLog.WriteLine("Connect Status: " + status);
                if (status == 0)
                {
                    ErrorLog.WriteLine("Searching for NM Discovery Parameters...");
                    UpdateConnectionStatus("Searching for NM Discovery Parameters...");
                    nm_discovery_parameters_t parameters = new nm_discovery_parameters_t();
                    status = NMPRK_API.GetDiscoveryParameters(handle, ref parameters);
                    if (status != NMPRK_API.NMPRK_SUCCESS)
                    {
                        DisplayNmprkError("GetDiscoveryParameters", status, "The server may not support Node Manager or has not implemented the 'Node Manager OEM SDR'");
                        NMPRK_API.Disconnect(handle);
                        ConnectThreadComplete(false);
                    }
                    else
                    {
                        ErrorLog.WriteLine("NM Channel: 0x" + parameters.channel.ToString("X2"));
                        ErrorLog.WriteLine("NM Address: 0x" + parameters.address.ToString("X2"));
                        status = NMPRK_API.SetDefaultNmCommandBridging(handle, parameters.channel, parameters.address);
                        if (status != NMPRK_API.NMPRK_SUCCESS)
                        {
                            DisplayNmprkError("SetDefaultNmCommandBridging", status);
                            NMPRK_API.Disconnect(handle);
                            ConnectThreadComplete(false);
                        }
                        else
                        {
                            ConnectionHandle = handle;
                            Connected        = true;
                            ConnectThreadComplete(true);
                        }
                    }
                }
                else
                {
                    DisplayNmprkError("Connect", status);
                    NMPRK_API.Disconnect(handle);
                    ConnectThreadComplete(false);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogException(ex);
            }
        }