/// <summary> /// Initializes a new instance of the <see cref="HandlerRegisteredArgs"/> /// class. /// </summary> /// <param name="handler">The <see cref="LoadedHandler"/> loaded from /// the factory.</param> /// <exception cref="ArgumentNullException">handler is null.</exception> public HandlerRegisteredArgs(LoadedHandler handler) { if (handler == null) { throw new ArgumentNullException("handler"); } Handler = handler; }
/// <summary> /// Creates the appropriate results handler for the given /// identifier. /// </summary> /// <param name="identifier">The identifier of the handler.</param> /// <returns>The <see cref="IJobResultsHandler"/> associated with /// the given identifier.</returns> public IJobResultsHandler CreateHandler(string identifier) { if (_handlers.ContainsKey(identifier)) { LoadedHandler h = _handlers[identifier]; return((IJobResultsHandler)h.Handler.Clone()); } else { return(null); } }
/// <summary> /// Registers a new handler within this factory /// </summary> /// <param name="t">The type of the handler</param> /// <param name="id">The identifier for the handler</param> private void _registerHandler(Type t, string id) { LoadedHandler h = new LoadedHandler((IJobResultsHandler)Activator.CreateInstance(t)); object[] nameAttr = t.GetCustomAttributes(typeof(DisplayNameAttribute), false); if (nameAttr.Any() && nameAttr.First() is DisplayNameAttribute) { DisplayNameAttribute a = (DisplayNameAttribute)nameAttr[0]; h.DisplayName = a.DisplayName; } _handlers.Add(id, h); if (HandlerRegistered != null) { HandlerRegistered(this, new HandlerRegisteredArgs(h)); } }