/// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns>
        public bool Equals(SubscriptionEventName other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            return(this.Equals(other.SchemaQualifiedEventName));
        }
Esempio n. 2
0
        /// <summary>
        /// Registers a new receiver to receive any raised events of the given type.
        /// </summary>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="receiver">The receiver to add.</param>
        public void AddReceiver(SubscriptionEventName eventName, ISubscriptionEventReceiver receiver)
        {
            Validation.ThrowIfNull(eventName, nameof(eventName));
            Validation.ThrowIfNull(receiver, nameof(receiver));

            lock (_receivers)
            {
                if (!_receivers.ContainsKey(eventName))
                {
                    _receivers.Add(eventName, new HashSet <ISubscriptionEventReceiver>());
                }

                _receivers[eventName].Add(receiver);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Removes the receiver from the list of events to be delivered for the given event type.
        /// </summary>
        /// <param name="eventName">Type of the event.</param>
        /// <param name="receiver">The receiver to remove.</param>
        public void RemoveReceiver(SubscriptionEventName eventName, ISubscriptionEventReceiver receiver)
        {
            if (receiver == null || eventName == null)
            {
                return;
            }

            lock (_receivers)
            {
                if (_receivers.ContainsKey(eventName))
                {
                    if (_receivers[eventName].Contains(receiver))
                    {
                        _receivers[eventName].Remove(receiver);
                    }
                    if (_receivers[eventName].Count == 0)
                    {
                        _receivers.Remove(eventName);
                    }
                }
            }
        }
 /// <summary>
 /// Creates a set of event names representing all the possible forms of the event as defined
 /// by the graph field.
 /// </summary>
 /// <param name="schema">The schema owning the field definition.</param>
 /// <param name="field">The field to create names for.</param>
 /// <returns>IEnumerable&lt;SubscriptionEventName&gt;.</returns>
 public static IEnumerable <SubscriptionEventName> FromGraphField(ISchema schema, ISubscriptionGraphField field)
 {
     Validation.ThrowIfNull(schema, nameof(schema));
     Validation.ThrowIfNull(field, nameof(field));
     return(SubscriptionEventName.FromSchemaTypeAndField(schema.GetType(), field));
 }
 /// <summary>
 /// Creates a set of event names representing all the possible forms of the event as defined
 /// by the grpah field.
 /// </summary>
 /// <typeparam name="TSchema">The type of the schema the graph field exists in.</typeparam>
 /// <param name="field">The field to create names for.</param>
 /// <returns>IEnumerable&lt;SubscriptionEventName&gt;.</returns>
 public static IEnumerable <SubscriptionEventName> FromGraphField <TSchema>(ISubscriptionGraphField field)
     where TSchema : class, ISchema
 {
     Validation.ThrowIfNull(field, nameof(field));
     return(SubscriptionEventName.FromSchemaTypeAndField(typeof(TSchema), field));
 }