public async Task <ResultData> AddPublicDataAdapters([FromBody] PublicDataAdapters info) { string guid = Request.Query["guid"]; string localPath = ApiUtils.GetLocalPath(_dbContext, guid, out string errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { return(ResultData.CreateResult("-1", errorMessage, null)); } List <PublicDataAdapters> infos; using (StreamReader reader = new StreamReader(localPath)) { string json = await reader.ReadToEndAsync(); infos = JsonConvert.DeserializeObject <List <PublicDataAdapters> >(json); if (infos.Where(x => x.DataAdapterAccountName == info.DataAdapterAccountName || x.DataAdapterAlias == info.DataAdapterAlias).ToList().Count > 0) { return(ResultData.CreateResult("-1", "账套名称或账套号已存在", null)); } infos.Add(info); } using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8); await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(infos))); return(ResultData.CreateSuccessResult()); }
public ResultData BuildPublicDataAdapters([FromBody] List <DataBaseInfo> infos) { try { List <DataBaseInfo> dataBaseInfos = _dbContext.Queryable <DataBaseInfo>().In(infos.Select(x => x.Guid).ToArray()).ToList(); List <PublicDataAdapters> publicDataAdapters = new List <PublicDataAdapters>(); foreach (var item in dataBaseInfos) { PublicDataAdapters publicDataAdapter = new PublicDataAdapters { DataAdapterType = item.DataBaseType, DataAdapterAlias = item.AccountSetNumber, IsDefaultDataAdapter = "0", DataAdapterAccountName = item.AccountSetName, DataAdapterInfo = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={item.ServerAddress})(PORT={item.Port})))(CONNECT_DATA=(SERVICE_NAME={item.DataBaseName})));User Id={item.UserName};Password={item.UserPassword};{item.ConnectionStringOther}".ToEncodeString() }; publicDataAdapters.Add(publicDataAdapter); } return(ResultData.CreateSuccessResult("", JsonConvert.SerializeObject(publicDataAdapters))); } catch (Exception ex) { return(ResultData.CreateResult("-1", ex.Message, null)); } }
public async Task <ResultData> AddDataBaseInfo([FromBody] DataBaseInfo info) { //检查重复 if (_dbContext.Queryable <DataBaseInfo>().Where(x => x.BusinessType == info.BusinessType && (x.AccountSetName == info.AccountSetName || x.AccountSetNumber == info.AccountSetNumber)).Count() > 0) { return(ResultData.CreateResult("-1", "账套号或账套名称已存在", null)); } //获取配置文件信息 ConfigInfo configInfo = _dbContext.Queryable <ConfigInfo>().Where(x => x.ConfigName == "PublicDataAdapters.json" && x.CategoryType == info.BusinessType).First(); if (configInfo == null) { return(ResultData.CreateResult("-1", "配置文件不存在", null)); } //判断配置文件是否存在 string localPath = ApiUtils.GetLocalPath(_dbContext, configInfo.Guid, out string errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { return(ResultData.CreateResult("-1", errorMessage, null)); } //生成加密信息 PublicDataAdapters publicDataAdapter = new PublicDataAdapters { DataAdapterType = info.DataBaseType, DataAdapterAlias = info.AccountSetNumber, IsDefaultDataAdapter = "0", DataAdapterAccountName = info.AccountSetName, DataAdapterInfo = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={info.ServerAddress})(PORT={info.Port})))(CONNECT_DATA=(SERVICE_NAME={info.DataBaseName})));User Id={info.UserName};Password={info.UserPassword};{info.ConnectionStringOther}".ToEncodeString() }; List <PublicDataAdapters> infos; using (StreamReader reader = new StreamReader(localPath)) { string json = await reader.ReadToEndAsync(); infos = JsonConvert.DeserializeObject <List <PublicDataAdapters> >(json); if (infos.Where(x => x.DataAdapterAccountName == publicDataAdapter.DataAdapterAccountName || x.DataAdapterAlias == publicDataAdapter.DataAdapterAlias).ToList().Count > 0) { return(ResultData.CreateResult("-1", "配置文件中账套名称或账套号已存在", null)); } infos.Add(publicDataAdapter); } //插入数据库 ResultData result = await ApiUtils.InsertData(_dbContext, info); //修改本地文件 using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8); await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(infos))); return(result); }
public async Task <IActionResult> UpdatePublicDataAdapters(string guid, string dataAdapterAlias) { string localPath = ApiUtils.GetLocalPath(_dbContext, guid, out string errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { return(Content(errorMessage)); } using StreamReader reader = new StreamReader(localPath); string json = await reader.ReadToEndAsync(); List <PublicDataAdapters> infos = JsonConvert.DeserializeObject <List <PublicDataAdapters> >(json); PublicDataAdapters info = infos.Where(x => x.DataAdapterAlias == dataAdapterAlias).FirstOrDefault(); ViewBag.Guid = guid; return(View(info)); }