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