示例#1
0
        /// <summary>
        /// 更新启动日志
        /// </summary>
        /// <param name="startFailedReason">启动失败原因</param>
        private void updateAppStartupLog(string startFailedReason)
        {
            //设置 HmiName
            var localIp = YUtil.GetAllIps().FirstOrDefault(ip => ip.Contains("188."));
            var hmiName = !string.IsNullOrEmpty(MachineConfig.HmiName) ? MachineConfig.HmiName : localIp ?? "Unknowns";

            if (!string.IsNullOrEmpty(App.StartupLog.HmiName))
            {
                App.StartupLog.HmiName = hmiName;
            }

            var lastLog = getAppLatestStartupLog();

            //增加启动失败次数
            if (lastLog != null)
            {
                App.StartupLog.ContinueFailedTimes = ++lastLog.ContinueFailedTimes;
            }
            else
            {
                App.StartupLog.ContinueFailedTimes = 1;
            }
            App.StartupLog.StartFailedReason = startFailedReason;
            Logger.Error(startFailedReason + " -->" + JsonConvert.SerializeObject(App.StartupLog));

            //保存到 Sqlite
            using (var ctx = SqliteHelper.CreateSqliteService()) {
                ctx.StartupLogs.Add(App.StartupLog);
                ctx.SaveChanges();
            }
            //上传到 MongoDB
            var mongoClient = MongoHelper.GetMongoService();

            mongoClient.GetDatabase(MongoHelper.LogsDb).GetCollection <StartupLog>(MongoHelper.StartupLogsCollection).InsertOneAsync(App.StartupLog);
        }
示例#2
0
        /// <summary>
        /// 根据ip来寻找其配置文件的路径
        /// 如果指定了 hmiXlsPath,则直接使用
        /// </summary>
        public static void LoadFromGlobal(string hmiXlsPath)
        {
            if (!string.IsNullOrEmpty(hmiXlsPath))
            {
                Load(hmiXlsPath);
                return;
            }
            string configPath = null;
            var    ips        = YUtil.GetAllIps();

            foreach (var ip in ips)
            {
                if (GlobalConfig.IpToHmiDict.TryGetValue(ip, out var hmi))
                {
                    configPath = YUtil.GetAbsolutePath(CmdOptions.GlobalOptions.ConfigFolder + "\\Machines\\" + hmi + ".xls");
                }
            }
            if (string.IsNullOrEmpty(configPath))
            {
                throw new Exception($"本机ip{string.Join(",", YUtil.GetAllIps())}未在 Global.xls中配置");
            }
            Load(configPath);
            Console.WriteLine("加载机台配置文件路径:-" + configPath);
        }