internal static HandlerProvider GetOrCreate(ExpertInfo expertInfo, HostElement hostElement) { lock (HandlerProvider._storageLocker) { if (HandlerProvider._storage.ContainsKey(expertInfo.Discriminator)) { return(HandlerProvider._storage[expertInfo.Discriminator]); } if (!hostElement.Handlers.ContainsKey(expertInfo.HandlerName)) { throw new HandlerLoadException(expertInfo, "Requested application not found in configuration", (Exception)null); } HandlerElement local_0 = hostElement.Handlers[expertInfo.HandlerName]; Assembly local_1; try { local_1 = Assembly.LoadFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + local_0.AssemblyName + ".dll"); } catch (Exception exception_3) { throw new HandlerLoadException(expertInfo, "Requested assembly not found", exception_3); } Type local_3; try { local_3 = local_1.GetType(local_0.TypeName); } catch (Exception exception_2) { throw new HandlerLoadException(expertInfo, "Requested type not found in assembly.", exception_2); } MqlHandler local_5; try { local_5 = (MqlHandler)Activator.CreateInstance(local_3); } catch (Exception exception_1) { throw new HandlerLoadException(expertInfo, "Can't create intance of expert.", exception_1); } try { foreach (ParameterElement item_0 in (ConfigurationElementCollection)local_0.InputParameters) { PropertyInfo local_8 = local_5.GetType().GetProperty(item_0.PropertyName); Type local_9 = local_8.PropertyType; object local_10 = Convert.ChangeType((object)item_0.PropertyValue, local_9); local_8.SetValue((object)local_5, local_10); } } catch (Exception exception_0) { throw new HandlerLoadException(expertInfo, "Can't set input parameters for expert", exception_0); } local_5.Discriminator = expertInfo.Discriminator; HandlerProvider local_12 = new HandlerProvider(local_5, local_0, expertInfo); HandlerProvider._storage.Add(expertInfo.Discriminator, local_12); return(local_12); } }
internal static HandlerProvider GetOrCreate(ExpertInfo expertInfo, HostElement hostElement) { lock (HandlerProvider._storageLocker) { if (HandlerProvider._storage.ContainsKey(expertInfo.Discriminator)) return HandlerProvider._storage[expertInfo.Discriminator]; if (!hostElement.Handlers.ContainsKey(expertInfo.HandlerName)) throw new HandlerLoadException(expertInfo, "Requested application not found in configuration", (Exception) null); HandlerElement local_0 = hostElement.Handlers[expertInfo.HandlerName]; Assembly local_1; try { local_1 = Assembly.LoadFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + local_0.AssemblyName + ".dll"); } catch (Exception exception_3) { throw new HandlerLoadException(expertInfo, "Requested assembly not found", exception_3); } Type local_3; try { local_3 = local_1.GetType(local_0.TypeName); } catch (Exception exception_2) { throw new HandlerLoadException(expertInfo, "Requested type not found in assembly.", exception_2); } MqlHandler local_5; try { local_5 = (MqlHandler) Activator.CreateInstance(local_3); } catch (Exception exception_1) { throw new HandlerLoadException(expertInfo, "Can't create intance of expert.", exception_1); } try { foreach (ParameterElement item_0 in (ConfigurationElementCollection) local_0.InputParameters) { PropertyInfo local_8 = local_5.GetType().GetProperty(item_0.PropertyName); Type local_9 = local_8.PropertyType; object local_10 = Convert.ChangeType((object) item_0.PropertyValue, local_9); local_8.SetValue((object) local_5, local_10); } } catch (Exception exception_0) { throw new HandlerLoadException(expertInfo, "Can't set input parameters for expert", exception_0); } local_5.Discriminator = expertInfo.Discriminator; HandlerProvider local_12 = new HandlerProvider(local_5, local_0, expertInfo); HandlerProvider._storage.Add(expertInfo.Discriminator, local_12); return local_12; } }
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")); }
internal static HandlerProvider GetOrCreate(TradePlatform.MT4.Core.Utils.ExpertInfo expertInfo, HostElement hostElement) { Assembly assembly; Type type; MqlHandler mqlHandler; HandlerProvider item; lock (HandlerProvider._storageLocker) { if (!HandlerProvider._storage.ContainsKey(expertInfo.Discriminator)) { if (hostElement.Handlers.ContainsKey(expertInfo.HandlerName)) { HandlerElement handlerElement = hostElement.Handlers[expertInfo.HandlerName]; try { assembly = Assembly.LoadFile(string.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "\\", handlerElement.AssemblyName, ".dll")); } catch (Exception exception1) { Exception exception = exception1; throw new HandlerLoadException(expertInfo, "Requested assembly not found", exception); } try { type = assembly.GetType(handlerElement.TypeName); } catch (Exception exception3) { Exception exception2 = exception3; throw new HandlerLoadException(expertInfo, "Requested type not found in assembly.", exception2); } try { mqlHandler = (MqlHandler)Activator.CreateInstance(type); } catch (Exception exception5) { Exception exception4 = exception5; throw new HandlerLoadException(expertInfo, "Can't create intance of expert.", exception4); } try { foreach (ParameterElement inputParameter in handlerElement.InputParameters) { PropertyInfo property = mqlHandler.GetType().GetProperty(inputParameter.PropertyName); Type propertyType = property.PropertyType; object obj = Convert.ChangeType(inputParameter.PropertyValue, propertyType); property.SetValue(mqlHandler, obj); } } catch (Exception exception7) { Exception exception6 = exception7; throw new HandlerLoadException(expertInfo, "Can't set input parameters for expert", exception6); } HandlerProvider handlerProvider = new HandlerProvider(mqlHandler, handlerElement, expertInfo); HandlerProvider._storage.TryAdd(expertInfo.Discriminator, handlerProvider); item = handlerProvider; } else { throw new HandlerLoadException(expertInfo, "Requested application not found in configuration", null); } } else { item = HandlerProvider._storage[expertInfo.Discriminator]; } } return item; }
internal static HandlerProvider GetOrCreate(TradePlatform.MT4.Core.Utils.ExpertInfo expertInfo, HostElement hostElement) { Assembly assembly; Type type; MqlHandler mqlHandler; HandlerProvider item; lock (HandlerProvider._storageLocker) { if (!HandlerProvider._storage.ContainsKey(expertInfo.Discriminator)) { if (hostElement.Handlers.ContainsKey(expertInfo.HandlerName)) { HandlerElement handlerElement = hostElement.Handlers[expertInfo.HandlerName]; try { assembly = Assembly.LoadFile(string.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "\\", handlerElement.AssemblyName, ".dll")); } catch (Exception exception1) { Exception exception = exception1; throw new HandlerLoadException(expertInfo, "Requested assembly not found", exception); } try { type = assembly.GetType(handlerElement.TypeName); } catch (Exception exception3) { Exception exception2 = exception3; throw new HandlerLoadException(expertInfo, "Requested type not found in assembly.", exception2); } try { mqlHandler = (MqlHandler)Activator.CreateInstance(type); } catch (Exception exception5) { Exception exception4 = exception5; throw new HandlerLoadException(expertInfo, "Can't create intance of expert.", exception4); } try { foreach (ParameterElement inputParameter in handlerElement.InputParameters) { PropertyInfo property = mqlHandler.GetType().GetProperty(inputParameter.PropertyName); Type propertyType = property.PropertyType; object obj = Convert.ChangeType(inputParameter.PropertyValue, propertyType); property.SetValue(mqlHandler, obj); } } catch (Exception exception7) { Exception exception6 = exception7; throw new HandlerLoadException(expertInfo, "Can't set input parameters for expert", exception6); } HandlerProvider handlerProvider = new HandlerProvider(mqlHandler, handlerElement, expertInfo); HandlerProvider._storage.TryAdd(expertInfo.Discriminator, handlerProvider); item = handlerProvider; } else { throw new HandlerLoadException(expertInfo, "Requested application not found in configuration", null); } } else { item = HandlerProvider._storage[expertInfo.Discriminator]; } } return(item); }