Exemplo n.º 1
0
 /// <summary>
 /// 方法:加载轴机械参数配置
 /// </summary>
 /// <returns></returns>
 public static ConfigAxis Load()
 {
     try
     {
         ConfigAxis rt = (ConfigAxis)Serialization.LoadFromFile(typeof(ConfigAxis), _configName);
         return(rt);
     }
     catch (Exception ex)
     {
         LogWriter.WriteException(ex);
         LogWriter.WriteLog(string.Format("错误:加载配置文件[{0}]失败!\n异常描述:{1}\n时间:{2}", _name, ex.Message, System.DateTime.Now.ToString("yyyyMMddhhmmss")));
         throw new LoadException(_name, ex.Message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 加载所有配置
        /// </summary>
        public void Load()
        {
            try
            {
                #region 加载配置
                this.AlarmDefine  = new ConfigAlarm();
                this.InputDefine  = new ConfigInput();
                this.OutputDefine = new ConfigOutput();

                this.SystemDefine = ConfigSystem.Load();
                this.UserDefine   = ConfigUser.Load();
                this.AxisDefine   = ConfigAxis.Load();


                // LoadEquipmentConfig();
                #endregion
            }
            catch (Exception ex)
            {
                LogWriter.WriteException(ex);
                LogWriter.WriteLog(string.Format("错误:加载配置文件失败!\n异常描述:{0}\n时间:{1}", ex.Message, System.DateTime.Now.ToString("yyyyMMddhhmmss")));
            }
        }
Exemplo n.º 3
0
        private void LoadEquipmentConfig()
        {
            AppSqliteConfigure.mDataSource = _configName;
            AppSqliteConfigure.Connected();
            try
            {
                //*********************   创建系统配置表(包含:平台配置参数,通讯配置参数,高级设置参数)
                SysDataManage = new AppSqliteConfigure("SystemTb");
                SysDataManage.CreatTable_DB(sqlSystemData, sqlSystemDataTyp);
                List <string> allData = new List <string>();
                SysDataManage.ReadallDataFromSqliteTable_1("SystemTypes", ref allData);
                bool _needCreate = false;
                allData.Distinct();

                if (!allData.Contains("ConfigUser") && !allData.Contains("ConfigAxis") && !allData.Contains("ConfigSystem"))
                {
                    _needCreate = true;
                }
                else
                {
                    if (!allData.Contains("ConfigUser"))
                    {
                        SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigUser", "", "", "", "" });
                    }
                    if (!allData.Contains("ConfigAxis"))
                    {
                        SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigAxis", "", "", "", "" });
                    }
                    if (!allData.Contains("ConfigSystem"))
                    {
                        SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigSystem", "", "", "", "" });
                    }
                }
                if (_needCreate)
                {
                    //******************   首次默认插入3行数据 ---- 第一位为配置类型名,第二位为详细配置参数
                    SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigUser", "", "", "", "" });
                    SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigAxis", "", "", "", "" });
                    SysDataManage.InsertOneDataOfSqliteTable_1(new string[] { "ConfigSystem", "", "", "", "" });

                    //******************   对象序列化成JSON
                    UserDefine = new ConfigUser();
                    string UserJson = JsonHelper.SerializeObject(UserDefine);
                    AxisDefine = new ConfigAxis();
                    string AxisJson = JsonHelper.SerializeObject(AxisDefine);
                    SystemDefine = new ConfigSystem();
                    string SystemJson = JsonHelper.SerializeObject(SystemDefine);

                    //******************   更新数据库
                    SysDataManage.UpdateOneDataOfSqliteTable_1("SystemTypes", "ConfigUser", "Data1", UserJson);
                    SysDataManage.UpdateOneDataOfSqliteTable_1("SystemTypes", "ConfigAxis", "Data1", AxisJson);
                    SysDataManage.UpdateOneDataOfSqliteTable_1("SystemTypes", "ConfigSystem", "Data1", SystemJson);

                    _needCreate = false;
                }
                //**********************   检查数据库信息
                List <string> platMsg = new List <string>();
                SysDataManage.ReadallDataFromSqliteTable_1("SystemTypes", ref platMsg);
                foreach (string item in platMsg)
                {
                    string DesCriptionMsg = "";
                    SysDataManage.ReadOneDataFromSqliteTable_1("SystemTypes", item, "Data1", ref DesCriptionMsg);
                    if (DesCriptionMsg != "")
                    {
                        if (item == "ConfigSystem")
                        {
                            SystemDefine = JsonHelper.DeserializeJsonToObject <ConfigSystem>(DesCriptionMsg);
                            StartUpdate.SendStartMsg("系统配置加载成功");
                        }
                        else if (item == "ConfigUser")
                        {
                            UserDefine = JsonHelper.DeserializeJsonToObject <ConfigUser>(DesCriptionMsg);
                            StartUpdate.SendStartMsg("用户配置加载成功");
                        }
                        else if (item == "ConfigAxis")
                        {
                            AxisDefine = JsonHelper.DeserializeJsonToObject <ConfigAxis>(DesCriptionMsg);
                            StartUpdate.SendStartMsg("轴配置加载成功");
                        }
                    }
                    else
                    {
                        StartUpdate.SendStartMsg(item + "配置加载失败");
                        LogWriter.WriteLog(string.Format("错误:加载配置文件失败!\n异常描述:{0}\n时间:{1}", item, System.DateTime.Now.ToString("yyyyMMddhhmmss")));
                    }
                }
            }
            catch (Exception ex)
            {
                StartUpdate.SendStartMsg("设备配置加载错误");
                LogWriter.WriteLog(string.Format("错误:设备配置加载错误!\n异常描述:{0}\n时间:{1}", ex.ToString(), System.DateTime.Now.ToString("yyyyMMddhhmmss")));
            }
        }