コード例 #1
0
 private void SaveMapCfg_Click(object sender, RoutedEventArgs e)
 {
     //try
     {
         if (double.Parse(CenterLngBox.Text) > 180 || double.Parse(CenterLngBox.Text) < -180)
         {
             UnitCore.Instance.EventAggregator.PublishMessage(new LogEvent("经度格式不正确", LogType.OnlyInfo));
             return;
         }
         if (double.Parse(CenterLatBox.Text) > 180 || double.Parse(CenterLatBox.Text) < -180)
         {
             UnitCore.Instance.EventAggregator.PublishMessage(new LogEvent("纬度格式不正确", LogType.OnlyInfo));
             return;
         }
         MonConf.GetInstance().SetCenLat(double.Parse(CenterLatBox.Text));
         MonConf.GetInstance().SetCenLng(double.Parse(CenterLngBox.Text));
         MonConf.GetInstance().SetAccessMode(CacheModeBox.SelectedItem.ToString());
         MonConf.GetInstance().SetMapName(Mapnamebox.Text);
         MonConf.GetInstance().SetMapType(MapTypeBox.SelectedItem.ToString());
         var point = new Offset();
         point.Lng = double.Parse(OffsetLngBox.Text);
         point.Lat = double.Parse(OffsetLatBox.Text);
         MonConf.GetInstance().SetMapOffset(point);
         UnitCore.Instance.MainMapCfg = UnitCore.Instance.MonConfigueService.LoadMapCfg();
         RefreshMap(UnitCore.Instance.MainMapCfg);
         UnitCore.Instance.EventAggregator.PublishMessage(new ShowAboutSlide(false));
     }/*
       * catch(Exception ex)
       * {
       * UnitCore.Instance.EventAggregator.PublishMessage(new LogEvent(ex.Message, LogType.OnlyInfo));
       * }*/
 }
コード例 #2
0
ファイル: UnitCore.cs プロジェクト: BJFX/Torp
        public bool LoadConfiguration()
        {
            bool ret = true;

            try
            {
                _monConf     = MonConf.GetInstance();
                _MonConfInfo = _monConf.GetNet();
                if (_MonConfInfo == null)
                {
                    throw _monConf.ex;
                }
                SetupCfg = _monConf.GetSetup();
                if (SetupCfg == null)
                {
                    throw _monConf.ex;
                }
                TargetObj1.ID = (byte)SetupCfg.AUVID1;
                TargetObj2.ID = (byte)SetupCfg.AUVID2;
                MonProtocol.MonProtocol.Velocity    = SetupCfg.AcouVel;
                MonProtocol.MonProtocol.FixedOffset = SetupCfg.Offset;
                _serviceStarted = true;//if failed never get here

                return(_serviceStarted);
            }
            catch (Exception ex)
            {
                ret = false;
                EventAggregator.PublishMessage(new ErrorEvent(ex, LogType.Both));
            }
            return(ret);
        }
コード例 #3
0
ファイル: UnitCore.cs プロジェクト: BJFX/Torp
        private void SaveInitPara()
        {
            string          gridname  = MonConf.GetInstance().MyExecPath + "\\" + "default.ini";
            Stream          stream    = new FileStream(gridname, FileMode.Create, FileAccess.Write, FileShare.None);
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                initpara.buoy = Buoy;
                //initpara.info = InfoBoard;

                formatter.Serialize(stream, initpara);
                stream.Close();
            }
            catch (Exception MyEx)
            {
                stream.Close();
                var errmsg = new ErrorEvent(MyEx, LogType.Both)
                {
                    Message = "保存浮标信息失败:" + MyEx.Message,
                };
                UnitCore.Instance.EventAggregator.PublishMessage(errmsg);
            }
        }
コード例 #4
0
ファイル: UnitCore.cs プロジェクト: BJFX/Torp
        private void ReadInitPara()
        {
            string gridname = MonConf.GetInstance().MyExecPath + "\\" + "default.ini";
            Stream stream   = null;

            try
            {
                stream = new FileStream(gridname, FileMode.Open, FileAccess.Read, FileShare.Read);
                IFormatter formatter = new BinaryFormatter();
                initpara = (InitialData)formatter.Deserialize(stream);
                stream.Close();
                Buoy = initpara.buoy;
                if (Buoy.Count == 0)
                {
                    throw new Exception();//use default value
                }
                //clean the range info,only need gps location
                foreach (var buoy in Buoy.Values)
                {
                    var b = (Buoy)buoy;
                    b.Range1     = 0;
                    b.Range2     = 0;
                    b.liteRange1 = new LiteRange();
                    b.teleRange1 = new TeleRange();
                    b.liteRange2 = new LiteRange();
                    b.teleRange2 = new TeleRange();
                }
                //InfoBoard = initpara.info;
            }
            catch (Exception MyEx)
            {
                if (stream != null)
                {
                    stream.Close();
                }
                var gpsinfo = new GpsInfo()
                {
                    UTCTime   = DateTime.UtcNow,
                    Latitude  = 29.592966F,
                    Longitude = 118.983188F,
                };

                var by1 = new Buoy()
                {
                    Id  = 1,
                    gps = gpsinfo,
                    IP  = "192.168.2.101",
                };
                Buoy.Add(0, by1);
                gpsinfo = new GpsInfo()
                {
                    UTCTime   = DateTime.UtcNow,
                    Latitude  = 29.502966F,
                    Longitude = 118.903188F,
                };
                var by2 = new Buoy()
                {
                    Id  = 2,
                    gps = gpsinfo,
                    IP  = "192.168.2.102",
                };
                Buoy.Add(1, by2);
                gpsinfo = new GpsInfo()
                {
                    UTCTime   = DateTime.UtcNow,
                    Latitude  = 29.512966F,
                    Longitude = 118.913188F,
                };
                var by3 = new Buoy()
                {
                    Id  = 3,
                    gps = gpsinfo,
                    IP  = "192.168.2.103",
                };
                Buoy.Add(2, by3);
                gpsinfo = new GpsInfo()
                {
                    UTCTime   = DateTime.UtcNow,
                    Latitude  = 29.542966F,
                    Longitude = 118.943188F,
                };
                var by4 = new Buoy()
                {
                    Id  = 4,
                    gps = gpsinfo,
                    IP  = "192.168.2.104",
                };
                Buoy.Add(3, by4);
                //InfoBoard = new Hashtable();
                SaveInitPara();
                var errmsg = new ErrorEvent(MyEx, LogType.Both)
                {
                    Message = "浮标信息读取失败,使用默认参数"
                };
                UnitCore.Instance.EventAggregator.PublishMessage(errmsg);
            }
        }