Ejemplo n.º 1
0
 /*
  * <root>
  * <operation>writeRes</operation>
  * <operator>supervisor</operator>
  * <operTime>Mon, 21 Sep 2020 11:01:56 +0800</operTime>
  * <requestResPath>读者/1/object/0</requestResPath>
  * <resPath>读者/0000000001/object/0</resPath>
  * <ranges>0-72044</ranges>
  * <totalLength>72045</totalLength>
  * <metadata>&lt;file mimetype="image/pjpeg" localpath="a10d0d2e-c3e7-44f4-83ab-e31f7608d429" /&gt;</metadata>
  * <style>
  * </style>
  * <clientAddress via="net.pipe://localhost/dp2library/xe">localhost</clientAddress>
  * <version>1.06</version>
  * </root>
  * */
 static NormalResult TraceWriteRes(
     XmlDocument domLog,
     ProcessInfo info)
 {
     try
     {
         string strResPath = DomUtil.GetElementText(domLog.DocumentElement, "requestResPath");
         if (string.IsNullOrEmpty(strResPath) == false)
         {
             var ret = PatronControl.ClearPhotoCacheFile(strResPath);
             if (ret == true)
             {
                 WpfClientInfo.WriteInfoLog($"路径 {strResPath} 对应的照片本地缓存文件被同步过程删除");
             }
         }
         return(new NormalResult());
     }
     catch (Exception ex)
     {
         return(new NormalResult
         {
             Value = -1,
             ErrorInfo = $"TraceWriteRes() 出现异常: {ex.Message}"
         });
     }
 }
Ejemplo n.º 2
0
        /*
         * <root>
         * <operation>setSystemParameter</operation>
         * <category>circulation</category>
         * <name>rightsTable</name>
         * <value>...</value>
         * <libraryCodeList>
         * </libraryCodeList>
         * <operator>supervisor</operator>
         * <operTime>Fri, 28 Aug 2020 12:02:28 +0800</operTime>
         * <clientAddress via="net.pipe://localhost/dp2library/xe">localhost</clientAddress>
         * <version>1.08</version>
         * </root>
         * */
        static NormalResult TraceSetSystemParameter(
            XmlDocument domLog,
            ProcessInfo info)
        {
            try
            {
                string strCategory = DomUtil.GetElementText(domLog.DocumentElement, "category");
                string strName     = DomUtil.GetElementText(domLog.DocumentElement, "name");

                if (strCategory == "circulation" && strName == "rightsTable")
                {
                    // 获得读者借阅权限定义
                    var result = ShelfData.GetRightsTableFromServer();
                    if (result.Value == -1)
                    {
                        WpfClientInfo.WriteErrorLog($"同步获取读者借阅权限定义时出错: {result.ErrorInfo}");
                        // TODO: 延时后尝试重新获取?
                    }
                    else
                    {
                        string strOperTime = DomUtil.GetElementText(domLog.DocumentElement, "operTime");
                        // DateTime operTime = DateTimeUtil.FromRfc1123DateTimeString(strOperTime);

                        WpfClientInfo.WriteInfoLog($"更新读者权限定义。操作日志创建时间 {strOperTime}");
                    }
                }

                return(new NormalResult());
            }
            catch (Exception ex)
            {
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = $"TraceSetSystemParameter() 出现异常: {ex.Message}"
                });
            }
        }
Ejemplo n.º 3
0
        // 启动一般监控任务
        public static void StartMonitorTask()
        {
            if (_monitorTask != null)
            {
                return;
            }

            CancellationToken token = App.CancelToken;

            token.Register(() =>
            {
                _eventMonitor.Set();
            });

            _monitorTask = Task.Factory.StartNew(async() =>
            {
                WpfClientInfo.WriteInfoLog("全局监控专用线程开始");
                try
                {
                    while (token.IsCancellationRequested == false)
                    {
                        // await Task.Delay(TimeSpan.FromSeconds(10));
                        _eventMonitor.WaitOne(_monitorIdleLength);

                        token.ThrowIfCancellationRequested();

                        // 检查小票打印机状态
                        var check_result = CheckPosPrinter();
                        if (check_result.Value == -1)
                        {
                            App.SetError("printer", "小票打印机状态异常");
                        }
                        else if (StringUtil.IsInList("paperout", check_result.ErrorCode))
                        {
                            App.SetError("printer", "小票打印机缺纸");
                        }
                        else if (StringUtil.IsInList("paperwillout", check_result.ErrorCode))
                        {
                            App.SetError("printer", "小票打印机即将缺纸");
                        }
                        else
                        {
                            App.SetError("printer", null);
                        }

                        // 检查升级绿色 dp2ssl
                        if (_needReboot == false &&
                            StringUtil.IsDevelopMode() == false &&
                            ApplicationDeployment.IsNetworkDeployed == false &&
                            DateTime.Now - _lastUpdateTime > _updatePeriod)
                        {
                            WpfClientInfo.WriteInfoLog("开始自动检查升级");
                            // result.Value:
                            //      -1  出错
                            //      0   经过检查发现没有必要升级
                            //      1   成功
                            //      2   成功,但需要立即重新启动计算机才能让复制的文件生效
                            var update_result = await GreenInstall.GreenInstaller.InstallFromWeb(GreenInstall.GreenInstaller.dp2ssl_weburl,  // "http://dp2003.com/dp2ssl/v1_dev",
                                                                                                 "c:\\dp2ssl",
                                                                                                 "delayExtract,updateGreenSetupExe,clearStateFile,debugInfo",
                                                                                                 //true,
                                                                                                 //true,
                                                                                                 token,
                                                                                                 null);
                            if (update_result.Value == -1)
                            {
                                WpfClientInfo.WriteErrorLog($"自动检查升级出错: {update_result.ErrorInfo}");
                            }
                            else
                            {
                                WpfClientInfo.WriteInfoLog($"结束自动检查升级 update_result:{update_result.ToString()}");
                            }

                            // 2020/9/1
                            WpfClientInfo.WriteInfoLog($"InstallFromWeb() 调试信息如下:\r\n{update_result.DebugInfo}");

                            if (update_result.Value == 1 || update_result.Value == 2)
                            {
                                if (update_result.Value == 1)
                                {
                                    App.TriggerUpdated("重启 dp2ssl(greensetup) 可使用新版本");
                                    PageShelf.TrySetMessage(null, "dp2SSL 升级文件已经下载成功,下次重启 dp2ssl(greensetup) 时可自动升级到新版本");
                                }
                                else if (update_result.Value == 2)
                                {
                                    _needReboot = true;
                                    App.TriggerUpdated("重启计算机可使用新版本");
                                    PageShelf.TrySetMessage(null, "dp2SSL 升级文件已经下载成功,下次重启计算机时可自动升级到新版本");
                                }
                            }
                            _lastUpdateTime = DateTime.Now;
                        }

                        // 2020/9/15
                        // 检查升级 ClickOnce dp2ssl
                        if (StringUtil.IsDevelopMode() == false &&
                            ApplicationDeployment.IsNetworkDeployed == true &&
                            DateTime.Now - _lastUpdateTime > _updatePeriod)
                        {
                            try
                            {
                                // result.Value:
                                //      -1  出错
                                //      0   没有发现新版本
                                //      1   发现新版本,重启后可以使用新版本
                                NormalResult result = WpfClientInfo.InstallUpdateSync();
                                WpfClientInfo.WriteInfoLog($"ClickOnce 后台升级 dp2ssl 返回: {result.ToString()}");
                                if (result.Value == -1)
                                {
                                    WpfClientInfo.WriteErrorLog($"升级出错: {result.ErrorInfo}");
                                }
                                else if (result.Value == 1)
                                {
                                    WpfClientInfo.WriteInfoLog($"升级成功: {result.ErrorInfo}");
                                    App.TriggerUpdated(result.ErrorInfo);
                                    // MessageBox.Show(result.ErrorInfo);
                                }
                                else if (string.IsNullOrEmpty(result.ErrorInfo) == false)
                                {
                                    WpfClientInfo.WriteInfoLog($"{result.ErrorInfo}");
                                }
                            }
                            catch (Exception ex)
                            {
                                WpfClientInfo.WriteErrorLog($"后台 ClickOnce 自动升级出现异常: {ExceptionUtil.GetDebugText(ex)}");
                            }

                            _lastUpdateTime = DateTime.Now;
                        }
                    }
                    _monitorTask = null;
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception ex)
                {
                    WpfClientInfo.WriteErrorLog($"全局监控专用线程出现异常: {ExceptionUtil.GetDebugText(ex)}");
                    App.SetError("global_monitor", $"全局监控专用线程出现异常: {ex.Message}");
                }
                finally
                {
                    WpfClientInfo.WriteInfoLog("全局监控专用线程结束");
                }
            },
                                                 token,
                                                 TaskCreationOptions.LongRunning,
                                                 TaskScheduler.Default);
        }