/// <summary> /// 获取一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <Admin> GetOne(Admin model) { var rst = new ReturnResult <Admin>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select t1.*,t2.Token from admin t1 "); strSql.Append(@"inner join admin_token t2 on t1.Id = t2.AdminId "); strSql.Append("where 1=1 "); if (model != null) { if (model.Id != 0) { strSql.Append("and t1.Id = @Id "); } if (!string.IsNullOrEmpty(model.Token)) { strSql.Append("and t2.Token = @Token "); } } var query = conn.Query <Admin>(strSql.ToString(), model).FirstOrDefault(); if (query == null) { rst.Message = "数据不存在"; } else { rst.Result = true; rst.Data = query; rst.Message = "查询成功"; } } catch (Exception ex) { rst.Message = "查询失败:" + ex.Message; Log4netUtil.Error("AdminDal/GetOne", ex); } return(rst); }
public ReturnResult <User> Login(User model, Trans t = null) { var rst = new ReturnResult <User>() { Message = "用户名或密码错误" }; try { conn = CreateMySqlConnection(t); model.password = EncryptHelper.MD5Encrypt(model.password); var sql = new StringBuilder("select * from user where password=@password "); if (!string.IsNullOrEmpty(model.user_id)) { sql.Append("and user_id=@user_id"); } else if (!string.IsNullOrEmpty(model.user_name)) { sql.Append("and user_name=@user_name"); } else { rst.Status = 10005; rst.Message = "信息已失效请刷新界面重新登录!"; return(rst); } rst.Data = conn.QueryFirstOrDefault <User>(sql.ToString(), model, t?.DbTrans); if (rst.Data != null) { rst.Result = true; rst.Message = "登录成功"; } } catch (Exception ex) { rst.Message = $"服务异常:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ApiResult <bool> DeleteCustom(string where, object model, Trans t = null) { var rst = new ApiResult <bool>() { Message = "批量删除失败" }; try { CreateMySqlConnection(t); conn.Execute($"delete from {GetTableName()} {where}", model, t?.DbTrans); rst.Result = true; rst.Message = "删除成功"; } catch (Exception ex) { rst.Message = $"批量删除失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <AdminToken> CheckToken(AdminToken model) { var rst = new ReturnResult <AdminToken>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select Id,AdminId,Token,TimeOut from admin_token "); strSql.Append("where Token=@Token "); var query = conn.Query <AdminToken>(strSql.ToString(), model).FirstOrDefault(); if (query == null) { throw new Exception("Token不存在"); } else { if (DateTime.Compare((DateTime)query.TimeOut, DateTime.Now) > 0) { rst.Data = query; rst.Result = true; rst.Message = "Token有效"; } else { //否则直接返回false 过期 rst.Status = "10000"; rst.Message = "会话超时,请重新登录"; } } } catch (Exception ex) { rst.Message = ex.Message; Log4netUtil.Error("AdminTokenDal/CheckToken", ex); } return(rst); }
public virtual ApiResult <List <T> > GetList(string where, string orderBy = "", int pageIndex = 0, int pageSize = 10, object parameters = null, Trans t = null) { var rst = new ApiResult <List <T> >() { Message = "暂无记录" }; try { CreateMySqlConnection(t); if (pageIndex > 0) { var sql = $"select * from {GetTableName()} {where}"; rst.Data = conn.GetListPaged <T>(pageIndex, pageSize, sql, out int totalCount, orderBy, parameters, t?.DbTrans).ToList(); rst.PageInfo = new PageInfo() { PageIndex = pageIndex, PageSize = pageSize, TotalCount = totalCount }; } else { rst.Data = GetAll($"{where} {$"order by {orderBy}".If(!string.IsNullOrEmpty(orderBy))}", parameters, t).ToList(); } if (rst.Data != null) { rst.Result = true; rst.Message = "获取成功"; } } catch (Exception ex) { rst.Message = $"获取失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public virtual ApiResult <bool> AddList(List <T> list, Trans t = null) { var rst = new ApiResult <bool>() { Message = "批量添加失败" }; try { CreateMySqlConnection(t); conn.Insert(list, t?.DbTrans); rst.Result = true; rst.Message = "批量添加成功"; } catch (Exception ex) { rst.Message = $"添加失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
/// <summary> /// 验证身份 验证签名的有效性, /// </summary> /// <param name="encodeJwt"></param> /// <param name="validatePayLoad">自定义各类验证; 是否包含那种申明,或者申明的值, </param> /// 例如:payLoad["aud"]?.ToString() == "roberAuddience"; /// 例如:验证是否过期 等 /// <returns></returns> public static bool Validate(JwtSetting jwtSetting, string encodeJwt, out int code, out string error, out Dictionary <string, object> payLoad) { try { var jwtArr = encodeJwt.Split('.'); var header = JsonConvert.DeserializeObject <Dictionary <string, object> >(Base64UrlEncoder.Decode(jwtArr[0])); payLoad = JsonConvert.DeserializeObject <Dictionary <string, object> >(Base64UrlEncoder.Decode(jwtArr[1])); var hs256 = new HMACSHA256(Encoding.ASCII.GetBytes(jwtSetting.SecurityKey)); //首先验证签名是否正确(必须的) if (!string.Equals(jwtArr[2], Base64UrlEncoder.Encode(hs256.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(jwtArr[0], ".", jwtArr[1])))))) { code = 10001; error = "签名不正确"; return(false); } //其次验证是否在有效期内(也应该必须) var now = ToUnixEpochDate(DateTime.Now); if (!(now >= long.Parse(payLoad["nbf"].ToString()) && now < long.Parse(payLoad["exp"].ToString()))) { code = 10002; error = "会话超时"; return(false); } code = 200; error = ""; return(true); } catch (Exception ex) { Log4netUtil.Error($"授权验证失败:{ex}"); code = 10003; error = "授权验证失败"; payLoad = null; return(false); } }
public void Init() { try { string setting = File.ReadAllText(path); List <JobInfoPushMessage> list = JsonConvert.DeserializeObject <List <JobInfoPushMessage> >(setting); if (list == null || list.Count <= 0) { return; } foreach (var item in list) { item.dbstring = EncodeHelper.DecodeBase64(item.dbstring); item.SettingInterface = this; item.CreatJob(); _Default.Add(item); } } catch (Exception ex) { Log4netUtil.Error("加载消息推送任务配置失败,请检查,原因:" + ex.Message, ex); } }
public ReturnResult <bool> UpdateOnlineStatus(Client model) { var rst = new ReturnResult <bool>() { Message = "更新失败" }; try { if (conn.Execute($"update client set is_online=@is_online{(model.is_online ? ",last_heart_time=@last_heart_time" : "")} where secret=@secret", model) > 0) { rst.Result = true; rst.Message = "更新成功"; } } catch (Exception ex) { rst.Message = $"更新失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <bool> Delete(T model) { var rst = new ReturnResult <bool>() { Message = "删除失败" }; try { if (conn.Delete(model) > 0) { rst.Result = true; rst.Message = "删除成功"; } } catch (Exception ex) { rst.Message = $"删除失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public void Save() { try { if (Default == null || Default.Count <= 0) { return; } List <JobInfoCloudHis> list = Tools.CloneByJson <List <JobInfoCloudHis> >(Default); foreach (JobInfoCloudHis job in list) { job.createtmp = EncodeHelper.EncodeBase64(job.createtmp); job.targetsql = EncodeHelper.EncodeBase64(job.targetsql); job.targetdbstring = EncodeAndDecode.Encode(job.targetdbstring); job.requestxml = EncodeHelper.EncodeBase64(job.requestxml); } File.WriteAllText(path, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(list)).ToString()); } catch (Exception ex) { Log4netUtil.Error("定时同步任务配置保存失败,请检查,原因:" + ex.Message, ex); } }
public override void SetTmpTableSchema() { try { DataTable dt = ((RunInterface)this.TaskStarter.CreateInstance(this)).GetTmpTable(); Tools.FlushMemory(); if (dt != null) { string strtmp = "create table " + this.tmpname + Environment.NewLine + "(" + Environment.NewLine; foreach (DataColumn dc in dt.Columns) { strtmp += " " + dc.ColumnName + " varchar(256) null," + Environment.NewLine; } strtmp = strtmp.Remove(strtmp.LastIndexOf(','), 1); strtmp += ")"; this.createtmp = strtmp; } } catch (Exception ex) { Log4netUtil.Error("作业【" + this.name + "】创建临时表发生异常:" + ex.Message, ex); } }
private void LoadChildTreeNode(TreeListNode pnode, List <JobInfo> dv) { try { if (dv == null) { return; } foreach (JobInfo rv in dv) { TreeListNode node = pnode.TreeList.AppendNode(rv.sysname, pnode); node.SetValue(0, rv.name); node.Tag = rv; rv.onJobInfoChanged -= onJobInfoChanged; rv.onJobInfoChanged += onJobInfoChanged; node.StateImageIndex = rv.jlzt == "0" ? 1 : 0; } } catch (Exception ex) { Log4netUtil.Error("作业列表加载失败:" + ex.Message, ex); } }
/// <summary> /// 删除一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Delete(UserDevice model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); if (model.Id > 0) { strSql.Append("delete from user_device "); strSql.Append("where Id=@Id"); } if (!string.IsNullOrEmpty(model.DeviceId)) { strSql.Append("delete from user_device "); strSql.Append("where DeviceId=@DeviceId"); } int count = conn.Execute(strSql.ToString(), model); if (count > 0) { rst.Result = true; rst.Message = "删除成功"; } else { rst.Message = "删除失败"; } } catch (Exception ex) { rst.Message = "删除失败:" + ex.Message; Log4netUtil.Error("UserDeviceDal/Delete", ex); } return(rst); }
public ApiResult <bool> Add(T model, Trans t = null) { var rst = new ApiResult <bool>() { Message = "添加失败" }; try { CreateMySqlConnection(t); if (conn.Insert(model, t?.DbTrans) > 0) { rst.Result = true; rst.Message = "添加成功"; } } catch (Exception ex) { rst.Message = $"添加失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
/// <summary> /// 新增一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Add(UserDevice model) { var rst = new ReturnResult <bool>(); try { //判断重复 var checkQuery = Check(model); if (checkQuery.Result) { rst.Message = "设备名称已存在"; return(rst); } //获取profileid //获取userid StringBuilder strSql = new StringBuilder(); strSql.Append("insert into user_device("); strSql.Append("DeviceId,DeviceName,VerifyCode,NodeId,ProfileId,UserId) "); strSql.Append("values ("); strSql.Append("@DeviceId,@DeviceName,@VerifyCode,@NodeId,@ProfileId,@UserId)"); conn.Execute(strSql.ToString(), model); rst.Result = true; rst.Message = "添加成功"; } catch (Exception ex) { rst.Message = "添加失败:" + ex.Message; Log4netUtil.Error("UserDeviceDal/Add", ex); } return(rst); }
public ReturnResult <Client> GetOne(string secret) { var rst = new ReturnResult <Client>() { Message = "暂无记录" }; try { rst.Data = conn.QueryFirstOrDefault <Client>("select * from client where secret=@secret", new { secret }); if (rst.Data != null) { rst.Result = true; rst.Message = "获取成功"; } } catch (Exception ex) { rst.Message = $"获取失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
/// <summary> /// 修改一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Update(Profile model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("update profile set "); strSql.Append("ManufacturerId=@ManufacturerId,"); strSql.Append("ManufacturerName=@ManufacturerName,"); strSql.Append("DeviceType=@DeviceType,"); strSql.Append("Model=@Model,"); strSql.Append("ProtocolType=@ProtocolType, "); strSql.Append("AppId=@AppId, "); strSql.Append("ProtocolId=@ProtocolId "); strSql.Append("where Id=@Id"); int count = conn.Execute(strSql.ToString(), model); if (count > 0) { rst.Result = true; rst.Message = "更新成功"; } else { rst.Message = "更新失败"; } } catch (Exception ex) { rst.Message = "更新失败:" + ex.Message; Log4netUtil.Error("ProfileDal/Update", ex); } return(rst); }
/// <summary> /// 新增一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Add(CommandInfo model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into command_info("); strSql.Append("CommandId,AppId,DeviceId,Command,CallbackUrl,ExpireTime,Status,Result,CreationTime,ExecuteTime,PlatformIssUedTime,DeliveredTime,IssuedTimes,MaxRetransMit) "); strSql.Append("values ("); strSql.Append("@CommandId,@AppId,@DeviceId,@Command,@CallbackUrl,@ExpireTime,@Status,@Result,@CreationTime,@ExecuteTime,@PlatformIssUedTime,@DeliveredTime,@IssuedTimes,@MaxRetransMit)"); conn.Execute(strSql.ToString(), model); rst.Result = true; rst.Message = "添加成功"; } catch (Exception ex) { rst.Message = "添加失败:" + ex.Message; Log4netUtil.Error("CommandInfoDal/Add", ex); } return(rst); }
public ReturnResult <bool> UpdateOnlineStatus(Client model, Trans t = null) { var rst = new ReturnResult <bool>() { Message = "更新失败" }; try { conn = CreateMySqlConnection(t); if (conn.Execute($"update client set is_online=@is_online{",last_heart_time=@last_heart_time".If(model.is_online)} where secret=@secret", model, t?.DbTrans) > 0) { rst.Result = true; rst.Message = "更新成功"; } } catch (Exception ex) { rst.Message = $"更新失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <T> GetOne(IModel model) { var rst = new ReturnResult <T>() { Message = "暂无记录" }; try { rst.Data = conn.Get <T>(model.id); if (rst.Data != null) { rst.Result = true; rst.Message = "获取成功"; } } catch (Exception ex) { rst.Message = $"获取失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <bool> Delete(T model, Trans t = null) { var rst = new ReturnResult <bool>() { Message = "删除失败" }; try { conn = CreateMySqlConnection(t); if (conn.Delete(model, t?.DbTrans) > 0) { rst.Result = true; rst.Message = "删除成功"; } } catch (Exception ex) { rst.Message = $"删除失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <bool> DeleteList(string where, object param, Trans t = null) { var rst = new ReturnResult <bool>() { Message = "批量删除失败" }; try { conn = CreateMySqlConnection(t); if (conn.DeleteList <T>(where, param, t?.DbTrans) > 0) { rst.Result = true; rst.Message = "批量删除成功"; } } catch (Exception ex) { rst.Message = $"批量删除失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
public ReturnResult <List <T> > GetList(string where) { var rst = new ReturnResult <List <T> >() { Message = "暂无记录" }; try { rst.Data = conn.GetList <T>(where).ToList(); if (rst.Data != null) { rst.Result = true; rst.Message = "获取成功"; } } catch (Exception ex) { rst.Message = $"获取失败:{ex.InnerException ?? ex}"; Log4netUtil.Error($"{ex.InnerException ?? ex}"); } return(rst); }
/// <summary> /// 修改一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Update(Apps model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("update apps set "); strSql.Append("Name=@Name,"); strSql.Append("AppId=@AppId,"); strSql.Append("Secret=@Secret,"); strSql.Append("AppType=@AppType,"); strSql.Append("AppServer=@AppServer,"); strSql.Append("DeviceServer=@DeviceServer,"); strSql.Append("CreateTime=@CreateTime "); strSql.Append("where Id=@Id"); int count = conn.Execute(strSql.ToString(), model); if (count > 0) { rst.Result = true; rst.Message = "更新成功"; } else { rst.Message = "更新失败"; } } catch (Exception ex) { rst.Message = "更新失败:" + ex.Message; Log4netUtil.Error("AppsDal/Update", ex); } return(rst); }
public ApiResult <bool> Update(Map model) { var rst = new ApiResult <bool>(); try { using Trans t = new Trans(); var exitRemote = mapDal.IsExit(model, t); if (exitRemote.Result) { rst.Message = "外网地址已被使用,请更换其它地址"; return(rst); } rst = mapDal.Update(model, t); t.Commit(); } catch (Exception ex) { Log4netUtil.Error($"更新映射失败:{ex}"); } return(rst); }
/// <summary> /// 新增一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Add(AdminToken model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into admin_token("); strSql.Append("AdminId,Token,TimeOut) "); strSql.Append("values ("); strSql.Append("@AdminId,@Token,@TimeOut)"); conn.Execute(strSql.ToString(), model); rst.Result = true; rst.Message = "添加成功"; } catch (Exception ex) { rst.Message = "添加失败:" + ex.Message; Log4netUtil.Error("AdminTokenDal/Add", ex); } return(rst); }
public override string WebRequest() { string result = ""; try { WebServiceArgs list = JsonConvert.DeserializeObject <WebServiceArgs>(this.Cur_Job.GetExcuteCondition()); object[] args = null; if (list != null && list.ArgsList != null && list.ArgsList.Count > 0) { args = new object[list.ArgsList.Count]; foreach (WebServiceArgsInfo item in list.ArgsList) { args.SetValue(item.Value, item.KeyIndex); } } result = GlobalWebRequestHelper.SoapRequest(this.Cur_Job.weburl, this.Cur_Job.servermethod, args); } catch (Exception ex) { Log4netUtil.Error("作业【" + this.Cur_Job.name + "】RunInterfaceByWebService执行异常:" + ex.Message, ex); } return(result); }
/// <summary> /// 新增一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public ReturnResult <bool> Add(HistoryData model) { var rst = new ReturnResult <bool>(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into history_data("); strSql.Append("AppId,DeviceId,ServiceId,ServiceType,Data,EventTime) "); strSql.Append("values ("); strSql.Append("@AppId,@DeviceId,@ServiceId,@ServiceType,@Data,@EventTime)"); conn.Execute(strSql.ToString(), model); rst.Result = true; rst.Message = "添加成功"; } catch (Exception ex) { rst.Message = "添加失败:" + ex.Message; Log4netUtil.Error("HistoryDataDal/Add", ex); } return(rst); }
public static HttpResponseMessage Request(string method, string url, string postData = null, Dictionary <string, string> headers = null, string contentType = null, int timeout = 60, Encoding encoding = null) { HttpResponseMessage result = new HttpResponseMessage(); HttpClient client = null; try { if (url.StartsWith("https")) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; } //反向代理手动设置cookies client = new HttpClient(new HttpClientHandler() { UseCookies = false }); if (headers != null) { if (DefaultRequestHeadersKeys == null) { DefaultRequestHeadersKeys = client.DefaultRequestHeaders.GetType().GetProperties().Select(s => s.Name).ToList(); } foreach (KeyValuePair <string, string> header in headers) { try { if (DefaultRequestHeadersKeys.Contains(header.Key)) { continue; } client.DefaultRequestHeaders.Add(header.Key, header.Value); //Console.WriteLine($"正确添加的header:{header.Key}"); } catch { //Console.WriteLine($"错误添加的header:{header.Key}"); } } } if (timeout > 0) { client.Timeout = new TimeSpan(0, 0, timeout); } using (HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8)) { if (!string.IsNullOrEmpty(contentType)) { content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType); } //先不释放 switch (method.ToUpper()) { case "POST": result = client.PostAsync(url, content).Result; break; case "GET": result = client.GetAsync(url).Result; break; case "PUT": result = client.PutAsync(url, content).Result; break; case "DELETE": result = client.DeleteAsync(url).Result; break; case "OPTIONS": result.StatusCode = HttpStatusCode.NoContent; result.Content = new StringContent(""); break; } } Log4netUtil.Info($"请求地址:{url}{Environment.NewLine}请求参数:{postData}{Environment.NewLine}返回结果:{result.ToString()}"); } catch (Exception ex) { Log4netUtil.Error("Api接口出错了", ex.InnerException ?? ex); Console.WriteLine($"Api接口出错了:{ex.InnerException ?? ex}"); } finally { client.Dispose(); } return(result); }