Example #1
0
 public void SyncTime()
 {
     Task.Run(() => {
         try {
             //获取服务器时间
             var ntpTime = YUtil.GetNtpTime(HmiConfig.NtpIp);
             App.StartupLog.SyncServerTime = ntpTime;
             //时间差超过10秒才同步时间
             if (Math.Abs((DateTime.Now - ntpTime).TotalSeconds) > 10)
             {
                 YUtil.SetLoadTimeByDateTime(ntpTime);
             }
             App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg()
             {
                 Title   = "通知",
                 Content = "同步时间成功"
             }));
         } catch (Exception e) {
             App.Store.Dispatch(new SysActions.ShowNotification(new SysNotificationMsg()
             {
                 Title   = "警告",
                 Content = "同步时间失败"
             }));
         }
     });
 }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            // 初始化主窗口
            InitializeMainWindow();

            // 设置通知栏图标
            InitailizeNotifyIcon();
            try {
                // 开发电脑上面就不用自启了
                // 设置开机自启
                if (!YUtil.GetWindowsUserName().ToUpper().Contains("SOMIAR"))
                {
                    YUtil.SetAppAutoStart("PanyuVisualSystem", true);
                }
                else
                {
                    UIMessageBox.Show("提示", "开发电脑无需自启", 5000);
                }
            } catch {
                UIMessageBox.Show("异常", "设置启动异常", 5000);
                // ignored
            }
            try {
                // 番禺的防火墙服务默认是禁用
                // 这样就会封掉所有端口,所以只能打开防火墙服务,然后关闭防火墙才行
                // 当然防火墙的状态是设置的为关闭
                YUtil.SetWinServiceStartupType("MpsSvc", ServiceStartMode.Automatic);
                YUtil.StartWinService("MpsSvc");
            } catch {
                // ignored
            }
            // 检查网络连接
            if (OnlineDataCenter.IsNetwork2ServerOK())
            {
                InitAndSetupMachineWindow();
                try {
                    // 同步服务器时间
                    var time = YUtil.GetNtpTime(Configuration.ServerIp);
                    if (Math.Abs((DateTime.Now - time).TotalSeconds) > 10)
                    {
                        YUtil.SetLoadTimeByDateTime(time);
                    }
                } catch {
                    // ignored
                }
            }
            else
            {
                Task.Run(() => {
                    SustainedNetworkTest(null);
                });
            }
        }
Example #3
0
 /// <summary>
 /// 与服务器同步时间
 /// </summary>
 private void syncTime(bool canSync)
 {
     //非开发环境才同步时间
     if (canSync)
     {
         Task.Run(() => {
             try {
                 //获取服务器时间
                 var ntpTime = YUtil.GetNtpTime(HmiConfig.NtpIp);
                 App.StartupLog.SyncServerTime = ntpTime;
                 //时间差超过10秒才同步时间
                 if (Math.Abs((DateTime.Now - ntpTime).TotalSeconds) > 10)
                 {
                     YUtil.SetLoadTimeByDateTime(ntpTime);
                 }
                 Logger.Info($"同步时间成功: {ntpTime}");
             } catch (Exception e) {
                 Logger.Error("获取服务器时间失败", e);
             }
         });
     }
 }