Ejemplo n.º 1
0
        /// <summary>Get the information on a specific service on a specific train. Service shall be available.</summary>
        /// <param name="systemId">The system identifier to retrieve the information.</param>
        /// <param name="serviceId">The service identifier to retrieve information on</param>
        /// <param name="serviceDataResult">[out] Information on the service retrieve. It's never null.</param>
        /// <returns>The success of the operation. Possible values are:
        /// <list type="table">
        /// <listheader><term>Error code</term><description>Description</description></listheader>
        /// <item><term>T2GManagerErrorEnum.eSuccess</term><description>Service retrieved successfully and it is available</description></item>
        /// <item><term>T2GManagerErrorEnum.eServiceInfoNotFound</term><description>Service is unknown or it is not available..</description></item>
        /// <item><term>T2GManagerErrorEnum.eElementNotFound</term><description>Queried system is unknown.</description></item>
        /// <item><term>T2GManagerErrorEnum.eT2GServerOffline</term><description>T2G services are down.</description></item>
        /// </list>
        /// </returns>
        public T2GManagerErrorEnum GetAvailableServiceData(string systemId, int serviceId, out ServiceInfo serviceDataResult)
        {
            T2GManagerErrorEnum lReturn = T2GManagerErrorEnum.eFailed;

            serviceDataResult = null;

            if (T2GServerConnectionStatus)
            {
                // By default, assume that system exist to speed up expected behavior
                ServiceInfo service = _localDataStorage.GetAvailableServiceData(systemId, serviceId);
                if (object.ReferenceEquals(service, null))
                {
                    lReturn = _localDataStorage.ElementExists(systemId) ? T2GManagerErrorEnum.eServiceInfoNotFound : T2GManagerErrorEnum.eElementNotFound;
                }
                else if (service.IsAvailable)
                {
                    serviceDataResult = service; // Copy reference, service info immutable

                    lReturn = T2GManagerErrorEnum.eSuccess;
                }
                else
                {
                    lReturn = T2GManagerErrorEnum.eServiceInfoNotFound;
                }
            }
            else
            {
                lReturn = T2GManagerErrorEnum.eT2GServerOffline;
            }

            if (lReturn != T2GManagerErrorEnum.eSuccess)
            {
                // Always return a valid object.
                serviceDataResult = new ServiceInfo();
            }
            return(lReturn);
        }