protected void btnSubscribe_Click(object sender, ImageClickEventArgs e) { var objEventSubscriptionController = new EventSubscriptionController(); if (btnSubscribe.ImageUrl == IconController.IconURL("Unchecked")) { var objEventSubscription = new EventSubscriptionInfo(); objEventSubscription.SubscriptionID = -1; objEventSubscription.ModuleID = ModuleId; objEventSubscription.PortalID = PortalId; objEventSubscription.UserID = UserId; objEventSubscriptionController.EventsSubscriptionSave(objEventSubscription); btnSubscribe.Visible = true; lblSubscribe.Text = Localization.GetString("lblUnsubscribe", LocalResourceFile); btnSubscribe.AlternateText = Localization.GetString("MenuUnsubscribe", LocalResourceFile); btnSubscribe.ToolTip = Localization.GetString("MenuTTUnsubscribe", LocalResourceFile); btnSubscribe.ImageUrl = IconController.IconURL("Checked"); } else { objEventSubscriptionController.EventsSubscriptionDeleteUser(UserId, ModuleId); btnSubscribe.Visible = true; lblSubscribe.Text = Localization.GetString("lblSubscribe", LocalResourceFile); btnSubscribe.AlternateText = Localization.GetString("MenuSubscribe", LocalResourceFile); btnSubscribe.ToolTip = Localization.GetString("MenuTTSubscribe", LocalResourceFile); btnSubscribe.ImageUrl = IconController.IconURL("Unchecked"); } }
/// <summary> /// Client source has raised an event, process it. /// </summary> internal object ProcessEventRaised(ClientEventsHandler client, ClientEventsHandler.EventHandlingInformation eventSubscriptionInfo, Type returnType, object[] parameters) { if (string.IsNullOrEmpty(eventSubscriptionInfo.GeneratedMethodInfo.EventName)) { // Establish the name of the event. eventSubscriptionInfo.GeneratedMethodInfo.EventName = GeneralHelper.GetEventMethodExtendedName(eventSubscriptionInfo.EventInfo, false); } EventSubscriptionInfo eventSubscription = null; if (string.IsNullOrEmpty(eventSubscriptionInfo.GeneratedMethodInfo.EventName) == false && _eventSubscriptions.TryGetValue(eventSubscriptionInfo.GeneratedMethodInfo.EventName, out eventSubscription)) {// OK, to perform the calls. // Process specific subscribers foreach (KeyValuePair <ClientId, EventSubscriptionInfo.ClientEventSubscriptionInfo> pair in eventSubscription.GetReceivers(client.Client.Id, true)) { foreach (KeyValuePair <MethodInfo, int> subPair in pair.Value.Data) { for (int i = 0; i < subPair.Value; i++) { // May need to raise multiple times. if (client.Client.Id != pair.Key) { // Filter out subscriptions by the one that raised it. ProcessEventCall(client.Client.Id, pair.Key, subPair.Key, parameters); } } } } // Process subscribe to all. foreach (KeyValuePair <ClientId, EventSubscriptionInfo.ClientEventSubscriptionInfo> pair in eventSubscription.GetReceivers(client.Client.Id, false)) { foreach (KeyValuePair <MethodInfo, int> subPair in pair.Value.Data) { for (int i = 0; i < subPair.Value; i++) { // May need to raise multiple times. if (client.Client.Id != pair.Key) { // Filter out subscriptions by the one that raised it. ProcessEventCall(client.Client.Id, pair.Key, subPair.Key, parameters); } } } } } else {// No subscription(s) for this event. #if Matrix_Diagnostics InstanceMonitor.Info(string.Format("Event raised [{0}] had no subscribers.", eventSubscriptionInfo.GeneratedMethodInfo.EventName), TracerItem.PriorityEnum.Trivial); #endif } // Return a default value. return(ProxyTypeManager.GetTypeDefaultValue(returnType)); }
private void DoAddSubscription(Type handlerType, string eventName, bool isDynamic) { if (!HasSubscriptionsForEvent(eventName)) { _handlers.Add(eventName, new List <EventSubscriptionInfo>()); } if (_handlers[eventName].Any(s => s.HandlerType == handlerType)) { throw new ArgumentException($"Handler Type {handlerType.Name} already registered for '{eventName}'", nameof(handlerType)); } _handlers[eventName].Add(isDynamic ? EventSubscriptionInfo.Dynamic(handlerType) : EventSubscriptionInfo.Typed(handlerType)); }
private void DoRemoveSubscription(string eventName, EventSubscriptionInfo subsToRemove) { if (subsToRemove != null) { _handlers[eventName].Remove(subsToRemove); if (!_handlers[eventName].Any()) { _handlers.Remove(eventName); var eventType = _eventTypes.SingleOrDefault(e => e.Name == eventName); if (eventType != null) { _eventTypes.Remove(eventType); } RaiseOnEventRemoved(eventName); } } }
/// <summary> /// Registra o evento para a entidade. /// </summary> /// <typeparam name="TEvent">Tipo da classe do evento.</typeparam> /// <typeparam name="TExecuteSubscription">Tipo da inscrição de execução.</typeparam> /// <typeparam name="TArgs">Tipo dos argumentos do evento.</typeparam> /// <param name="entityType">Nome da entidade associada.</param> /// <param name="info"></param> private Domain.SubscriptionToken RegisterEvent <TEvent, TExecuteSubscription, TArgs>(Reflection.TypeName entityType, EntityEventInfo info) where TEvent : Domain.CompositeDomainEvent <TArgs>, new() where TExecuteSubscription : Domain.IExecuteSubscription <TArgs> where TArgs : IEntityEventArgs { TExecuteSubscription subscription = default(TExecuteSubscription); try { subscription = Extensions.ExtensionServiceLocator.Current.GetInstance <TExecuteSubscription>(info.ExportId); } catch (Exception ex) { ex = new RegisterEntityEventException(ResourceMessageFormatter.Create(() => Properties.Resources.EntityEventManager_GetEventTypeImplementationError, info.EventType.ToString(), entityType, info.ExportId), ex); OnRegisterEventInfoError(entityType, info, ex); return(null); } var subscriptionInfo = new EventSubscriptionInfo <TArgs>(info, entityType, subscription); return(Domain.DomainEvents.Instance.GetEvent <TEvent>().Subscribe(subscriptionInfo.Execute, Domain.DomainEventThreadOption.PublisherThread, true, subscriptionInfo.CanExecute, false, subscriptionInfo.ToString())); }
void ISuperPoolIntercom.ProcessSubscriptionUpdate(EventSubscriptionRequest subscriptionRequest) { // Filter request, since it may not be related at all to this super pool. bool clientFound = false; ReadOnlyCollection <ClientId> sources = subscriptionRequest.EventsSources; if (sources == null) {// Null value indicates a subscirption to all possible sources. clientFound = true; } else { foreach (ClientId id in sources) { if (_clients.ContainsKey(id)) { clientFound = true; break; } } } // Check the sources and the SenderId, before dumping event. if (clientFound == false && subscriptionRequest.SenderId.IsLocalClientId == false) { #if Matrix_Diagnostics InstanceMonitor.Info("Subscription request received [" + subscriptionRequest.ToString() + "], ignored since not related."); #endif return; } else { #if Matrix_Diagnostics InstanceMonitor.Info("Subscription request received [" + subscriptionRequest.ToString() + "] and processing..."); #endif } EventSubscriptionInfo methodSubscription = null; if (_eventSubscriptions.TryGetValue(subscriptionRequest.ExtendedEventName, out methodSubscription) == false) { lock (_syncRoot) { if (_eventSubscriptions.TryGetValue(subscriptionRequest.ExtendedEventName, out methodSubscription) == false) {// Add a new method subscription info. methodSubscription = new EventSubscriptionInfo(subscriptionRequest.ExtendedEventName); _eventSubscriptions.Add(subscriptionRequest.ExtendedEventName, methodSubscription); } } } if (methodSubscription == null) { #if Matrix_Diagnostics InstanceMonitor.OperationError("Failed to find method subscription, subscription failed."); #endif return; } // Apply the requests locally. methodSubscription.SubscriptionUpdate(subscriptionRequest); }