public RoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { this.Name = name; this.RoutingStrategy = routingStrategy; this.HandlerType = handlerType; this.OwnerType = ownerType; }
/// <summary> /// Registers a <see cref="RoutedEvent"/> /// with the given parameters /// </summary> /// <remarks> /// <see cref="RoutedEvent.Name"/> must be /// unique within the <see cref="RoutedEvent.OwnerType"/> /// (super class types not considered when talking about /// uniqueness) and cannot be null <para/> /// <see cref="RoutedEvent.HandlerType"/> must be a /// type of delegate and cannot be null <para/> /// <see cref="RoutedEvent.OwnerType"/> must be any /// object type and cannot be null <para/> /// <para/> /// /// NOTE: Caller must be the static constructor of the /// <see cref="RoutedEvent.OwnerType"/> - /// enforced by stack walk /// </remarks> /// <param name="name"> /// <see cref="RoutedEvent.Name"/> /// </param> /// <param name="routingStrategy"> /// <see cref="RoutedEvent.RoutingStrategy"/> /// </param> /// <param name="handlerType"> /// <see cref="RoutedEvent.HandlerType"/> /// </param> /// <param name="ownerType"> /// <see cref="RoutedEvent.OwnerType"/> /// </param> /// <returns> /// The new registered <see cref="RoutedEvent"/> /// </returns> /// <ExternalAPI/> public static RoutedEvent RegisterRoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { if (name == null) { throw new ArgumentNullException("name"); } if (routingStrategy != RoutingStrategy.Tunnel && routingStrategy != RoutingStrategy.Bubble && routingStrategy != RoutingStrategy.Direct) { throw new System.ComponentModel.InvalidEnumArgumentException("routingStrategy", (int)routingStrategy, typeof(RoutingStrategy)); } if (handlerType == null) { throw new ArgumentNullException("handlerType"); } if (ownerType == null) { throw new ArgumentNullException("ownerType"); } if (GlobalEventManager.GetRoutedEventFromName(name, ownerType, false) != null) { throw new ArgumentException(SR.Get(SRID.DuplicateEventName, name, ownerType)); } return GlobalEventManager.RegisterRoutedEvent(name, routingStrategy, handlerType, ownerType); }
internal RoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { Name = name; RoutingStrategy = routingStrategy; HandlerType = handlerType; OwnerType = ownerType; }
public RoutingContext(OutgoingMessage messageToDispatch, RoutingStrategy routingStrategy, IBehaviorContext parentContext) : this(messageToDispatch, new[] { routingStrategy }, parentContext) { }
// Registers a RoutedEvent with the given details // NOTE: The Name must be unique within the given OwnerType internal static RoutedEvent RegisterRoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { Debug.Assert(GetRoutedEventFromName(name, ownerType, false) == null, "RoutedEvent name must be unique within a given OwnerType"); lock (Synchronized) { // Create a new RoutedEvent // Requires GlobalLock to access _countRoutedEvents RoutedEvent routedEvent = new RoutedEvent( name, routingStrategy, handlerType, ownerType); // Increment the count for registered RoutedEvents // Requires GlobalLock to access _countRoutedEvents _countRoutedEvents++; AddOwner(routedEvent, ownerType); return routedEvent; } }
internal RoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { _name = name; _routingStrategy = routingStrategy; _handlerType = handlerType; _ownerType = ownerType; }
internal RoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("'name' property cannot be null or an empty string."); } if (handlerType == null) { throw new ArgumentNullException("handlerType"); } if (!typeof(Delegate).IsAssignableFrom(handlerType)) { throw new ArgumentException("'handlerType' must be a delegate type."); } if (ownerType == null) { throw new ArgumentNullException("ownerType"); } this.Name = name; this.RoutingStrategy = routingStrategy; this.HandlerType = handlerType; this.OwnerType = ownerType; }
/// <summary> /// Creates a <see cref="IRoutingContext" /> based on the current context. /// </summary> public static IRoutingContext CreateRoutingContext(this StageConnector<IAuditContext, IRoutingContext> stageConnector, OutgoingMessage outgoingMessage, RoutingStrategy routingStrategy, IAuditContext sourceContext) { Guard.AgainstNull(nameof(outgoingMessage), outgoingMessage); Guard.AgainstNull(nameof(routingStrategy), routingStrategy); Guard.AgainstNull(nameof(sourceContext), sourceContext); return new RoutingContext(outgoingMessage, routingStrategy, sourceContext); }
public static RoutedEvent RegisterRoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { return new RoutedEvent(name, routingStrategy, handlerType, ownerType); }
/// <summary> /// Initializes a new instance of the <see cref="RoutedEvent"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="routingStrategy">The routing strategy.</param> /// <param name="handlerType">Type of the handler.</param> /// <param name="ownerType">Type of the owner.</param> internal RoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { this.Name = name; this.RoutingStrategy = routingStrategy; this.HandlerType = handlerType; this.OwnerType = ownerType; this.GlobalIndex = GlobalEventManager.GetNextAvailableGlobalIndex(this); }
public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { lock (Synchronized) { var routedEvent = new RoutedEvent(name, routingStrategy, handlerType, ownerType); AddOwner(routedEvent, ownerType); return routedEvent; } }
/// <summary> /// Registers a new routed event. /// </summary> /// <param name="name">The routed event's name.</param> /// <param name="uvssName">The routed event's name within the UVSS styling system.</param> /// <param name="routingStrategy">The routed event's routing strategy.</param> /// <param name="delegateType">The routed event's delegate type.</param> /// <param name="ownerType">The routed event's owner type.</param> /// <returns>A <see cref="RoutedEvent"/> instance which represents the registered routed event.</returns> public static RoutedEvent Register(String name, String uvssName, RoutingStrategy routingStrategy, Type delegateType, Type ownerType) { Contract.Require(name, "name"); Contract.Require(delegateType, "delegateType"); Contract.Require(ownerType, "ownerType"); var evt = new RoutedEvent(reid++, name, uvssName, routingStrategy, delegateType, ownerType); RegisterInternal(evt, ownerType); return evt; }
internal RoutedEvent (string name, Type handlerType, Type ownerType, RoutingStrategy routingStrategy) { this.name = name; this.handlerType = handlerType; this.ownerType = ownerType; this.routingStrategy = routingStrategy; }
/// <summary> /// Initializes a new instance of the <see cref="RoutedEvent"/> class. /// </summary> /// <param name="id">The event's unique identifier within the routed events system.</param> /// <param name="name">The routed event's name.</param> /// <param name="uvssName">The dependency property's name within the UVSS styling system.</param> /// <param name="routingStrategy">The routed event's routing strategy.</param> /// <param name="delegateType">The routed event's delegate type.</param> /// <param name="ownerType">The routed event's owner type.</param> internal RoutedEvent(Int64 id, String name, String uvssName, RoutingStrategy routingStrategy, Type delegateType, Type ownerType) { this.id = id; this.name = name; this.uvssName = uvssName ?? UvssNameGenerator.GenerateUvssName(name); this.routingStrategy = routingStrategy; this.delegateType = delegateType; this.ownerType = ownerType; this.invocationDelegate = RoutedEventInvocation.CreateInvocationDelegate(this); this.raisedNotificationServer = new RoutedEventRaisedNotificationServer(this); }
public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { if (string.IsNullOrEmpty(name)) throw new ArgumentException("name"); if (null == handlerType) throw new ArgumentNullException("handlerType"); if (null == ownerType) throw new ArgumentNullException("ownerType"); // RoutedEventKey key = new RoutedEventKey(name, ownerType); if (routedEvents.ContainsKey(key)) { throw new InvalidOperationException("This routed event is already registered."); } RoutedEvent routedEvent = new RoutedEvent(handlerType, name, ownerType, routingStrategy); RoutedEventInfo routedEventInfo = new RoutedEventInfo(routedEvent); routedEvents.Add(key, routedEventInfo); return routedEvent; }
public static RoutedEvent RegisterRoutedEvent (string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { RoutedEvent re = new RoutedEvent (name, handlerType, ownerType, routingStrategy); Dictionary<string, RoutedEvent> events; if (eventsByType.ContainsKey (ownerType)) { events = eventsByType[ownerType]; } else { events = eventsByType[ownerType] = new Dictionary<string, RoutedEvent>(); } if (events.ContainsKey (name)) throw new InvalidOperationException (String.Format ("Type '{0}' already has routed event '{1}' registered.", ownerType, name)); events[name] = re; return re; }
public RoutedStore(string storeName, ClientConfig config, Cluster cluster, IDictionary<int, Store> clusterMap, RoutingStrategy routingStrategy) { if (string.IsNullOrEmpty(storeName)) throw new ArgumentNullException("storeName", "storeName cannot be null."); if (null == config) throw new ArgumentNullException("config", "config cannot be null."); if (null == cluster) throw new ArgumentNullException("cluster", "cluster cannot be null."); if (null == clusterMap) throw new ArgumentNullException("clusterMap", "clusterMap cannot be null."); if (null == routingStrategy) throw new ArgumentNullException("routingStrategy", "routingStrategy cannot be null."); _storeName = storeName; _config = config; _cluster = cluster; _clusterMap = clusterMap; _routingStrategy = routingStrategy; }
/// <summary> /// Create a new routed event. /// /// You have to promise not to duplicate another event name in the system, /// or you will be sorry. /// </summary> /// <param name="name"></param> /// <param name="routingStrategy"></param> /// <param name="handlerType"></param> public RoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType ) { _name = name; _routingStrategy = routingStrategy; _handlerType = handlerType; lock (typeof(GlobalLock)) { if (_eventCount >= Int32.MaxValue) { throw new InvalidOperationException("too many events"); } _globalIndex = _eventCount++; } }
/// <summary> /// Initializes a new instance of the <see cref="WebServer" /> class. /// /// Default settings are Regex RoutingStrategy and EmbedIO HttpListenerMode. /// </summary> /// <remarks> /// <c>urlPrefix</c> must be specified as something similar to: http://localhost:9696/ /// Please notice the ending slash. -- It is important. /// </remarks> /// <param name="urlPrefix">The URL prefix.</param> /// <param name="strategy">The strategy.</param> public WebServer(string urlPrefix, RoutingStrategy strategy = RoutingStrategy.Regex) : this(new[] { urlPrefix }, strategy) { // placeholder }
public SiteRoutingStrategy(RoutingStrategy originalRoutingStrategy, string[] sites) { this.originalRoutingStrategy = originalRoutingStrategy; this.sites = sites; }
public static RoutedEvent Register <TOwner, TEventArgs>(string name, RoutingStrategy routing) where TEventArgs : RoutedEventArgs { return(EventManager.RegisterRoutedEvent(name, routing, typeof(EventHandler <TEventArgs>), typeof(TOwner))); }
/// <summary> /// Initializes a new instance of the <see cref="WebServer"/> class. /// /// Default settings are Regex RoutingStrategy and EmbedIO HttpListenerMode. /// </summary> /// <remarks> /// <c>urlPrefixes</c> must be specified as something similar to: http://localhost:9696/ /// Please notice the ending slash. -- It is important. /// </remarks> /// <param name="urlPrefixes">The URL prefix.</param> /// <param name="routingStrategy">The routing strategy.</param> /// <exception cref="ArgumentException">Argument urlPrefix must be specified.</exception> public WebServer(string[] urlPrefixes, RoutingStrategy routingStrategy = RoutingStrategy.Regex) : this(urlPrefixes, routingStrategy, HttpListenerFactory.Create(HttpListenerMode.EmbedIO)) { // placeholder }
public void TestRoutedEvent() { // test argument null exception Assert.Throws<ArgumentNullException>(() => EventManager.RegisterRoutedEvent<RoutedEventArgs>(null, RoutingStrategy.Tunnel, typeof(EventManagerTests))); Assert.Throws<ArgumentNullException>(() => EventManager.RegisterRoutedEvent<RoutedEventArgs>("Test", RoutingStrategy.Tunnel, null)); // test InvalidOperationException when element is already added Assert.Throws<InvalidOperationException>(() => EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestBasicHandler", RoutingStrategy.Tunnel, typeof(EventManagerTests))); Assert.Throws<InvalidOperationException>(() => EventManager.RegisterRoutedEvent<MyTestRoutedEventArgs>("TestBasicHandler", RoutingStrategy.Tunnel, typeof(EventManagerTests))); var testBasicHandlerOtherOwner = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestBasicHandler", RoutingStrategy.Tunnel, typeof(EventManager)); // should not throw owner type is different // check the values of the returned routed event const string eventName = "CheckValues"; const RoutingStrategy strategy = RoutingStrategy.Bubble; var ownerType = typeof(EventManagerTests); var checkValues = EventManager.RegisterRoutedEvent<RoutedEventArgs>(eventName, strategy, ownerType); try { Assert.Equal(eventName, checkValues.Name); Assert.Equal(strategy, checkValues.RoutingStrategy); Assert.Equal(ownerType, checkValues.OwnerType); Assert.Equal(typeof(RoutedEventArgs), checkValues.HandlerSecondArgumentType); // check the get routed events functions Assert.Equal(4, EventManager.GetRoutedEvents().Length - originalRoutedEventCount); Assert.Contains(checkValues, EventManager.GetRoutedEvents()); Assert.Contains(testBasicHandler, EventManager.GetRoutedEvents()); Assert.Contains(testSpecialHandler, EventManager.GetRoutedEvents()); Assert.Contains(testBasicHandlerOtherOwner, EventManager.GetRoutedEvents()); } finally { EventManager.UnregisterRoutedEvent(checkValues); EventManager.UnregisterRoutedEvent(testBasicHandlerOtherOwner); } // test ownership var testChild = EventManager.RegisterRoutedEvent<RoutedEventArgs>("Test", RoutingStrategy.Tunnel, typeof(Child)); var testGrandChild = EventManager.RegisterRoutedEvent<RoutedEventArgs>("Test2", RoutingStrategy.Tunnel, typeof(GrandChild)); try { Assert.Empty(EventManager.GetRoutedEventsForOwner(typeof(Parent))); Assert.Single(EventManager.GetRoutedEventsForOwner(typeof(Child))); Assert.Equal(testChild, EventManager.GetRoutedEventsForOwner(typeof(Child))[0]); Assert.Equal(2, EventManager.GetRoutedEventsForOwner(typeof(GrandChild)).Length); Assert.Equal(testGrandChild, EventManager.GetRoutedEventsForOwner(typeof(GrandChild))[0]); Assert.Equal(testChild, EventManager.GetRoutedEventsForOwner(typeof(GrandChild))[1]); // test research by name Assert.Null(EventManager.GetRoutedEvent(typeof(Parent), "Test")); Assert.Equal(testChild, EventManager.GetRoutedEvent(typeof(Child), "Test")); Assert.Equal(testChild, EventManager.GetRoutedEvent(typeof(GrandChild), "Test")); Assert.Equal(testGrandChild, EventManager.GetRoutedEvent(typeof(GrandChild), "Test2")); } finally { EventManager.UnregisterRoutedEvent(testChild); EventManager.UnregisterRoutedEvent(testGrandChild); } }
/// <summary> /// Initializes a new instance of the <see cref="WebServer"/> class. /// </summary> /// <param name="port">The port.</param> /// <param name="strategy">The strategy.</param> public WebServer(int port, RoutingStrategy strategy = RoutingStrategy.Wildcard) : this(new[] { "http://*:" + port + "/" }, strategy) { // placeholder }
public static RoutedEvent Register <TEventHandler> (string eventFieldName, RoutingStrategy strategy = RoutingStrategy.Bubble) where TEventHandler : Delegate { return(StaticREUtils.Register <TEventHandler>(eventFieldName, typeof(TOwner), strategy)); }
public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { RoutedEventKey key = new RoutedEventKey(ownerType, name); if (registeredRoutedEvents.ContainsKey(key)) { throw new Granular.Exception("RoutedEvent {0}.{1} is already registered", ownerType.Name, name); } RoutedEvent routedEvent = new RoutedEvent(name, routingStrategy, handlerType, ownerType); registeredRoutedEvents.Add(key, routedEvent); return routedEvent; }
public static RoutedEvent Register(string eventFieldName, RoutingStrategy strategy = RoutingStrategy.Bubble) { return(StaticREUtils.Register(eventFieldName, typeof(TOwner), strategy)); }
/// <summary> /// Initializes a new instance of the <see cref="WebServer"/> class. /// /// Default settings are Regex RoutingStrategy, EmbedIO HttpListenerMode, and binding all /// network interfaces with HTTP protocol with the selected port (http://*:{port}/). /// </summary> /// <param name="port">The port.</param> /// <param name="strategy">The strategy.</param> public WebServer(int port, RoutingStrategy strategy = RoutingStrategy.Regex) : this(new[] { $"http://*:{port}/" }, strategy) { // placeholder }
protected FixtureBase(Action <WebServer> builder, RoutingStrategy routeSrtategy) { Swan.Terminal.Settings.DisplayLoggingMessageType = Swan.LogMessageType.None; _builder = builder; _routeStrategy = routeSrtategy; }
/// <summary> /// Registers a new event with the event system. /// </summary> /// <param name="name">Name of the event. The name must be unique within the owner class. It must not be <c>null</c> or empty.</param> /// <param name="routingStrategy">The routing strategy for this event.</param> /// <param name="handlerType">The type of the event handler. Can not be <c>null</c></param> /// <param name="ownerType">The owner class type of the event. Can not be <c>null</c>.</param> /// <returns></returns> public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { if (name == null) throw new ArgumentNullException("name"); if (handlerType == null) throw new ArgumentNullException("handlerType"); if (ownerType == null) throw new ArgumentNullException("ownerType"); if (String.IsNullOrEmpty(name)) throw new ArgumentException(@"name must not be an empty string", "name"); return GlobalEventManager.RegisterRoutedEvent(name, routingStrategy, handlerType, ownerType); }
/// <summary> /// Initializes a new instance of the <see cref="WebServer" /> class. /// </summary> /// <param name="urlPrefixes">The URL prefix.</param> /// <param name="routingStrategy">The routing strategy.</param> /// <param name="mode">The mode.</param> /// <param name="certificate">The certificate.</param> /// <exception cref="ArgumentException">Argument urlPrefix must be specified.</exception> /// <remarks> /// <c>urlPrefixes</c> must be specified as something similar to: http://localhost:9696/ /// Please notice the ending slash. -- It is important. /// </remarks> public WebServer(string[] urlPrefixes, RoutingStrategy routingStrategy, HttpListenerMode mode, X509Certificate certificate) : this(urlPrefixes, routingStrategy, HttpListenerFactory.Create(mode, certificate)) { // placeholder }
public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { return default(RoutedEvent); }
public RoutedEvent Register <T>(string name, RoutingStrategy routingStrategy) { ValidateEvent <T>(name); return(EventManager.RegisterRoutedEvent(name, routingStrategy, typeof(T), OwnerType)); }
// Constructor for a RoutedEvent (is internal // to the EventManager and is onvoked when a new // RoutedEvent is registered) internal RoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { _name = name; _routingStrategy = routingStrategy; _handlerType = handlerType; _ownerType = ownerType; _globalIndex = GlobalEventManager.GetNextAvailableGlobalIndex(this); }
/// <summary> /// Static method to create webserver instance /// </summary> /// <param name="urlPrefix">The URL prefix.</param> /// <param name="routingStrategy">Matching/Parsing of URL: choose from: Wildcard, Regex, Simple </param> /// <returns>The webserver instance.</returns> public static WebServer Create(string urlPrefix, RoutingStrategy routingStrategy) => new WebServer(urlPrefix, routingStrategy);