public override async Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) { if (connectionId == null) { throw new ArgumentNullException(nameof(connectionId)); } if (groupName == null) { throw new ArgumentNullException(nameof(groupName)); } var connection = Connections[connectionId]; if (connection != null) { // short circuit if connection is on this server AddGroupAsyncCore(connection, groupName); return; } // Publish to mass transit group management instead, but it waits for an ack... try { LogContext.Info?.Log("Publishing add GroupManagement<THub> message to MassTransit."); RequestHandle <GroupManagement <THub> > request = _groupManagementRequestClient.Create(new { ConnectionId = connectionId, GroupName = groupName, ServerName, Action = GroupAction.Add }, cancellationToken); Response <Ack <THub> > ack = await request.GetResponse <Ack <THub> >(); LogContext.Info?.Log($"Request Received for add GroupManagement<THub> from {ack.Message.ServerName}."); } catch (RequestTimeoutException e) { // That's okay, just log and swallow LogContext.Warning?.Log(e, "GroupManagement<THub> add ack timed out.", e); } }
public async Task Should_be_awesome_with_a_side_of_sourdough_toast() { IRequestClient <GetValue> client = Bus.CreateRequestClient <GetValue>(InputQueueAddress); Response <Value> response; using (RequestHandle <GetValue> request = client.Create(new GetValue())) { request.UseExecute(context => context.Headers.Set("Frank", "Mary")); response = await request.GetResponse <Value>(); } Assert.That(response.RequestId.HasValue, Is.True); Assert.That(response.Headers.TryGetHeader("Frank", out var value), Is.True); Assert.That(value, Is.EqualTo("Mary")); }
/// <summary> /// Send a request from the bus to the endpoint, and return a Task which can be awaited for the response. /// </summary> /// <param name="bus">A started bus instance</param> /// <param name="message">The request message</param> /// <param name="cancellationToken">An optional cancellationToken for this request</param> /// <param name="timeout">An optional timeout for the request (defaults to 30 seconds)</param> /// <param name="callback">A callback, which can modify the <see cref="SendContext" /> of the request</param> /// <typeparam name="TRequest">The request type</typeparam> /// <typeparam name="TResponse">The response type</typeparam> /// <returns></returns> public static async Task <Response <TResponse> > Request <TRequest, TResponse>(this IBus bus, TRequest message, CancellationToken cancellationToken = default, RequestTimeout timeout = default, Action <SendContext <TRequest> > callback = null) where TRequest : class where TResponse : class { IRequestClient <TRequest> requestClient = bus.CreateRequestClient <TRequest>(timeout); using (RequestHandle <TRequest> requestHandle = requestClient.Create(message, cancellationToken)) { if (callback != null) { requestHandle.UseExecute(callback); } return(await requestHandle.GetResponse <TResponse>().ConfigureAwait(false)); } }
/// <summary> /// Execute the method specified in the task. /// If the task-object contains an object-host pair data, then the method /// will be executed on that object - otherwise, a brand new non-persistent /// object of the type specified in the task will be created and the method /// will be executed in that object. /// </summary> /// <returns>task request handle</returns> public RequestHandle ExecuteTask(Task task) { _log.InfoFormat("Received execute request for task: {0}", task.TaskId); // create a new request handle RequestHandle handle = new RequestHandle(); handle.Handle = String.Format("TB-{0}-{1}", Environment.MachineName, Guid.NewGuid().ToString()); _taskRequestHandleMap[task.TaskId] = handle; _handleCallbackMap[handle.Handle] = OperationContext.Current.GetCallbackChannel <ITaskBrokerCallback>(); handle.TaskStatus = TaskStatus.Queued; // enqueue the task _executeQueue.Enqueue(task); _waitTillExecuteQueueHasTasks.Set(); _log.DebugFormat("Task {0} enqueued with handle: {1}", task.TaskId, handle.Handle); return(handle); }
public RequestHandle ScheduleRequest(RequestHandle request, bool force = false) { if (OnGoing()) { if (force || (_request.Background && !request.Background)) { Abort(); } else { Logger.Instance.Log("WARNING", "Please wait for current request to terminate"); return(null); } } _request = request; StartCoroutine(_request.ProcessRequest()); return(request); }
public ActionResult Active(string cusId, bool isActive) { var find = db.BS_Customers.Find(cusId); if (find != null) { find.IsActive = isActive; db.Entry(find).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); if (!String.IsNullOrEmpty(find.ClientUser)) { var postData = "user="******"&isActice=" + isActive; var res = RequestHandle.SendPost(APISource.ROOTURL + "/account/DisableAccount", postData); } } return(Json(new ResultInfo() { error = 0 }, JsonRequestBehavior.AllowGet)); }
public void ClearSendRequestState() { #if DEBUG Interlocked.Increment(ref s_dbg_clearSendRequestState); #endif // Since WinHttpRequestState has a self-referenced strong GCHandle, we // need to clear out object references to break cycles and prevent leaks. Tcs = null; TcsInternalWriteDataToRequestStream = null; CancellationToken = default(CancellationToken); RequestMessage = null; Handler = null; ServerCertificateValidationCallback = null; TransportContext = null; Proxy = null; ServerCredentials = null; DefaultProxyCredentials = null; if (RequestHandle != null) { RequestHandle.Dispose(); RequestHandle = null; } }
public Server(string ipStr, int port) { //controllerManager = new ControllerManager(this); SetIpAndPort(ipStr, port); requestHandle = new RequestHandle(); }
public void Start() { if (IsRunning) { return; } MonitorPool.Singleton.Start(); ResourcesLoader.Singleton.LoadAllConfig(this.configRoot); IsRunning = true; //同时对外对内服务器不能使用全部注册 var listenHandler = new RequestHandle(); //2 对外 listenHandler.RegAssembly(this.GetType().Assembly, HandleResponserType.CLIENT_SERVER); ListenServer = new SocketServer(new ConnectionManager(), port); ListenServer.HandlerManager = listenHandler; ListenServer.Start(); var serviceHandler = new RequestHandle(); serviceHandler.RegAssembly(this.GetType().Assembly, HandleResponserType.SERVER_SERVER); ServiceServer = new SocketServer(new ConnectionManager(), ServicePort); ServiceServer.HandlerManager = serviceHandler; ServiceServer.Start(); Client = new RequestClient(LoginHost, LoginPort); Client.RegTaskHandlerFromAssembly(this.GetType().Assembly); Client.UseSendThreadUpdate = true; Client.OnConnectCompleted = (s, e) => { if (e.Success) { int currentPlayer = 0; using (var db = new DataBaseContext.GameDb(Connection)) { currentPlayer = db.TBGAmePlayer.Count(); } var request = Client.CreateRequest <G2L_Reg, L2G_Reg>(); request.RequestMessage.ServerID = ServerID; request.RequestMessage.Port = this.port; request.RequestMessage.Host = serverHostName; request.RequestMessage.ServiceHost = ServiceHost; request.RequestMessage.ServicesProt = ServicePort; request.RequestMessage.MaxPlayer = 100000; //最大玩家数 request.RequestMessage.CurrentPlayer = currentPlayer; request.RequestMessage.Version = ProtoTool.GetVersion(); request.OnCompleted = (success, r) => { if (success && r.Code == ErrorCode.OK) { Debuger.Log("Server Reg Success!"); } }; request.SendRequestSync(); } else { Debuger.Log("Can't connect LoginServer!"); Stop(); } }; Client.OnDisconnect = (s, e) => { Debuger.Log("Can't connect LoginServer!"); Stop(); }; Client.Connect(); }
public RequestProxry(IExtendApp app, IPlugin plugin) { this._app = app; this._handler = new RequestHandle(plugin); this._mgHandler = new ManageHandle(app,plugin); }
// 请求拦截 private void Application_BeginRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; HttpResponse respond = application.Response; HttpRequest request = application.Request; string url = request.Url.AbsolutePath.ToString(); //如果请求以“/plugins/”开头,表面我们需要对该请求做拦截处理了。 if (url.ToLower().StartsWith("/plugins/")) { string action = url.Substring(url.LastIndexOf("/") + 1); //如果是非静态文件,即是action if (action.IndexOf(".") < 0) { #region 匹配controller和action var urlEntity = HuberPluginHandle.getUrlPathEntity(url.Substring(8), true); #endregion if (urlEntity != null && urlEntity.controller != null) { #region 获取路径中的插件名称等信息 #endregion SandBoxDynamicLoader sandBox = HuberPluginHandle.getSandBox(urlEntity.pluginname, urlEntity.pluginversion); if (sandBox != null) { List <RightEntity> userRight = new List <RightEntity>(); string uid = string.Empty; int login = new UserBll().chekLogin(ref uid, false, userRight); if (login == 2)//验证用户是否具有访问的权限 { RefRequestEntity paras = new RefRequestEntity(); paras.PageRights = userRight; paras.UserID = uid; #region 获取http参数 RequestHandle.FillCorRefEntity(paras, request); #endregion //sandBox.InvokeMothod(urlEntity.controller, "InitChannel", paras) var result = sandBox.InvokeMothod(urlEntity.controller, urlEntity.action, paras); RequestHandle.ResposeResult(respond, result); } else if (login == 1) { RequestHandle.ResponseNoRight(request, respond); } else { RequestHandle.ResponseNoLogin(request, respond); } } } else { RequestHandle.ResponseNotfound(request, respond);; } respond.End(); } } else { if (!url.ToLower().Equals("/user/login")) { string action = url.Substring(url.LastIndexOf("/") + 1); if (action.IndexOf(".") < 0) { List <RightEntity> userRight = new List <RightEntity>(); string uid = string.Empty; int login = new UserBll().chekLogin(ref uid, false, userRight); if (login == 2)//验证用户是否具有访问的权限 { } else if (login == 1) { RequestHandle.ResponseNoRight(request, respond); } else { RequestHandle.ResponseNoLogin(request, respond); } } } } }