public async Task <ResultData> UpdateLogger()
        {
            using StreamReader bodyReader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8);
            var data = await bodyReader.ReadToEndAsync();

            JObject jObject = JObject.Parse(data);

            string localPath = ApiUtils.GetLocalPath(_dbContext, jObject["Guid"].ToString(), out string errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(ResultData.CreateResult("-1", errorMessage, null));
            }

            List <Logger> info;

            using (StreamReader reader = new StreamReader(localPath))
            {
                string json = await reader.ReadToEndAsync();

                info = JsonConvert.DeserializeObject <List <Logger> >(json);
                info[0].DataAdapterType = jObject["DataAdapterType"].ToString();
                info[0].DbInfo          = jObject["DbInfo"].ToString();
                info[0].LogLevel        = jObject["LogLevel"].ToString();
            }

            using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8);
            await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(info)));

            return(ResultData.CreateSuccessResult());
        }
        public async Task <ResultData> DeletePublicDataAdapters([FromBody] List <PublicDataAdapters> data)
        {
            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);
            }

            string[] dataAdapterAlias = data.Select(x => x.DataAdapterAlias).ToArray();

            List <PublicDataAdapters> deleteData = infos.Where(x => dataAdapterAlias.Contains(x.DataAdapterAlias)).ToList();

            foreach (var item in deleteData)
            {
                infos.Remove(item);
            }

            using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8);
            await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(infos)));

            return(ResultData.CreateSuccessResult());
        }
        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 async Task <ResultData> UpdateErpLog()
        {
            using StreamReader bodyReader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8);
            var data = await bodyReader.ReadToEndAsync();

            JObject jObject = JObject.Parse(data);

            string localPath = ApiUtils.GetLocalPath(_dbContext, jObject["Guid"].ToString(), out string errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(ResultData.CreateResult("-1", errorMessage, null));
            }

            ErpLogConfig info;

            using (StreamReader reader = new StreamReader(localPath))
            {
                string json = await reader.ReadToEndAsync();

                info = JsonConvert.DeserializeObject <ErpLogConfig>(json);
                info.MQConnModel.ConnectionModel.Host     = jObject["Host"].ToString();
                info.MQConnModel.ConnectionModel.Port     = jObject["Port"].ToString();
                info.MQConnModel.ConnectionModel.UserName = jObject["UserName"].ToString();
                info.MQConnModel.ConnectionModel.Password = jObject["Password"].ToString();
            }


            using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8);
            await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(info)));

            return(ResultData.CreateSuccessResult());
        }
        public async Task <ResultData> UpdateRedis()
        {
            using StreamReader bodyReader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8);
            var data = await bodyReader.ReadToEndAsync();

            JObject jObject   = JObject.Parse(data);
            string  localPath = ApiUtils.GetLocalPath(_dbContext, jObject["Guid"].ToString(), out string errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(ResultData.CreateResult("-1", errorMessage, null));
            }

            List <RedisInfo> info;

            using (StreamReader reader = new StreamReader(localPath))
            {
                string json = await reader.ReadToEndAsync();

                info = JsonConvert.DeserializeObject <List <RedisInfo> >(json);
                info[0].ServiceName     = jObject["ServiceName"].ToString();
                info[0].Servers[0].IP   = jObject["IP"].ToString();
                info[0].Servers[0].Port = jObject["Port"].ToString().ToInt32();
                info[0].Address         = jObject["Address"].ToString();
                info[0].InstanceName    = jObject["InstanceName"].ToString();
                info[0].Password        = jObject["Password"].ToString();
            }


            using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8);
            await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(info)));

            return(ResultData.CreateSuccessResult());
        }
Beispiel #6
0
        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 <ResultData> UpdatePublicDataAdapters()
        {
            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);
            }

            using StreamReader bodyReader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8);
            var data = await bodyReader.ReadToEndAsync();

            JObject info = JObject.Parse(data);

            if (infos.Where(x => x.DataAdapterAlias != info["DataAdapterAlias"].ToNullString() && x.DataAdapterAccountName != info["DataAdapterAccountName"].ToNullString()).Where(x => x.DataAdapterAlias == info["NewDataAdapterAlias"].ToNullString() || x.DataAdapterAccountName == info["NewDataAdapterAccountName"].ToNullString()).ToList().Count > 0)
            {
                return(ResultData.CreateResult("-1", "账套名称或账套号已存在", null));
            }

            foreach (var item in infos)
            {
                if (item.DataAdapterAlias != info["DataAdapterAlias"].ToNullString())
                {
                    continue;
                }

                item.DataAdapterAlias       = info["NewDataAdapterAlias"].ToNullString();
                item.DataAdapterType        = info["NewDataAdapterType"].ToNullString();
                item.DataAdapterInfo        = info["NewDataAdapterInfo"].ToNullString();
                item.DataAdapterAccountName = info["NewDataAdapterAccountName"].ToNullString();
            }

            using StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8);
            await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(infos)));

            return(ResultData.CreateSuccessResult());
        }
Beispiel #8
0
        public async Task <ResultData> DeleteDataBaseInfo(List <DataBaseInfo> infos, string type)
        {
            //获取配置文件信息
            ConfigInfo configInfo = _dbContext.Queryable <ConfigInfo>().Where(x => x.ConfigName == "PublicDataAdapters.json" && x.CategoryType == type).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));
            }

            List <PublicDataAdapters> datainfos;

            using (StreamReader reader = new StreamReader(localPath))
            {
                string json = await reader.ReadToEndAsync();

                datainfos = JsonConvert.DeserializeObject <List <PublicDataAdapters> >(json);
            }

            string[] dataAdapterAlias = infos.Select(x => x.AccountSetNumber).ToArray();

            List <PublicDataAdapters> deleteData = datainfos.Where(x => dataAdapterAlias.Contains(x.DataAdapterAlias)).ToList();

            foreach (var item in deleteData)
            {
                datainfos.Remove(item);
            }

            using (StreamWriter writer = new StreamWriter(localPath, false, Encoding.UTF8))
            {
                await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(datainfos)));
            }

            return(ResultData.CreateSuccessResult());
        }
        public async Task <ResultData> UpdateRabbitMQApi()
        {
            using StreamReader bodyReader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8);
            var data = await bodyReader.ReadToEndAsync();

            JObject jObject = JObject.Parse(data);

            List <string> localPath = ApiUtils.GetLocalPathByFileName(_dbContext, "RabbitMQ.json", out string errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(ResultData.CreateResult("-1", errorMessage, null));
            }

            List <RabbitMQ> info;

            using (StreamReader reader = new StreamReader(localPath[0]))
            {
                string json = await reader.ReadToEndAsync();

                info = JsonConvert.DeserializeObject <List <RabbitMQ> >(json);
                info[0].ServerUrl  = jObject["ServerUrl"].ToString();
                info[0].ServerPort = jObject["ServerPort"].ToString();
                info[0].UserName   = jObject["UserName"].ToString();
                info[0].Password   = jObject["Password"].ToString();
            }


            foreach (var item in localPath)
            {
                using (StreamWriter writer = new StreamWriter(item, false, Encoding.UTF8))
                {
                    await writer.WriteAsync(ApiUtils.ConvertJsonString(JsonConvert.SerializeObject(info)));
                }
            }

            return(ResultData.CreateSuccessResult());
        }