Ejemplo n.º 1
0
        /// <summary>
        /// Send a command to the driver
        /// </summary>
        /// <param name="requestData">Details of the command to send</param>
        /// <returns>Background thread on which the command is executing</returns>
        public Thread DriverCommand(RequestData requestData)
        {
            try // Process the command
            {
                Application.DoEvents();

                // Process the command on a separate thread allowing other requests to be handled concurrently through this thread, which is running the Windows message loop
                Thread driverThread = new Thread(new ParameterizedThreadStart(ProcessCommand)); // Create a new thread on which to make the call to the COM driver
                if (ServerForm.DebugTraceState)
                {
                    ServerForm.LogMessage1(requestData, requestData.Elements[ServerForm.URL_ELEMENT_METHOD], $"DriverCommand has received a command for {deviceKey} on FORM thread {Thread.CurrentThread.ManagedThreadId} Apartment state: {Thread.CurrentThread.GetApartmentState()} Is background: {Thread.CurrentThread.IsBackground} Is thread pool thread: {Thread.CurrentThread.IsThreadPoolThread}");
                }

                driverThread.Start(requestData); // Start the thread supplying the request data to the method

                if (ServerForm.DebugTraceState)
                {
                    ServerForm.LogMessage1(requestData, requestData.Elements[ServerForm.URL_ELEMENT_METHOD], $"DriverCommand has started the command for {deviceKey} on FORM thread { Thread.CurrentThread.ManagedThreadId}");
                }
                return(driverThread); // Return the thread so that the calling method can wait for it to complete and so that this thread can start waiting for the next command
            }
            catch (Exception ex)      // Something serious has gone wrong with the ASCOM Remote server itself so report this to the user
            {
                ServerForm.LogException1(requestData, "DriverCommand", ex.ToString());
                restServer.Return500Error(requestData, "Internal server error (DriverOnSeparateThread): " + ex.ToString());
            }
            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Send a command to the driver
 /// </summary>
 /// <param name="requestData">Details of the command to send</param>
 public void DriverCommand(RequestData requestData)
 {
     try // Process the command
     {
         if (ServerForm.DebugTraceState)
         {
             ServerForm.LogMessage1(requestData, requestData.Elements[ServerForm.URL_ELEMENT_METHOD], string.Format("DriverCommand has received a command for {0} on thread {1}", deviceKey, Thread.CurrentThread.ManagedThreadId));
         }
         Application.DoEvents();
         restServer.ProcessDriverCommand(requestData);
         if (ServerForm.DebugTraceState)
         {
             ServerForm.LogMessage1(requestData, requestData.Elements[ServerForm.URL_ELEMENT_METHOD], string.Format("DriverCommand has completed the command for {0} on thread {1}", deviceKey, Thread.CurrentThread.ManagedThreadId));
         }
     }
     catch (Exception ex) // Something serious has gone wrong with the ASCOM Rest server itself so report this to the user
     {
         ServerForm.LogException1(requestData, "DriverCommand", ex.ToString());
         restServer.Return500Error(requestData, "Internal server error (DriverOnSeparateThread): " + ex.ToString());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Send a command to the driver
 /// </summary>
 /// <param name="requestData">Details of the command to send</param>
 public void DriverCommand(RequestData requestData)
 {
     try // Process the command
     {
         if (ServerForm.DebugTraceState)
         {
             ServerForm.LogMessage(requestData.ClientID, requestData.ClientTransactionID, requestData.ServerTransactionID, "DriverCommand", string.Format("Received command for {0} on thread {1}", deviceKey, Thread.CurrentThread.ManagedThreadId));
         }
         Application.DoEvents();
         restServer.ProcessDriverCommand(requestData.ClientID, requestData.ClientTransactionID, requestData.ServerTransactionID, requestData.SuppliedParameters, requestData.Request, requestData.Response, requestData.Elements, requestData.DeviceKey);
         if (ServerForm.DebugTraceState)
         {
             ServerForm.LogMessage(requestData.ClientID, requestData.ClientTransactionID, requestData.ServerTransactionID, "DriverCommand", string.Format("Completed command for {0} on thread {1}", deviceKey, Thread.CurrentThread.ManagedThreadId));
         }
     }
     catch (Exception ex) // Something serious has gone wrong with the ASCOM Rest server itself so report this to the user
     {
         ServerForm.LogException(requestData.ClientID, requestData.ClientTransactionID, requestData.ServerTransactionID, "DriverCommand", ex.ToString());
         restServer.Return500Error(requestData.Request, requestData.Response, "Internal server error (DriverOnSeparateThread): " + ex.ToString(), requestData.ClientID, requestData.ClientTransactionID, requestData.ServerTransactionID);
     }
 }