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;
   }
 }
Beispiel #2
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;
 }