}//解压结束 public bool UzipReadIni(out Dictionary <string, string> readFile, out string err) { err = ""; readFile = null; //获取ini配置文件中的相关信息 ReadIniFile iniFile = new ReadIniFile(); string iniFilePath = iniFile.getIniFilePath("JsonDataMgr.ini"); // 1.校验 if (String.Empty == iniFilePath) { err = "JsonDataMgr.ini找不到!"; return(false); } // 2. 获取信息 try { readFile = new Dictionary <string, string>() { { "zipFile", (iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "zipfilePath") + iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "zipName")) }, { "extractPath", iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "extractPath") } }; } catch (Exception ex) { err = ex.Message; //显示异常信息 return(false); //显示异常信息 } return(true); }
/// <summary> /// json 文件生产 3种数据库 /// </summary> public bool GeneratedMibInfoList(string ConnectIp) { initDbMemory(); /// ReadIniFile iniFile = new ReadIniFile(); string jsonfilepath = iniFile.IniReadValue( iniFile.getIniFilePath("JsonDataMgr.ini"), "JsonFileInfo", "jsonfilepath"); JsonFile json = new JsonFile(); JObject JObj = json.ReadJsonFileForJObject(jsonfilepath + "mib.json"); foreach (var table in JObj["tableList"]) { CreateNameEnByTableInfo(table); CreateOidByTableInfo(table); CreateTableByTableInfo(table); foreach (var child in table["childList"]) { CreateNameEnByChildInfo(child, table); CreateOidByChildInfo(child, table); } } //TestWriteListDbFile2(); if (!AddDBList(ConnectIp)) { Console.WriteLine("add Db list err."); return(false); } TestWriteListDbFile2(); DelDbMemory(); return(true); }
/******************************** 私有,原来的代码 ********************************/ /// <summary> /// json 文件生产 3种数据库 /// </summary> private void GeneratedMibInfoList() { initDbMemory(); /// ReadIniFile iniFile = new ReadIniFile(); string jsonfilepath = iniFile.IniReadValue(iniFile.getIniFilePath( "JsonDataMgr.ini"), "JsonFileInfo", "jsonfilepath"); JsonFile json = new JsonFile(); JObject JObj = json.ReadJsonFileForJObject(jsonfilepath + "mib.json"); foreach (var table in JObj["tableList"]) { CreateNameEnByTableInfo(table); CreateOidByTableInfo(table); CreateTableByTableInfo(table); foreach (var child in table["childList"]) { CreateNameEnByChildInfo(child, table); CreateOidByChildInfo(child, table); } } //TestWriteListDbFile2(); return; }
public JsonDataManager(string mibVersion) { // 配置文件获取 ReadIniFile iniFile = new ReadIniFile(); string iniFilePath = iniFile.getIniFilePath("JsonDataMgr.ini"); try { string mdbfilePath = iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "mdbfilePath"); mdbFile = mdbfilePath + "lm.mdb"; this.jsonfilepath = iniFile.IniReadValue(iniFilePath, "JsonFileInfo", "jsonfilepath"); } catch (Exception ex) { Console.WriteLine("读取ini文件({0})时,{1}", iniFilePath, ex.Message); return;//显示异常信息 } this.mibVersion = mibVersion; }
/// <summary> /// 把数据库内容,写到文件中,便于查看 /// </summary> void TestWriteListDbFile() { ReadIniFile iniFile = new ReadIniFile(); string jsonfilepath = iniFile.IniReadValue(iniFile.getIniFilePath("JsonDataMgr.ini"), "JsonFileInfo", "jsonfilepath"); JsonFile json = new JsonFile(); json.WriteFile(jsonfilepath + "oid_info_db.json", JsonConvert.SerializeObject(oid_info_db)); json.WriteFile(jsonfilepath + "nameEn_info_db.json", JsonConvert.SerializeObject(nameEn_info_db)); json.WriteFile(jsonfilepath + "table_info_db.json", JsonConvert.SerializeObject(table_info_db)); }
/********** 私有函数 **********/ ////////// public bool testGetDataByTableEnglishName() { ReadIniFile iniFile = new ReadIniFile(); string jsonfilepath = iniFile.IniReadValue(iniFile.getIniFilePath("JsonDataMgr.ini"), "JsonFileInfo", "jsonfilepath"); JsonFile json = new JsonFile(); JObject JObj = json.ReadJsonFileForJObject(jsonfilepath + "Tree_Reference.json"); foreach (var table in JObj["NodeList"]) { IReDataByTableEnglishName reData; string MibTableName = table["MibTableName"].ToString(); if (String.Equals("/", MibTableName)) { continue; } if (false == getDataByTableEnglishName(MibTableName, out reData)) { Console.WriteLine("===={0} not exist.", MibTableName); } } return(true); }
public void GeneratedCmdInfoList() { /// ReadIniFile iniFile = new ReadIniFile(); string iniFilePath = iniFile.getIniFilePath("JsonDataMgr.ini"); string jsonfilepath = iniFile.IniReadValue(iniFilePath, "JsonFileInfo", "jsonfilepath"); string sFilePath = jsonfilepath + "cmd.json"; FileStream fs = new FileStream(sFilePath, FileMode.Open); //初始化文件流 byte[] array = new byte[fs.Length]; //初始化字节数组 fs.Read(array, 0, array.Length); //读取流中数据到字节数组中 fs.Close(); //关闭流 string str = Encoding.Default.GetString(array); //将字节数组转化为字符串 /// dynamic json = JObject.Parse(str); //cmd_info_db = json; foreach (var table in json) { dynamic value = table.Value; Dictionary <string, dynamic> cmdInfo = new Dictionary <string, dynamic>(); List <string> leaflist = new List <string>(); cmdInfo.Add("TableName", value["TableName"]); cmdInfo.Add("CmdType", value["CmdType"]); cmdInfo.Add("CmdDesc", value["CmdDesc"]); foreach (var leaf in value["leafOIdList"]) { leaflist.Add(leaf.ToString()); } cmdInfo.Add("leafOIdList", leaflist); cmd_info_db.Add(table.Name.ToString(), cmdInfo); } return; }
/// <summary> /// json 文件生产 3种数据库 /// </summary> private void GeneratedMibInfoList(bool useOld) { initDbMemory(); /// ReadIniFile iniFile = new ReadIniFile(); string jsonfilepath = iniFile.IniReadValue( iniFile.getIniFilePath("JsonDataMgr.ini"), "JsonFileInfo", "jsonfilepath"); JsonFile json = new JsonFile(); JObject JObj = json.ReadJsonFileForJObject(jsonfilepath + "mib.json"); foreach (var table in JObj["tableList"]) { Dictionary <string, string> nameEnTableInfo = new Dictionary <string, string>(); Dictionary <string, string> oidTableInfo = new Dictionary <string, string>(); string tableName = table["nameMib"].ToString(); string tableOid = table["oid"].ToString(); string tableIndexNum = table["indexNum"].ToString(); string nameCh = table["nameCh"].ToString(); dynamic childList = table["childList"]; nameEnTableInfo.Add("isLeaf", "0"); nameEnTableInfo.Add("oid", tableOid); nameEnTableInfo.Add("indexNum", tableIndexNum); nameEnTableInfo.Add("nameCh", nameCh); this.nameEn_info_db.Add(tableName, nameEnTableInfo); oidTableInfo.Add("isLeaf", "0"); oidTableInfo.Add("nameMib", tableName); oidTableInfo.Add("indexNum", tableIndexNum); oidTableInfo.Add("nameCh", nameCh); this.oid_info_db.Add(tableOid, oidTableInfo); this.table_info_db.Add(tableName, table); foreach (var child in childList) { Dictionary <string, string> nameEnChildInfo = new Dictionary <string, string>(); Dictionary <string, string> oidChildInfo = new Dictionary <string, string>(); string childName = child["childNameMib"]; string childOid = child["childOid"]; string childNameCh = child["childNameCh"]; nameEnChildInfo.Add("tableNameEn", tableName); nameEnChildInfo.Add("isLeaf", "1"); nameEnChildInfo.Add("oid", childOid); nameEnChildInfo.Add("indexNum", tableIndexNum); nameEnChildInfo.Add("nameCh", childNameCh); try { this.nameEn_info_db.Add(childName, nameEnChildInfo); } catch (Exception ex) { this.nameEn_info_db[childName]["oid"] = this.nameEn_info_db[childName]["oid"] + "|" + childOid; Console.WriteLine("生成json_db时{0},{1}", childName, ex.Message); } oidChildInfo.Add("isLeaf", "1"); oidChildInfo.Add("nameMib", childName); oidChildInfo.Add("indexNum", tableIndexNum); this.oid_info_db.Add(childOid, oidChildInfo); } } TestWriteListDbFile(); return; }
/// <summary> 解压缩文件 </summary> /// <returns> flase/true </returns> public bool UnZipFileOid(out string err) { err = ""; string zipfilePath = ""; string zipName = ""; string zipFile = ""; string extractPath = ""; //1. 获取ini配置文件中的相关信息 ReadIniFile iniFile = new ReadIniFile(); string iniFilePath = iniFile.getIniFilePath("JsonDataMgr.ini"); if (String.Empty == iniFilePath) { err = "JsonDataMgr.ini找不到!"; return(false); } try { zipfilePath = iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "zipfilePath"); zipName = iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "zipName"); extractPath = iniFile.IniReadValue(iniFilePath, "ZipFileInfo", "extractPath"); zipFile = zipfilePath + zipName; } catch (Exception ex) { err = ex.Message; //显示异常信息 return(false); //显示异常信息 } //2. 校验 if (zipFile == string.Empty) { err = zipFile + " 压缩文件不能为空!"; return(false); } if (!File.Exists(zipFile)) { err = zipFile + " 压缩文件不存在!"; return(false); } //3. 解压缩rar文件 try { string outfile = extractPath + "output\\lm.mdb"; //var dte = Directory.Exists(outfile); if (File.Exists(outfile)) { //err = outfile + "存在"; File.Delete(outfile); } //System.IO.Compression.ZipFile.ExtractToDirectory(@"D:\C#\myUnzipTest1\lm.dtz", @"D:\C#\myUnzipTest1"); ZipFile.ExtractToDirectory(zipFile, extractPath); } catch (Exception ex) { err = ex.Message;//显示异常信息 return(false); } return(true); }//解压结束