Beispiel #1
0
 public void Halt()
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "Halt");
     TL.LogMessage(clientNumber, "Halt", "Rotator halted OK");
 }
Beispiel #2
0
 public void Unpark()
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "Unpark");
     TL.LogMessage(clientNumber, "Unpark", "Unparked OK");
 }
Beispiel #3
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.ToLowerInvariant(), Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                request.AddParameter(SharedConstants.CLIENTID_PARAMETER_NAME, clientNumber.ToString());
                uint 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");
        }
Beispiel #4
0
 public void SetPark()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "SetPark");
     TL.LogMessage(clientNumber, "SetPark", "Park set OK");
 }
Beispiel #5
0
 public void SyncToTarget()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "SyncToTarget");
     TL.LogMessage(clientNumber, "SyncToTarget", "Slew completed OK");
 }
Beispiel #6
0
 public void StopExposure()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "StopExposure");
 }
Beispiel #7
0
 public string GetSwitchName(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedString(clientNumber, client, URIBase, TL, "GetSwitchName", id));
 }
 public string SensorDescription(string PropertyName)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetStringIndexedString(clientNumber, client, URIBase, TL, "SensorDescription", PropertyName));
 }
 public void Refresh()
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "Refresh");
 }
Beispiel #10
0
 public void SetSwitchValue(short id, double value)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetDoubleWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitchValue", id, value);
 }
 public double TimeSinceLastUpdate(string PropertyName)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetStringIndexedDouble(clientNumber, client, URIBase, TL, "TimeSinceLastUpdate", PropertyName));
 }
Beispiel #12
0
 public void SetSwitch(short id, bool state)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetBoolWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitch", id, state);
 }
Beispiel #13
0
 public void SetSwitchName(short id, string name)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     RemoteClientDriver.SetStringWithShortParameter(clientNumber, client, URIBase, TL, "SetSwitchName", id, name);
 }
Beispiel #14
0
 public double SwitchStep(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedDouble(clientNumber, client, URIBase, TL, "SwitchStep", id));
 }
Beispiel #15
0
 public void CommandBlind(string command, bool raw = false)
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CommandBlind(clientNumber, client, URIBase, TL, command, raw);
 }
Beispiel #16
0
 public void AbortSlew()
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "AbortSlew");
     TL.LogMessage(clientNumber, "AbortSlew", "Slew aborted OK");
 }
Beispiel #17
0
 public string CommandString(string command, bool raw = false)
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     return(RemoteClientDriver.CommandString(clientNumber, client, URIBase, TL, command, raw));
 }
Beispiel #18
0
 public void FindHome()
 {
     RemoteClientDriver.SetClientTimeout(client, longServerResponseTimeout);
     RemoteClientDriver.CallMethodWithNoParameters(clientNumber, client, URIBase, TL, "FindHome");
     TL.LogMessage(clientNumber, "FindHome", "Home found OK");
 }
Beispiel #19
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));
 }
Beispiel #20
0
 public bool GetSwitch(short id)
 {
     RemoteClientDriver.SetClientTimeout(client, standardServerResponseTimeout);
     return(RemoteClientDriver.GetShortIndexedBool(clientNumber, client, URIBase, TL, "GetSwitch", id));
 }