示例#1
0
        public IList<VRealTimeInfo> GetRealTimeInfo(string[] arrVehicleCode, SessionContext sessionContext, bool isNotCalcOil,bool isNotEncode)
        {
            if (arrVehicleCode == null || arrVehicleCode.Length == 0)
                throw new ArgumentNullException("GetRealTimeInfo: VehicleCode can not be null or empty!");
            if (sessionContext == null)
                throw new ArgumentNullException("GetRealTimeInfo: SessionContext can not be null!");
            if (string.IsNullOrEmpty(sessionContext.TenantCode))
                throw new ArgumentNullException("GetRealTimeInfo: TenantCode can not be null!");

            DateTime now = DateTime.Now;
            IList<EGPSCurrentInfo> ltCurrentInfo = this.GetCurrentInfo(arrVehicleCode);
            if (ltCurrentInfo.Count == 0)
            {
                return new List<VRealTimeInfo>();
            }

            string[] arrLatLonEncode = GetEncodeLatLon(isNotEncode, ltCurrentInfo);
            
            Guid[] arrVehicleCode_G = arrVehicleCode.Select(s => new Guid(s)).ToArray();

            IGPSInstallationManager igm = new GPSInstallationManager();

            Dictionary<Guid, EGPSInstallationInfo> dcInstallation = igm.GetUsingVehicleDict(sessionContext.TenantCode, arrVehicleCode_G);

            IVehicleAndMileageService service = new VehicleAndMileageService();
            IList<EVehicleAndMileage> ltEVehicleAndMileage = service.Get(arrVehicleCode_G);
            IList<VehicleType> ltVehicleType = GetAllVehicleTypes(sessionContext.TenantCode);
            IList<EDriver> ltDriver = GetDrivers(sessionContext, dcInstallation.Values.ToArray());
            IList<EVehicleRunningState> ltRunningState = GetRunningStates(dcInstallation.Values.ToArray());

            IList<VRealTimeInfo> ltRealTimeInfo = new List<VRealTimeInfo>();
            now = DateTime.Now;
            for (int i = 0; i < ltCurrentInfo.Count; i++)
            {
                if (!isNotEncode)
                {
                    ltCurrentInfo[i].EncodeLatLon = arrLatLonEncode[i];
                }

                VRealTimeInfo realTimeInfo;

                try
                {
                    if (!dcInstallation.ContainsKey(ltCurrentInfo[i].VehicleCode.Value))
                    {
                        continue;
                    }
                    EGPSInstallationInfo installationInfo = dcInstallation[ltCurrentInfo[i].VehicleCode.Value];

                    realTimeInfo = this.CreateVRealTimeInfo(ltEVehicleAndMileage, sessionContext, ltCurrentInfo[i], installationInfo,
                        isNotCalcOil,ltVehicleType,ltDriver,ltRunningState);
                }
                catch (GPSCurrentInfoNullException ex)
                {
                    Logger.Error(ex);
                    continue;
                }
                catch (InvalidGPSCurrentInfoException ex)
                {
                    Logger.Error(ex);
                    continue;
                }
                catch (VehicleInfoNullException ex)
                {
                    Logger.Error(ex);
                    continue;
                }

                ltRealTimeInfo.Add(realTimeInfo);
            }
            TimeSpan ts = DateTime.Now - now;

            Logger.Trace(string.Format("Get CreateVRealTimeInfo use{0}", ts.TotalMilliseconds.ToString()));

            return ltRealTimeInfo;
        }