/// <summary> /// Renders the server control wrapped in an additional element so that the /// element.innerHTML can be updated after a callback. /// </summary> protected override void Render(HtmlTextWriter writer) { if (EnableCallBack && AddCallBacks && Visible) { EventHandlerManager.AddChildCallBacks(this, EnabledDuringCallBack, TextDuringCallBack, PreCallBackFunction, PostCallBackFunction, CallBackCancelledFunction); } if (!DesignMode) { AnthemNxt.Core.Manager.WriteBeginControlMarker(writer, parentTagName, this); } if (Visible) { base.Render(writer); } if (!DesignMode) { AnthemNxt.Core.Manager.WriteEndControlMarker(writer, parentTagName, this); } }
private void CKSDevPackageInitializer_VSUIReady(object sender, EventArgs data) { // Call out to our event manager to register and handle project events. eventManager = new EventHandlerManager(package); eventManager.RegisterHandlers(); InitialiseDTEDependantObjects(); }
public async Task EventAbiCanBeNull() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(); var coordinator = new EventHandlerManager(mockEventHandlerHistoryDb.Object); await coordinator.HandleAsync(subscription, null, new FilterLog { }); Assert.Single(eventsHandled); }
static void Main(string[] args) { var manager = new EventHandlerManager(); manager.RegisterHandler(new TestEventHandler($"Hello 1")); manager.RegisterHandler(new Test2EventHandler($"Hello 2")); var bus = new EventBus(manager); bus.PublishAsync(new TestEvent()).Wait(); Console.ReadLine(); }
/// <summary> /// Adds the <strong>onclick</strong> attribute to invoke a callback from the client, then renders /// the attributes of the control to the output stream. /// </summary> protected override void AddAttributesToRender(HtmlTextWriter writer) { EventHandlerManager.AddScriptAttribute( this, "onclick", EventHandlerManager.GetCallbackEventReference( this, this.CausesValidation, this.ValidationGroup ) + "return false;" ); base.AddAttributesToRender(writer); }
public async Task DecodesEventFromAbi() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out _); var coordinator = new EventHandlerManager( mockEventHandlerHistoryDb.Object); var logs = new[] { TestContract.SampleTransferLog() }; await coordinator.HandleAsync(subscription, new[] { TestContract.TransferEventAbi }, logs); Assert.Single(eventsHandled); }
public async Task WhenAbisAreNotConfigured_DecodesToGenericEventLog() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out _); var coordinator = new EventHandlerManager( mockEventHandlerHistoryDb.Object); var logs = new[] { new FilterLog() }; await coordinator.HandleAsync(subscription, new ABI.Model.EventABI[0], logs); Assert.Single(eventsHandled); Assert.Empty(eventsHandled[0].Event); }
/// <summary> /// Adds the <strong>onclick</strong> attribute to invoke a callback from the client, then renders /// the attributes of the control to the output stream. /// </summary> protected override void AddAttributesToRender(HtmlTextWriter writer) { EventHandlerManager.AddScriptAttribute( this, "onclick", EventHandlerManager.GetCallbackEventReference( this, this.CausesValidation, this.ValidationGroup, this.ImageUrlDuringCallBack == string.Empty ? string.Empty : this.ResolveUrl(this.ImageUrlDuringCallBack) ) + "return false;" ); base.AddAttributesToRender(writer); }
private async Task <EventSubscription> LoadEventSubscriptionsAsync(IEventSubscriptionDto subscriptionConfig) { var matcher = await EventMatcherFactory.LoadAsync(subscriptionConfig).ConfigureAwait(false); var state = await ConfigurationRepository.EventSubscriptionStates.GetAsync(subscriptionConfig.Id).ConfigureAwait(false); var handlerCoOrdinator = new EventHandlerManager(ConfigurationRepository.EventHandlerHistoryRepo); var subscription = new EventSubscription( subscriptionConfig.Id, subscriptionConfig.SubscriberId, matcher, handlerCoOrdinator, state); await AddEventHandlers(subscription).ConfigureAwait(false); return(subscription); }
/// <summary> /// Adds the <strong>onchange</strong> attribute to invoke a callback from the client, then renders /// the attributes of the control to the output stream. /// </summary> protected override void AddAttributesToRender(HtmlTextWriter writer) { if (AutoCallBack) { EventHandlerManager.AddScriptAttribute( this, "onchange", EventHandlerManager.GetCallbackEventReference( this, this.CausesValidation, this.ValidationGroup ) ); } base.AddAttributesToRender(writer); }
public async Task InjectsStateDataToDecodedEvent() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(); var coordinator = new EventHandlerManager(mockEventHandlerHistoryDb.Object); var logs = new[] { new FilterLog { } }; await coordinator.HandleAsync(subscription, null, logs); Assert.Single(eventsHandled); Assert.Equal(subscription.SubscriberId, eventsHandled[0].State["SubscriberId"]); Assert.Equal(subscription.Id, eventsHandled[0].State["EventSubscriptionId"]); Assert.Equal(1, eventsHandled[0].State["HandlerInvocations"]); Assert.Equal(1, subscription.State.GetInt("EventsHandled")); }
/// <summary> /// Use OnPreRender. AddAttributesToRender is not called in ASP.NET 1.1. /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (AutoCallBack) { EventHandlerManager.AddScriptAttribute( this, "onclick", EventHandlerManager.GetCallbackEventReference( this, this.CausesValidation, this.ValidationGroup ) ); } }
public async Task WritesToHistory() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out List <IEventHandlerHistoryDto> history); var coordinator = new EventHandlerManager( mockEventHandlerHistoryDb.Object); var logs = new[] { new FilterLog { } }; await coordinator.HandleAsync(subscription, null, logs); Assert.Single(eventsHandled); Assert.Single(history); Assert.Equal(subscription.EventHandlers.First().Id, history[0].EventHandlerId); Assert.Equal(eventsHandled[0].Key, history[0].EventKey); }
public async Task WhenOneHandlerReturnsFalseDoesNotInvokeNext() { var handlerOneEvents = new List <DecodedEvent>(); var handlerTwoEvents = new List <DecodedEvent>(); var firstHandler = CreateMockEventHandler(handlerOneEvents, handleSuccessfully: false); var secondHandler = CreateMockEventHandler(handlerTwoEvents); var subscription = CreateMockSubscription(new[] { firstHandler.Object, secondHandler.Object }); var mockEventHandlerHistoryDb = CreateMockHistoryDb(); var coordinator = new EventHandlerManager(mockEventHandlerHistoryDb.Object); var logs = new[] { new FilterLog { } }; await coordinator.HandleAsync(subscription, null, logs); Assert.Single(handlerOneEvents); Assert.Empty(handlerTwoEvents); }
public async Task IgnoresEventsWithInvalidNumberOfIndexes() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out List <IEventHandlerHistoryDto> history); var coordinator = new EventHandlerManager( mockEventHandlerHistoryDb.Object); var log = TestContract.SampleTransferLog(); // deliberately make topic count inconsistent with abi log.Topics = log.Topics.Take(log.Topics.Length - 1).ToArray(); var logs = new[] { log }; var eventAbi = TestContract.TransferEventAbi; await coordinator.HandleAsync(subscription, new[] { eventAbi }, logs); Assert.Empty(eventsHandled); }
/// <summary> /// Adds the <strong>onclick</strong> attribute to invoke a callback from the client, then renders /// the attributes of the control to the output stream. /// </summary> protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); if (this.DisplayMode == ASP.BulletedListDisplayMode.LinkButton) { for (int index = 0; index < this.Items.Count; index++) { ASP.ListItem item = this.Items[index]; EventHandlerManager.AddScriptAttribute( this, item, "onclick", EventHandlerManager.GetCallbackEventReference( this, index.ToString(), this.CausesValidation, this.ValidationGroup ) + "return false;" ); } } }
/// <summary> /// Adds the <strong>onclick</strong> attribute to each item to invoke a callback from the client, /// then renders the item. /// </summary> protected override void RenderItem(ASP.ListItemType itemType, int repeatIndex, ASP.RepeatInfo repeatInfo, HtmlTextWriter writer) { if (AutoCallBack) { ASP.ListItem item = this.Items[repeatIndex]; if (item.Selected) { item.Attributes.Remove("onclick"); } else { item.Attributes["onclick"] = EventHandlerManager.GetCallbackEventReference( this, repeatIndex.ToString(), this.CausesValidation, this.ValidationGroup ); } } base.RenderItem(itemType, repeatIndex, repeatInfo, writer); }
public async Task WithMultipleAbis_DecodesToFirstMatchingAbi() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out _); var coordinator = new EventHandlerManager( mockEventHandlerHistoryDb.Object); var logs = new[] { TestContract.SampleTransferLog() }; var abis = new[] { TestContract.ApprovalEventAbi, TestContract.TransferEventAbi }; await coordinator.HandleAsync(subscription, abis, logs); Assert.Single(eventsHandled); Assert.Equal( TestContract.TransferEventAbi.InputParameters.Length, eventsHandled[0].Event.Count); }
public async Task ChecksHistoryToPreventDuplication() { var subscription = CreateMockSubscription(out List <DecodedEvent> eventsHandled); var mockEventHandlerHistoryDb = CreateMockHistoryDb(out List <IEventHandlerHistoryDto> history); var coordinator = new EventHandlerManager(mockEventHandlerHistoryDb.Object); var logs = new[] { new FilterLog { } }; //fake an entry in the history history.Add( new EventHandlerHistoryDto { EventHandlerId = subscription.EventHandlers.First().Id, EventKey = new DecodedEvent(null, logs[0]).Key }); await coordinator.HandleAsync(subscription, null, logs); Assert.Empty(eventsHandled); Assert.Single(history); }
/// <summary> /// Adds the <strong>onclick</strong> attribute to invoke a callback from the client. /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (AutoCallBack) { EventHandlerManager.AddScriptAttribute( this, "onclick", string.Format( "AnthemListControl_OnClick(event,{0},'{1}','{2}',{3},{4},{5},{6});", this.CausesValidation ? "true" : "false", this.ValidationGroup, this.TextDuringCallBack, this.EnabledDuringCallBack ? "true" : "false", (this.PreCallBackFunction == null || this.PreCallBackFunction.Length == 0) ? "null" : this.PreCallBackFunction, (this.PostCallBackFunction == null || this.PostCallBackFunction.Length == 0) ? "null" : this.PostCallBackFunction, (this.CallBackCancelledFunction == null || this.CallBackCancelledFunction.Length == 0) ? "null" : this.CallBackCancelledFunction ) ); // Disable postback so there is no double callback+postback ASP.CheckBox controlToRepeat = (ASP.CheckBox) this.Controls[0]; controlToRepeat.AutoPostBack = false; } }
/// <summary> /// Overrides the pretty useless ASP.NET 2.0 rendering of an ImageMap and replaces with a Anthem.NET capable (replaces the POST type maps) control that /// is also fully XHTML compatible. /// </summary> /// <param name="writer"></param> protected override void Render(HtmlTextWriter writer) { // Anthem preamble if (!DesignMode) { AnthemNxt.Core.Manager.WriteBeginControlMarker(writer, "span", this); } if (Visible) { // Manually render the underlying image due to not being able to skip the base.Render imagemap implementation RenderUnderlyingImage(writer); // Only output if there is at least one hotspot if (Enabled && !base.IsEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } if (HotSpots.Count > 0) { // Imagemap preamble, creating a new "sub" ID for the map which is referred to by the image string id = "ImageMap" + this.ClientID; writer.AddAttribute(HtmlTextWriterAttribute.Id, id); writer.AddAttribute(HtmlTextWriterAttribute.Name, id); writer.RenderBeginTag(HtmlTextWriterTag.Map); int i = 0; foreach (HotSpot spot in HotSpots) { writer.AddAttribute(HtmlTextWriterAttribute.Shape, GetHotSpotMarkupName(spot), false); writer.AddAttribute(HtmlTextWriterAttribute.Coords, spot.GetCoordinates()); // What kind of hotspot is this? POST of course is now routed through Anthem. switch (spot.HotSpotMode) { case HotSpotMode.NotSet: throw new NotSupportedException("HotSpotMode.NotSet not supported"); case HotSpotMode.PostBack: if (Page != null) { Page.VerifyRenderingInServerForm(this); } // Registers the click to fire back via AJAX writer.AddAttribute(HtmlTextWriterAttribute.Onclick, EventHandlerManager.GetCallbackEventReference( this, // Reference to this ICallbackControl spot.PostBackValue, // The event argument false, // Causes validation string.Empty, // Validation group string.Empty // Image during callback )); // Added otherwise most browsers won't render the map with the correct mouse cursor writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0);"); break; case HotSpotMode.Navigate: writer.AddAttribute(HtmlTextWriterAttribute.Href, ResolveClientUrl(spot.NavigateUrl)); if (spot.Target.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Target, spot.Target); } break; case HotSpotMode.Inactive: writer.AddAttribute("nohref", "true"); break; } // Add general hotspot attributes writer.AddAttribute(HtmlTextWriterAttribute.Title, spot.AlternateText); writer.AddAttribute(HtmlTextWriterAttribute.Alt, spot.AlternateText); if (AccessKey.Length > 0) { writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey); } if (TabIndex != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, spot.TabIndex.ToString()); } // Hotspot postamble writer.RenderBeginTag(HtmlTextWriterTag.Area); writer.RenderEndTag(); i++; } // Imagemap postamble writer.RenderEndTag(); } } // Anthem postamble if (!DesignMode) { AnthemNxt.Core.Manager.WriteEndControlMarker(writer, "span", this); } }