示例#1
0
        /// <summary>
        /// Convert the specified InstrumentBlocksType runtime object into a list of InstrumentStatus objects for
        /// use by the consumer application. Also checks the InstrumentBlocksType for errors reported by the
        /// service (Not to be confused with errors reported by instruments via the service!)The service will report
        /// errors if it is unable to complete a request normally. Such errors will be extremely rare in a production
        /// environment. and generally indicate an unrecoverable system context requiring rebooting of the hosting computer
        /// and/or all connected instruments.
        /// </summary>
        /// <param name="instrument_blocks_type"></param>
        /// <returns></returns>
        private List <InstrumentStatus> BlocksType2StatusList(InstrumentBlocksType instrument_blocks_type)
        {
            List <InstrumentStatus> current_statuses = new List <InstrumentStatus>();

            try
            {
                //First parse and report any errors reported by the service
                if (instrument_blocks_type.ErrorArray != null)
                {
                    foreach (ErrorType err in instrument_blocks_type.ErrorArray)
                    {
                        OnClientError(new ClientErrorEventArgs(new ErrorRecord(err, ErrorRecord.c_ServiceAPISource)));
                    }
                }
                //Then build the list of InstrumentStatus records
                if (instrument_blocks_type.BlockArray != null)
                {
                    foreach (InstrumentBlockType instrument_block_type in instrument_blocks_type.BlockArray)
                    {
                        current_statuses.Add(new InstrumentStatus(instrument_block_type));
                    }
                }
                return(current_statuses);
            }
            catch (Exception ex)
            {
                OnClientError(new ClientErrorEventArgs(new ErrorRecord(ex, System.Reflection.MethodBase.GetCurrentMethod().Name)));
                return(current_statuses);
            }
        }
示例#2
0
 /// <summary>
 /// Register the underlying client with the CFX Manager API service. Called by the consumer facing OpenClient()
 /// method to register the underlying client with the service once the connection is established.
 ///
 /// The registration ID aquired by this request is required by all other service requests. This class hides the
 /// registration ID and its associated role in service transactions from consuming applications.
 ///
 /// Wraps CFXManagerClient:SendServiceRequest() in the local exception handling framework
 /// </summary>
 /// <returns>true IFF no exceptions occurred during the operation</returns>
 private bool Register()
 {
     m_registrationID = string.Empty;
     try
     {
         m_MasterMessage.Item           = m_Register_Item;
         m_MasterMessage.RegistrationID = string.Empty;
         InstrumentBlocksType response = XML2BlocksType(CFXManagerClient.SendServiceRequest(Message2XML(m_MasterMessage)));
         m_registrationID = response.RegistrationID;
         m_MasterMessage.RegistrationID = m_registrationID;
     }
     catch (Exception ex)
     {
         OnClientError(new ClientErrorEventArgs(new ErrorRecord(ex, System.Reflection.MethodBase.GetCurrentMethod().Name)));
     }
     if (string.IsNullOrEmpty(m_registrationID))
     {
         OnClientError(new ClientErrorEventArgs(
                           new ErrorRecord(ErrorRecord.c_NoCode,
                                           "Registration with the CFX Manager API service failed. A previously connected client may have exited without unregistering. Try re-starting CFX Manager",
                                           System.Reflection.MethodBase.GetCurrentMethod().Name)));
     }
     return(!string.IsNullOrEmpty(m_registrationID));
 }