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 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; }
private HandlerProvider(MqlHandler mqlHandler, HandlerElement handlerElement, ExpertInfo expertInfo) { _mqlHandler = mqlHandler; _mqlHandler.CallMqlInternal = OnCallMqlMethod; HandlerConfiguration = handlerElement; ExpertInfo = expertInfo; }
public void LoadConfiguration() { EventsSection settings = Upac.Events.Configuration.ConfigurationManager.Settings; Assert.IsNotNull(settings); bool enabled = settings.Enabled; Assert.IsTrue(enabled); EventCollection collection = settings.Events; Assert.IsNotNull(collection); int count = collection.Count; Assert.AreEqual(2, count); EventElement element = collection[0]; Assert.IsTrue(element.Enabled); Assert.AreEqual("New", element.TargetEvent); Assert.AreEqual("umbraco.cms.businesslogic.web.Document, cms", element.TargetType); Assert.AreEqual(element.TargetType + "." + element.TargetEvent, element.Key); Assert.AreEqual(2, element.Handlers.Count); HandlerElement handler = element.Handlers[0]; Assert.IsTrue(handler.Enabled); element = collection[1]; Assert.IsFalse(element.Enabled); }
public IDictionary <Type, Type> GetCommandHandlers() { IDictionary <Type, Type> commandHandlerDictionary = new Dictionary <Type, Type>(); HandlerElementCollection handlerElements = EAppRuntime.Instance.CurrentApp.ConfigSource.Config.Handlers; if (handlerElements != null && handlerElements.Count > 0) { for (int handlerIndex = 0; handlerIndex < handlerElements.Count; handlerIndex++) { HandlerElement handlerElement = handlerElements[handlerIndex]; string handlerName = handlerElement.Name; string handlerTypeName = handlerElement.Type; Type handlerType = Type.GetType(handlerTypeName); var commandHandlerInterfaceQuery = from c in handlerType.GetInterfaces() where c.IsGenericType && c.GetGenericTypeDefinition() == typeof(ICommandHandler <>) select c; foreach (var commandHandlerInterface in commandHandlerInterfaceQuery) { Type commandType = commandHandlerInterface.GetGenericArguments().FirstOrDefault(); if (typeof(ICommand).IsAssignableFrom(commandType)) { commandHandlerDictionary.Add(commandType, handlerType); } } } } return(commandHandlerDictionary); }
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); }