private void HandleClientComm(object client) { lock (client) { TcpClient local_0 = (TcpClient)client; Trace.Write((object)new LogInfo(LogType.Initializations, (Exception)null, "Connection opened")); HandlerProvider handlerProvider = (HandlerProvider)null; try { NetworkStream local_1 = local_0.GetStream(); string[] local_2 = this.GetMessage(local_1); if (local_2.Length < 3) { throw new MessageException(local_2, 3, "discriminator|applicationName|methodName|param1|param2|param3"); } MethodCallInfo local_3 = new MethodCallInfo(local_2[2], Enumerable.Skip <string>((IEnumerable <string>)local_2, 3)); ExpertInfo expertInfo = new ExpertInfo(local_2[0] + local_2[1], local_2[1], local_3); handlerProvider = HandlerProvider.GetOrCreate(expertInfo, this.HostConfiguration); lock (handlerProvider.Locker) { handlerProvider.BeginTime = DateTime.Now; handlerProvider.ServerMethod = local_3; handlerProvider.ClientMethod = (MethodCallInfo)null; Thread local_4 = new Thread((ParameterizedThreadStart)(x => { try { ((HandlerProvider)x).ProceedServerMethod(); } catch (Exception exception_1) { HandlerExecutionException local_1 = new HandlerExecutionException(expertInfo, exception_1); handlerProvider.ServerMethod.ErrorMessage = local_1.Message; Trace.Write((object)new LogInfo(LogType.HandlerExecutionError, (Exception)local_1, "")); } finally { handlerProvider.ClientCallSemaphore.Set(); } })) { IsBackground = this._isBackground }; local_4.CurrentCulture = new CultureInfo("en-US"); local_4.Name = (string)(object)local_0.Client.RemoteEndPoint + (object)" > " + (string)(object)this._tcpListener.Server.LocalEndPoint; local_4.Start((object)handlerProvider); handlerProvider.ClientCallSemaphore.WaitOne(); while (handlerProvider.ClientMethod != null) { string[] local_5 = new string[2 + Enumerable.Count <string>((IEnumerable <string>)handlerProvider.ClientMethod.Parameters)]; local_5[0] = "###MQL###"; local_5[1] = handlerProvider.ClientMethod.MethodName; for (int local_6 = 2; local_6 < local_5.Length; ++local_6) { local_5[local_6] = handlerProvider.ClientMethod.Parameters[local_6 - 2]; } this.WriteMessage(local_1, local_5); string[] local_7 = this.GetMessage(local_1); if (local_7.Length < 2) { throw new MessageException(local_7, 2, "lastError|returnValue"); } handlerProvider.ClientMethod.ErrorMessage = local_7[0] == "0:no error" ? (string)null : local_7[0]; handlerProvider.ClientMethod.ReturnValue = local_7[1] == "###EMPTY###" ? string.Empty : local_7[1]; handlerProvider.ServerCallSemaphore.Set(); handlerProvider.ClientCallSemaphore.WaitOne(); } if (handlerProvider.ServerMethod.ErrorMessage != null) { this.WriteMessage(local_1, "###ERR###", handlerProvider.ServerMethod.ErrorMessage); } if (handlerProvider.ServerMethod.ReturnValue != null) { this.WriteMessage(local_1, new string[1] { handlerProvider.ServerMethod.ReturnValue }); } } } catch (Exception exception_0) { Trace.Write((object)new LogInfo(LogType.Execption, exception_0, "")); } finally { if (handlerProvider != null) { handlerProvider.EndTime = DateTime.Now; Trace.Write((object)new LogInfo(LogType.Notifications, (Exception)null, "Method execution time: " + (object)(handlerProvider.EndTime - handlerProvider.BeginTime).TotalMilliseconds + " ms.")); } local_0.Close(); } Trace.Write((object)new LogInfo(LogType.Initializations, (Exception)null, "Connection closed\n")); } }
private void HandleClientComm(object client) { string str; string str1; TcpClient tcpClient = (TcpClient)client; Trace.Write(new TraceInfo(BridgeTraceErrorType.HostInfo, null, "Connection opened")); HandlerProvider orCreate = null; try { try { NetworkStream stream = tcpClient.GetStream(); string[] message = this.GetMessage(stream); if ((int)message.Length >= 3) { MethodCallInfo methodCallInfo = new MethodCallInfo(message[2], message.Skip <string>(3)); ExpertInfo expertInfo = new ExpertInfo(message[0], message[1], methodCallInfo); orCreate = HandlerProvider.GetOrCreate(expertInfo, this.HostConfiguration); lock (orCreate.Locker) { orCreate.BeginTime = DateTime.Now; orCreate.ServerMethod = methodCallInfo; orCreate.ClientMethod = null; Thread thread = new Thread((object x) => { try { try { ((HandlerProvider)x).ProceedServerMethod(); } catch (Exception exception1) { Exception exception = exception1; HandlerExecutionException handlerExecutionException = new HandlerExecutionException(expertInfo, exception); orCreate.ServerMethod.ErrorMessage = handlerExecutionException.Message; Trace.Write(new TraceInfo(BridgeTraceErrorType.HandlerExecutionError, handlerExecutionException, "")); } } finally { orCreate.ClientCallSemaphore.Set(); } }); thread.IsBackground = this._isBackground; Thread cultureInfo = thread; cultureInfo.CurrentCulture = new CultureInfo("en-US"); cultureInfo.Name = string.Concat(tcpClient.Client.RemoteEndPoint, " > ", this._tcpListener.Server.LocalEndPoint); cultureInfo.Start(orCreate); orCreate.ClientCallSemaphore.WaitOne(); while (orCreate.ClientMethod != null) { string[] methodName = new string[2 + orCreate.ClientMethod.Parameters.Count <string>()]; methodName[0] = "###MQL###"; methodName[1] = orCreate.ClientMethod.MethodName; for (int i = 2; i < (int)methodName.Length; i++) { methodName[i] = orCreate.ClientMethod.Parameters[i - 2]; } this.WriteMessage(stream, methodName); string[] strArrays = this.GetMessage(stream); if ((int)strArrays.Length >= 2) { MethodCallInfo clientMethod = orCreate.ClientMethod; if (strArrays[0] == "0:no error") { str = null; } else { str = strArrays[0]; } clientMethod.ErrorMessage = str; MethodCallInfo clientMethod1 = orCreate.ClientMethod; str1 = (strArrays[1] == "###EMPTY###" ? string.Empty : strArrays[1]); clientMethod1.ReturnValue = str1; orCreate.ServerCallSemaphore.Set(); orCreate.ClientCallSemaphore.WaitOne(); } else { throw new MessageException(strArrays, 2, "lastError|returnValue"); } } if (orCreate.ServerMethod.ErrorMessage != null) { string[] errorMessage = new string[] { "###ERR###", orCreate.ServerMethod.ErrorMessage }; this.WriteMessage(stream, errorMessage); } if (orCreate.ServerMethod.ReturnValue != null) { string[] returnValue = new string[] { orCreate.ServerMethod.ReturnValue }; this.WriteMessage(stream, returnValue); } } } else { throw new MessageException(message, 3, "discriminator|applicationName|methodName|param1|param2|param3"); } } catch (Exception exception3) { Exception exception2 = exception3; Trace.Write(new TraceInfo(BridgeTraceErrorType.Execption, exception2, "")); } } finally { if (orCreate != null) { orCreate.EndTime = DateTime.Now; TimeSpan endTime = orCreate.EndTime - orCreate.BeginTime; Trace.Write(new TraceInfo(BridgeTraceErrorType.Service, null, string.Concat("Method execution time: ", endTime.TotalMilliseconds, " ms."))); } tcpClient.Close(); } Trace.Write(new TraceInfo(BridgeTraceErrorType.HostInfo, null, "Connection closed\n")); }