/// <summary> /// 发送消息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="path"></param> /// <param name="message"></param> /// <returns></returns> public async Task <T> SendMessage <T>(string channelKey, IPEndPoint endPoint, string flowControlCfgKey, ServiceConfigureInfo configure, string key, string path, object message) where T : class { T result = default; if (Channels.TryGetValue(channelKey, out var _channel)) { try { result = await _flowControlCenter.ExcuteAsync(key, endPoint, flowControlCfgKey, configure, async() => { var taskId = Guid.NewGuid(); var sendMessage = new RpcGlobalMessageBase <object> { CustomerIp = _customerInfo.Ip, TaskId = taskId, Path = path, Message = message is string?_serialize.Deserializes <object>(_serialize.SerializesJsonString((string)message)) : message }; sendMessage.Sign(GlobalCommon.SHA256Encrypt(taskId + OxygenSetting.SignKey)); var resultTask = RegisterResultCallbackAsync(taskId); await _channel.WriteAndFlushAsync(sendMessage); var resultBt = await resultTask; if (resultBt != null && resultBt.Any()) { return(_serialize.Deserializes <T>(resultBt)); } return(default);
public HttpResponseMessage DeleteUSer(string username) { DnnUser dnnUser = new DnnUser(username); Dictionary <string, string> listParam = uow.SystemParamRepo.GetByGroupKey("AD"); var pass = GlobalCommon.DecryptString(listParam[ADManager.AD_ADMIN_PASS] ?? ""); ADManager manager = new ADManager(listParam[ADManager.AD_DOMAIN], listParam[ADManager.AD_ADMIN_USER], pass); if (manager.IsAuthenticated()) { string message = manager.Delete(username); if (string.IsNullOrEmpty(message)) { bool result = dnnUser.DeleteUser(username); if (result) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = true })); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = "Error delete user DNN" })); } } return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = message })); } return(Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false })); }
/// <summary> /// 启动tcp服务 /// </summary> /// <returns></returns> public async Task <IPEndPoint> OpenServer() { var dispatcher = new DispatcherEventLoopGroup(); _bossGroup = dispatcher; _workerGroup = new WorkerEventLoopGroup(dispatcher); _bootstrap = new ServerBootstrap() .Channel <TcpServerChannel>() .Group(_bossGroup, _workerGroup) .Option(ChannelOption.SoBacklog, 100) .ChildOption(ChannelOption.Allocator, PooledByteBufferAllocator.Default) .ChildOption(ChannelOption.ConnectTimeout, new TimeSpan(0, 0, 5)) .ChildHandler(new ActionChannelInitializer <IChannel>(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(new LengthFieldPrepender(4)); pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4)); pipeline.AddLast(new MessageDecoder <RpcGlobalMessageBase <object> >(_serialize)); pipeline.AddLast(new MessageEncoder <object>(_serialize)); pipeline.AddLast(new RpcServerHandler(_logger, _localProxyGenerator)); })); var port = OxygenSetting.ServerPort ?? GlobalCommon.GetFreePort(); boundChannel = await _bootstrap.BindAsync(port); _logger.LogInfo($"bind tcp 0.0.0.0:{port} to listen"); return(new IPEndPoint(GlobalCommon.GetMachineIp(), port)); }
public object Execute(object param) { try { Dictionary <string, object> paramMap = param as Dictionary <string, object>; if (paramMap == null || paramMap.Count < 1) { throw (new Exception("No parameter in SaveLeaveSoundDAO!")); } using (RisDAL dal = new RisDAL()) { DataSet ds = paramMap["DataSet"] as DataSet; foreach (DataRow dr in ds.Tables[0].Rows) { string strSoundGuid = Guid.NewGuid().ToString(); string strReportGuid = Convert.ToString(dr["ReportGuid"]); string strPath = Convert.ToString(dr["Path"]); int nStatus = 0; string strLeaveTime = GlobalCommon.ToLongDateTime(DateTime.Now); string strOwner = Convert.ToString(dr["Owner"]); string strDomain = Convert.ToString(dr["Domain"]); string strSQL = string.Format("insert into tLeaveSound(SoundGuid,ReportGuid,Path,Status,LeaveTime,Owner,Domain) values('{0}','{1}','{2}',{3},'{4}','{5}','{6}')", strSoundGuid, strReportGuid, strPath, nStatus, strLeaveTime, strOwner, strDomain); dal.ExecuteNonQuery(strSQL); strSQL = string.Format("update tReport set IsLeaveSound=1 where ReportGuid='{0}'", strReportGuid); dal.ExecuteNonQuery(strSQL); } } } catch (Exception ex) { System.Diagnostics.Debug.Assert(false, ex.Message); ServerPubFun.RISLog_Error(0, "SaveLeaveSoundDAO=" + ex.Message, (new System.Diagnostics.StackFrame()).GetFileName(), (new System.Diagnostics.StackFrame()).GetFileLineNumber()); return(false); } return(true); }
public static MvcHtmlString InputFile(this HtmlHelper html, string name, int?currentFileID = 0, string currentFileName = "", bool multiple = false, string onChange = "") { StringBuilder result = new StringBuilder(); result.AppendLine("<div style='width: 188px;overflow:hidden;float: left; border: 1px solid #c0c0c0; padding: 7px;height:20px;' class='selected-file' style='{3}' id='selected-file-{1}'>{2}</div>"); string str = currentFileID != null && currentFileID != 0 && currentFileName != "" ? GlobalCommon.GetDownloadLink(currentFileID, currentFileName).ToString() : ""; string show = currentFileID != null && currentFileID != 0 && currentFileName != "" ? "" : "display:none"; result.AppendLine("<div id='button-{0}'><input type='button' value='Chọn file...' onclick='$(\"#input-file-{1}\").click()'/></div>"); result.AppendLine("<input {4} type='file' class='vt-input-file' id='input-file-{1}' name='{0}' style='display:none'/>"); if (!multiple) { result.AppendLine("<script type=\"text/javascript\">$(document).ready(function () {{$('#input-file-{1}').change(function (){{$('#selected-file-{1}').html('<span>'+$(this).val()+'</span>');$('#selected-file-{1}').show(); " + onChange + "}})}});</script>"); } else { result.AppendLine("<script type=\"text/javascript\">$(document).ready(function () {{$('#input-file-{1}').change(function (){{ filesStr = ''; for (i = 0; i < this.files.length; i++) {{ filesStr += '<span>'+this.files[i].name+'<br />'+'</span>'; }} $('#selected-file-{1}').html('<span>'+filesStr+'</span'); $('#selected-file-{1}').show(); "+ onChange + " }})}});</script>"); } return(MvcHtmlString.Create(string.Format(result.ToString(), name, Guid.NewGuid(), str, show, multiple ? "multiple" : ""))); }