示例#1
0
 private HandlerProvider(MqlHandler mqlHandler, HandlerElement handlerElement, ExpertInfo expertInfo)
 {
     _mqlHandler = mqlHandler;
     _mqlHandler.CallMqlInternal = OnCallMqlMethod;
     HandlerConfiguration = handlerElement;
     ExpertInfo = expertInfo;
 }
示例#2
0
 private HandlerProvider(MqlHandler mqlHandler, HandlerElement handlerElement, ExpertInfo expertInfo)
 {
   this._mqlHandler = mqlHandler;
   this._mqlHandler.CallMqlInternal = new Func<string, IEnumerable<string>, string>(this.OnCallMqlMethod);
   this.HandlerConfiguration = handlerElement;
   this.ExpertInfo = expertInfo;
 }
示例#3
0
 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;
   }
 }
 public HandlerLoadException(ExpertInfo expertInfo, string reason, Exception innerException)
     : base(string.Format("Can't load handler: {0}. Failure Context: {1}", reason, expertInfo), innerException)
 {
 }
示例#5
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"));
       }
 }
 public HandlerExecutionException(ExpertInfo expertInfo, Exception innerException)
   : base(string.Format("Handler execution failed with error '{0}'. Failure Context: {1}", (object) innerException.Message, (object) expertInfo), innerException)
 {
 }
示例#7
0
 public MqlErrorException(ExpertInfo expertInfo, MethodCallInfo clientMethodInfo)
   : base(string.Format("MQL returned error: '{0}' for method {1}. Failure Context: {2}", (object) clientMethodInfo.ErrorMessage, (object) clientMethodInfo, (object) expertInfo))
 {
 }
示例#8
0
        internal static HandlerProvider GetOrCreate(ExpertInfo expertInfo, HostElement hostElement)
        {
            Assembly assembly;
            Type type;
            MqlHandler mqlHandler;
            HandlerProvider item;
            lock (_storageLocker)
            {
                if (!_storage.ContainsKey(expertInfo.Discriminator))
                {
                    if (hostElement.Handlers.ContainsKey(expertInfo.HandlerName))
                    {
                        HandlerElement handlerElement = hostElement.Handlers[expertInfo.HandlerName];
                        try
                        {

                            var assemblyPath =
                                Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                             string.Concat(handlerElement.AssemblyName, ".dll"));
                            assembly =
                                Assembly.LoadFile(assemblyPath);
                        }
                        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);
                        }
                        var handlerProvider = new HandlerProvider(mqlHandler, handlerElement, expertInfo);
                        _storage.TryAdd(expertInfo.Discriminator, handlerProvider);
                        item = handlerProvider;
                    }
                    else
                    {
                        throw new HandlerLoadException(expertInfo, "Requested application not found in configuration",
                                                       null);
                    }
                }
                else
                {
                    item = _storage[expertInfo.Discriminator];
                }
            }
            return item;
        }
示例#9
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"));
 }
示例#10
0
        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);
        }
示例#11
0
 private HandlerProvider(MqlHandler mqlHandler, HandlerElement handlerElement, TradePlatform.MT4.Core.Utils.ExpertInfo expertInfo)
 {
     this._mqlHandler = mqlHandler;
     this._mqlHandler.CallMqlInternal = new Func <string, IEnumerable <string>, string>(this.OnCallMqlMethod);
     this.HandlerConfiguration        = handlerElement;
     this.ExpertInfo = expertInfo;
 }