コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public void SetupDialog()
        {
            TL.LogMessage(clientNumber, "SetupDialog", "Connected: " + clientIsConnected.ToString());
            if (clientIsConnected)
            {
                MessageBox.Show("Simulator is connected, setup parameters cannot be changed, please press OK");
            }
            else
            {
                TL.LogMessage(clientNumber, "SetupDialog", "Creating setup form");
                using (setupForm = new SetupDialogForm(TL))
                {
                    // Pass the setup dialogue data into the form
                    setupForm.DriverDisplayName          = DriverDisplayName;
                    setupForm.TraceState                 = traceState;
                    setupForm.DebugTraceState            = debugTraceState;
                    setupForm.ServiceType                = serviceType;
                    setupForm.IPAddressString            = ipAddressString;
                    setupForm.PortNumber                 = portNumber;
                    setupForm.RemoteDeviceNumber         = remoteDeviceNumber;
                    setupForm.EstablishConnectionTimeout = establishConnectionTimeout;
                    setupForm.StandardTimeout            = standardServerResponseTimeout;
                    setupForm.LongTimeout                = longServerResponseTimeout;
                    setupForm.UserName             = userName;
                    setupForm.Password             = password;
                    setupForm.ManageConnectLocally = manageConnectLocally;

                    TL.LogMessage(clientNumber, "SetupDialog", "Showing Dialogue");
                    var result = setupForm.ShowDialog();
                    TL.LogMessage(clientNumber, "SetupDialog", "Dialogue closed");
                    if (result == DialogResult.OK)
                    {
                        TL.LogMessage(clientNumber, "SetupDialog", "Dialogue closed with OK status");

                        // Retrieve revised setup data from the form
                        traceState                    = setupForm.TraceState;
                        debugTraceState               = setupForm.DebugTraceState;
                        serviceType                   = setupForm.ServiceType;
                        ipAddressString               = setupForm.IPAddressString;
                        portNumber                    = setupForm.PortNumber;
                        remoteDeviceNumber            = setupForm.RemoteDeviceNumber;
                        establishConnectionTimeout    = (int)setupForm.EstablishConnectionTimeout;
                        standardServerResponseTimeout = (int)setupForm.StandardTimeout;
                        longServerResponseTimeout     = (int)setupForm.LongTimeout;
                        userName             = setupForm.UserName;
                        password             = setupForm.Password;
                        manageConnectLocally = setupForm.ManageConnectLocally;

                        // Write the changed values to the Profile
                        TL.LogMessage(clientNumber, "SetupDialog", "Writing new values to profile");
                        RemoteClientDriver.WriteProfile(clientNumber, TL, DEVICE_TYPE, DriverProgId,
                                                        traceState, debugTraceState, ipAddressString, portNumber, remoteDeviceNumber, serviceType, establishConnectionTimeout, standardServerResponseTimeout, longServerResponseTimeout, userName, password, manageConnectLocally);

                        // Establish new host and device parameters
                        TL.LogMessage(clientNumber, "SetupDialog", "Establishing new host and device parameters");
                        RemoteClientDriver.ConnectToRemoteServer(ref client, ipAddressString, portNumber, serviceType, TL, clientNumber, DEVICE_TYPE, standardServerResponseTimeout, userName, password);
                    }
                    else
                    {
                        TL.LogMessage(clientNumber, "SetupDialog", "Dialogue closed with Cancel status");
                    }
                }
                if (!(setupForm == null))
                {
                    setupForm.Dispose();
                    setupForm = null;
                }
            }
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <param name="raw"></param>
 public void CommandBlind(string command, bool raw = false)
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CommandBlind(clientNumber, client, URIBase, TL, command, raw);
 }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="command"></param>
 /// <param name="raw"></param>
 /// <returns></returns>
 public string CommandString(string command, bool raw = false)
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     return(RemoteClientDriver.CommandString(clientNumber, client, URIBase, TL, command, raw));
 }
コード例 #4
0
 public void Refresh()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "Refresh");
 }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="actionName"></param>
 /// <param name="actionParameters"></param>
 /// <returns></returns>
 public string Action(string actionName, string actionParameters)
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     return(RemoteClientDriver.Action(clientNumber, client, URIBase, TL, actionName, actionParameters));
 }
コード例 #6
0
 public double TimeSinceLastUpdate(string PropertyName)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetStringIndexedDouble(clientNumber, client, URIBase, TL, "TimeSinceLastUpdate", PropertyName));
 }
コード例 #7
0
 public string SensorDescription(string PropertyName)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetStringIndexedString(clientNumber, client, URIBase, TL, "SensorDescription", PropertyName));
 }
コード例 #8
0
        private void BtnGetRemoteConfiguration_Click(object sender, EventArgs e)
        {
            TL.LogMessage("GetConfiguration", "Start of btnGetRemoteConfgiuration_Click");
            try
            {
                int clientNumber = 0;
                TL.LogMessage("GetConfiguration", "Connecting to device: " + ipAddressString + ":" + portNumber.ToString());

                string clientHostAddress = string.Format("{0}://{1}:{2}", serviceType, ipAddressString, portNumber.ToString());
                TL.LogMessage("GetConfiguration", "Client host address: " + clientHostAddress);

                RestClient client = new RestClient(clientHostAddress)
                {
                    PreAuthenticate = true
                };
                TL.LogMessage("GetConfiguration", "Creating Authenticator");
                client.Authenticator = new HttpBasicAuthenticator(userName, password);
                TL.LogMessage("GetConfiguration", "Setting timeout");
                RemoteClientDriver.SetClientTimeout(client, 10);

                string      managementUri = string.Format("{0}{1}/{2}", SharedConstants.MANAGEMENT_URL_BASE, SharedConstants.API_VERSION_V1, SharedConstants.MANGEMENT_CONFIGURATION);
                RestRequest request       = new RestRequest(managementUri, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                request.AddParameter(SharedConstants.CLIENTID_PARAMETER_NAME, clientNumber.ToString());
                int transaction = RemoteClientDriver.TransactionNumber();
                request.AddParameter(SharedConstants.CLIENTTRANSACTION_PARAMETER_NAME, transaction.ToString());

                TL.LogMessage("GetConfiguration", "Client Txn ID: " + transaction.ToString() + ", Sending command to remote server");
                IRestResponse response = client.Execute(request);
                string        responseContent;
                if (response.Content.Length > 100)
                {
                    responseContent = response.Content.Substring(0, 100);
                }
                else
                {
                    responseContent = response.Content;
                }
                TL.LogMessage("GetConfiguration", string.Format("Response Status: '{0}', Response: {1}", response.StatusDescription, responseContent));

                if ((response.ResponseStatus == ResponseStatus.Completed) & (response.StatusCode == System.Net.HttpStatusCode.OK))
                {
                    ConfigurationResponse configurationResponse = JsonConvert.DeserializeObject <ConfigurationResponse>(response.Content);
                    ConcurrentDictionary <string, ConfiguredDevice> configuration = configurationResponse.Value;
                    TL.LogMessage("GetConfiguration", "Number of device records: " + configuration.Count);

                    using (Profile profile = new Profile())
                    {
                        foreach (string deviceType in profile.RegisteredDeviceTypes)
                        {
                            TL.LogMessage("GetConfiguration", "Adding item: " + deviceType);
                            registeredDeviceTypes.Add(deviceType); // Remember the device types on this system
                        }

                        foreach (ServedDeviceClient item in this.Controls.OfType <ServedDeviceClient>())
                        {
                            TL.LogMessage(0, 0, 0, "GetConfiguration", "Starting Init");
                            item.InitUI(this, TL);
                            TL.LogMessage(0, 0, 0, "GetConfiguration", "Completed Init");
                            item.DeviceType   = configuration[item.Name].DeviceType;
                            item.ProgID       = configuration[item.Name].ProgID;
                            item.DeviceNumber = configuration[item.Name].DeviceNumber;
                            TL.LogMessage("GetConfiguration", "Completed");
                        }
                        TL.LogMessage("GetConfiguration", "Before RecalculateDevice Numbers");

                        RecalculateDeviceNumbers();
                        TL.LogMessage("GetConfiguration", "After RecalculateDevice Numbers");
                    }

                    // Handle exceptions received from the driver by the remote server
                    if (configurationResponse.DriverException != null)
                    {
                        TL.LogMessageCrLf("GetConfiguration", string.Format("Exception Message: {0}, Exception Number: 0x{1}", configurationResponse.ErrorMessage, configurationResponse.ErrorNumber.ToString("X8")));
                    }
                }
                else
                {
                    if (response.ErrorException != null)
                    {
                        TL.LogMessageCrLf("GetConfiguration", "RestClient exception: " + response.ErrorMessage + "\r\n " + response.ErrorException.ToString());
                        // throw new ASCOM.DriverException(string.Format("Communications exception: {0} - {1}", response.ErrorMessage, response.ResponseStatus), response.ErrorException);
                    }
                    else
                    {
                        TL.LogMessage("GetConfiguration" + " Error", string.Format("RestRequest response status: {0}, HTTP response code: {1}, HTTP response description: {2}", response.ResponseStatus.ToString(), response.StatusCode, response.StatusDescription));
                        // throw new ASCOM.DriverException("ServerConfigurationForm Error - Status: " + response.ResponseStatus + " " + response.StatusDescription);
                    }
                }
            }
            catch (Exception ex)
            {
                TL.LogMessage("GetConfiguration", "Exception: " + ex.ToString());
            }

            TL.LogMessage("GetConfiguration", "End of btnGetRemoteConfgiuration_Click");
        }
コード例 #9
0
 public void StopExposure()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "StopExposure");
 }
コード例 #10
0
 public void SetSwitch(short id, bool state)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetBoolWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitch", id, state);
 }
コード例 #11
0
 public void SetSwitchValue(short id, double value)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetDoubleWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitchValue", id, value);
 }
コード例 #12
0
 public void SetSwitchName(short id, string name)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetStringWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitchName", id, name);
 }
コード例 #13
0
 public double SwitchStep(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedDouble(clientNumber, client, URIBase, TL, "SwitchStep", id));
 }
コード例 #14
0
 public string GetSwitchName(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedString(clientNumber, client, URIBase, TL, "GetSwitchName", id));
 }
コード例 #15
0
 public bool GetSwitch(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedBool(clientNumber, client, URIBase, TL, "GetSwitch", id));
 }
コード例 #16
0
 public void Halt()
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "Halt");
     TL.LogMessage(clientNumber, "Halt", "Halted OK");
 }