示例#1
0
        /// <summary>
        /// 获取服务,根据设置自动判断。
        /// </summary>
        /// <returns></returns>
        public override IEphemerisService GetService()
        {
            //检查当前,避免重复加载
            if (IsCurrentEphemerisServiceAvailable())
            {
                log.Info("返回已有星历服务 " + CurrentService);
                return(CurrentService);
            }

            if (ProcessOption.IsUseUniqueEphemerisFile)
            {
                this.CurrentService = EphemerisDataSourceFactory.Create(ProcessOption.EphemerisFilePath);
                log.Info("成功载入选项指定星历文件:  " + ProcessOption.EphemerisFilePath);
                return(CurrentService);
            }

            if (ProcessOption.IsIndicatedEphemerisPathes) //优先指定的星历文件
            {
                var ephePathes = ProcessOption.GetIndicatedEphemerisPathes();

                this.CurrentService = new IndicatedEphemerisService(ephePathes, ProcessOption, DataSourceOption.GetIgsProductSourceOption(CurrentSession));
                //EphemerisDataSourceFactory.Create(ProcessOption.EphemerisFilePath);
                StringBuilder sb = new StringBuilder();
                foreach (var item in ephePathes)
                {
                    sb.AppendLine(item.Key + ":" + item.Value);
                }
                log.Info("成功载入选项指定星历文件:\r\n " + sb.ToString());
                return(CurrentService);
            }



            //如果不需要精密星历,且数据文件夹中有导航文件,则加载之
            if (ObservationDataSources != null && !this.ProcessOption.IsPreciseEphemerisFileRequired)
            {
                ObservationDataSources.TryLoadEphemerisServices();
                if (ObservationDataSources.EphemerisServices.Count > 0)
                {
                    this.CurrentService = ObservationDataSources.EphemerisServices.First;

                    var msg = "设置没有指定星历,也不需要精密星历,发现了导航星历,因此采用此一个导航星历。" + this.CurrentService;
                    log.Info(msg);
                    return(CurrentService);
                }
            }

            //自动匹配精密星历
            if (DataSourceOption.EnableAutoFindingFile)
            {
                // new IgsEphemerisServiceAutoProvider(DataSourceOption.GetIgsProductSourceOption(CurrentSession)).GetEphemerisService();
                GlobalIgsEphemerisService.Instance.IgsEphAutoProvider.IsConnectIgsProduct = this.ProcessOption.IsConnectIgsDailyProduct;

                //尝试获取一个,如果失败则表示不可用
                if (CurrentSession.SatelliteTypes.Count == 0)
                {
                    log.Error("请指定GNSS系统类型");
                }
                else if (GlobalIgsEphemerisService.Instance.IsAvailable(this.CurrentSession.TimePeriod.Start, this.CurrentSession.SatelliteTypes[0]))
                {
                    this.CurrentService = GlobalIgsEphemerisService.Instance;

                    if (this.CurrentService == null || CurrentService.SatCount == 0)
                    {
                        log.Info("没有匹配上星历文件 " + CurrentService);
                    }
                    else
                    {
                        //设置拟合阶次,放在此处不是很合理,2019.05.15,czs
                        GlobalIgsEphemerisService.Instance.IgsEphAutoProvider.InerpolateOrder = this.ProcessOption.EphemerisInterpolationOrder;

                        log.Info("成功自动匹配星历文件 " + CurrentService);
                        return(CurrentService);
                    }
                }
            }
            //自动匹配精密星历
            //if (DataSourceOption.EnableAutoFindingFile)
            //{
            //    this.EphemerisService = new IgsEphemerisServiceAutoProvider(DataSourceOption.GetIgsProductSourceOption(CurrentSession)).GetEphemerisService();

            //    if (this.EphemerisService == null || EphemerisService.SatCount == 0) { log.Info("没有匹配上星历文件 " + EphemerisService); }
            //    else
            //    {
            //        log.Info("成功自动匹配星历文件 " + EphemerisService);
            //        return EphemerisService;
            //    }
            //}

            //NGA星历匹配
            if (ProcessOption.IsEnableNgaEphemerisSource && DataSourceOption.EnableAutoFindingFile && Setting.EnableNet)
            {
                Time obsTime       = CurrentSession.TimePeriod.Start;
                Time time          = Time.UtcNow;
                var  span          = (time - obsTime); //与当前的时间差
                var  isWithTwoDays = span < 48 * 3600; //IGS快速星历服务
                                                       //NGA只有预报星历,取消之。应急采用。
                TryAddNgaEphemeris(obsTime, isWithTwoDays);
                if (this.CurrentService == null || CurrentService.SatCount == 0)
                {
                    log.Info("没有匹配上星历文件 " + CurrentService);
                }
                else
                {
                    log.Info("成功自动匹配 NGA 星历文件 " + CurrentService);
                    return(CurrentService);
                }
            }


            //还没有匹配上,寻找导航文件
            if ((CurrentService == null || CurrentService.SatCount == 0))
            {
                ObservationDataSources.TryLoadEphemerisServices();
                if (ObservationDataSources.EphemerisServices.Count > 0)
                {
                    this.CurrentService = ObservationDataSources.EphemerisServices.First;

                    var msg = "最后时刻,采用了一个导航星历。" + this.CurrentService;
                    log.Info(msg);
                }
            }

            if ((CurrentService == null || CurrentService.SatCount == 0))
            {
                this.CurrentService = GlobalIgsEphemerisService.Instance;
                var msg = "星历服务匹配失败!!!,仍然尝试用全局星历!";
                log.Error(msg);
                //     throw new ArgumentException(msg);
            }

            return(this.CurrentService);
        }