public void TestMethod_GetInstance() { int length = 500; IList <IClientRequestHandler> outputList = new List <IClientRequestHandler>(); Task[] tasks = new Task[length]; //get client form client manager by multithread, and it must be output one client object(maybe get old or create new) for (var i = 0; i < length; i++) { int tmp = i; //Trace.WriteLine("開始任務:" + tmp); var tmoObj = new { manager = this.manager, output = outputList }; var t = Task.Factory.StartNew((obj) => { Trace.WriteLine("開始任務:" + tmp); IClientRequestHandler client = null; client = tmoObj.manager.GetInstance(); tmoObj.output.Add(client); }, tmoObj); tasks[i] = t; } Task.WaitAll(tasks); //check client list haven't null and client number is sequence for (int i = 0; i < length; i++) { Assert.IsNotNull(outputList[i]); Trace.WriteLine("outputList[" + i + "]:" + ((ClientRequestHandler)outputList[i]).ClientNo); Assert.IsTrue(((ClientRequestHandler)outputList[i]).ClientNo == (i + 1)); } foreach (string clientstatus in this.manager.GetClientStatus()) { Trace.WriteLine(clientstatus); } }
public AppConnectionProcessor(IAppConnection connection, IClientRequestHandler clientRequestHandler) { _connection = connection; Id = _connection.Id; _log = LogManager.GetLogger <AppConnectionProcessor>(Id.ToString()); _clientRequestHandler = clientRequestHandler; }
public ClientConnectionProcessor(IClientConnection connection, IClientRequestHandler clientRequestHandler) { _connection = connection; Id = _connection.Id; _log = LogManager.GetLogger <ClientConnectionProcessor>(Id.ToString()); _clientRequestHandler = clientRequestHandler; Completion = TaskRunner.RunInBackground(ProcessAsync); }
public static IClientRequestHandler WithJwtAuthentication(this IClientRequestHandler h, string token) { if (token == null) { throw new ArgumentNullException(nameof(token)); } h.AddJwtAuthentication(token); return(h); }
public static IClientRequestHandler WithFile(this IClientRequestHandler h, string name, string fileName, string contentType, long contentLength, Action <Stream> data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } h.AddFile(name, fileName, contentType, contentLength, data); return(h); }
public static IClientRequestHandler WithJsonBody <TBody>(this IClientRequestHandler h, TBody body) { if (body == null) { throw new ArgumentNullException(nameof(body)); } h.AddJsonBody(body); return(h); }
public static IClientRequestHandler WithHeader(this IClientRequestHandler h, string name, string value) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } h.AddHeader(name, value); return(h); }
/* * Registers a request handler. */ public new void RegisterHandler(string requestType, string urlBase, IClientRequestHandler clientRequestHandler) { // Register the base request. base.RegisterHandler(requestType, urlBase, clientRequestHandler); // Register the GET request. if (requestType != "GET") { base.RegisterHandler("GET", urlBase, clientRequestHandler); } }
/* * Registers a request handler. */ public void RegisterHandler(string requestType, string urlBase, IClientRequestHandler clientRequestHandler) { requestType = requestType.ToLower(); urlBase = URL.FromString(urlBase).GetBaseURL().ToLower(); // Add the request type handler if it doesn't exist. if (!this.Handlers.ContainsKey(requestType)) { this.Handlers.Add(requestType, new Dictionary <string, IClientRequestHandler>()); } //Add the handler. this.Handlers[requestType].Add(urlBase, clientRequestHandler); }
public static async Task <TData> ExecuteAsync <TResponseData, TData>(this IClientRequestHandler h, Func <IFunctionalResponse <TResponseData>, TData> onSuccess, Action <IFunctionalResponse <TResponseData> > onError, CancellationToken cancellationToken = default) { var response = await h.GetResponseAsync <TResponseData>(cancellationToken); if (response.GetSuccess()) { return(onSuccess(response)); } else { onError(response); return(default);
public BrokerProcessor( IReadableChannel <ITransportConnection> incomingConnections, IRegistryProvider registryProvider, IProtocolSerializerFactory serializerFactory, IAppLifecycleManager appLifecycleManager = null) { _incomingConnections = incomingConnections; var registryService = new RegistryService(registryProvider); var protocol = new ProtocolImplementation(DefaultProtocolMessageFactory, serializerFactory); _appLifecycleManager = appLifecycleManager ?? new NoopAppLifecycleManager(); var connectionTracker = new ClientConnectionTracker(_appLifecycleManager); _authenticationHandler = new AuthenticationHandler(connectionTracker, protocol, registryService); _clientRequestHandler = new ClientRequestHandler(connectionTracker, protocol, registryService); Completion = TaskRunner.RunInBackground(ProcessAsync); }
/// <summary> /// 取得一個未使用的client handler /// </summary> /// <returns></returns> public IClientRequestHandler GetInstance() { IClientRequestHandler result = null; lock (lockObj) { //get one client object that is not using, if none then create new result = this.dic.Where(n => { return(n.Value.IsUsed == false); }).FirstOrDefault().Value; //沒有就建一個新的ClientHandler if (result == null) { this.ClientNo++; result = new ClientRequestHandler(this.ClientNo); this.dic.Add(this.ClientNo, (ClientRequestHandler)result); } ((ClientRequestHandler)result).IsUsed = true; } return(result); }
public Client(IClientRequestHandler requestHandler) : base(requestHandler) { }
// ----- Constructors public ContinuousRequestProcessor(IClientRequestHandler clientRequestHandler) { _clientRequestHandler = clientRequestHandler; }
public WeatherForecastHub(IClientRequestHandler clientRequestHandler) { ClientRequestHandler = clientRequestHandler; }