Example #1
0
 public void Subscribe <T>(object subscriber, Action <T> action, SubscriptionKind subscriptionKind)
 {
     lock (_sync) {
         EnsureSubscribersList <T>();
         _subscribers[typeof(T)].Add(new WeakDelegate(subscriber, action));
     }
 }
Example #2
0
        // Note since the Target and Method are not set, the default IEquatable implementation does not produce
        // accurate results.
        // DRM: Acutally the IEquatable implementation should be ok -- but need to create unit test to be sure.
        // TODO: Create unit test to verify that the IEquatable implementation for SubscriptionKeyForBinding produces accurate result.

        // Creates a new Binding Request.
        protected SubscriptionKeyGen(
            ExKeyT ownerPropId,
            Type propertyType,
            LocalBindingInfo bindingInfo,
            SubscriptionKind kind,
            SubscriptionPriorityGroup subscriptionPriorityGroup,
            Func <ISubscriptionKeyGen, PSAccessServiceInterface, ISubscription> bindingFactory)
        {
            OwnerPropId  = ownerPropId; // The binding is created on the target, we will go find the source of the events to listen.
            PropertyType = PropertyType;

            SubscriptionKind          = kind;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = SubscriptionTargetKind.GlobalPropId;

            //GenDoWhenChanged = null;
            //Action = null;

            Target_Wrk = WeakRefKey.Empty;
            Method     = null;

            SubscriptionFactory = null;
            BindingFactory      = bindingFactory;
            HasBeenUsed         = false;

            // Properties unique to Binding Subscriptions
            BindingInfo = bindingInfo;
        }
Example #3
0
        // Target and Method. Also used for TypeDelegate and TypedAction.
        public SubscriptionKeyGen(ExKeyT sourcePropId, Type propertyType,
                                  object target, MethodInfo method,
                                  SubscriptionKind kind,
                                  SubscriptionPriorityGroup subscriptionPriorityGroup,
                                  bool keepRef,
                                  Func <ISubscriptionKeyGen, IProvideHandlerDispatchDelegateCaches, ISubscription> subscriptionFactory)
        {
            OwnerPropId  = sourcePropId;
            PropertyType = propertyType;

            SubscriptionKind          = kind;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = GetKindOfTarget(target, keepRef);

            //GenDoWhenChanged = null;
            //Action = null;

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            Target_Wrk = new WeakRefKey(target);
            Method     = method ?? throw new ArgumentNullException(nameof(method));

            SubscriptionFactory = subscriptionFactory ?? CreateSubscriptionGen;
            BindingFactory      = null;
            HasBeenUsed         = false;
        }
Example #4
0
        public MethodSubscriptionKind(MethodInfo method, SubscriptionKind subscriptionKind) : this()
        {
            Method           = method ?? throw new ArgumentNullException(nameof(method));
            SubscriptionKind = subscriptionKind;

            DelegateType = GetDelegateType(method);

            _hashCode = ComputeHashCode();
        }
Example #5
0
        public PropDoWhenChangedField(object target, MethodInfo method, SubscriptionKind subscriptionKind, SubscriptionPriorityGroup priorityGroup,
                                      bool methodIsLocal, Type declaringType, string fullClassName, string instanceKey)
        {
            Target           = target; // ?? throw new ArgumentNullException(nameof(target));
            Method           = method ?? throw new ArgumentNullException(nameof(method));
            SubscriptionKind = subscriptionKind;
            PriorityGroup    = priorityGroup;

            MethodIsLocal = methodIsLocal;
            DeclaringType = declaringType; // ?? throw new ArgumentNullException(nameof(declaringType));
            FullClassName = fullClassName; //  ?? throw new ArgumentNullException(nameof(fullClassName));
            InstanceKey   = instanceKey;   //  ?? throw new ArgumentNullException(nameof(instanceKey));
            MethodName    = method.Name;
        }
        public SubscriptionViewModel(IViewContext clientViewContext, Guid subscriptionId, SubscriptionKind kind, string paramUri)
        {
            _viewContext = new EntileViewContext(clientViewContext);

            _subscriptionId = subscriptionId;
            _viewContext.SetValue("SubscriptionId", _subscriptionId);

            RegisterLinkAction("Unsubscribe", l =>
                                              {
                                                  var action = new UnsubscribeCommand(_viewContext, l.Uri);
                                                  UnsubscribeCommand = action;
                                              });
            _kind = kind;
            _paramUri = paramUri;
        }
Example #7
0
        //public Func<object, EventHandler<PcGenEventArgs>> GetTheDoWhenChangedGenHandlerGetter(PropDoWhenChangedField pdwcf, Type propertyType)
        //{
        //    Type declaringType = pdwcf.DeclaringType ?? throw new ArgumentNullException(nameof(declaringType));

        //    string methodName = pdwcf.MethodName ?? throw new ArgumentNullException(nameof(methodName));

        //    GetGenHandlerRefDelegate GenHandlerRefGetter = GetTheGetGenHandlerDelegate(propertyType);

        //    // Return a function that takes a single input object and returns a reference to the clients EventHandler action.
        //    // The caller does not need to supply the declaringType, nor the methodName, since these are enclosed in the
        //    // new custom function.
        //    return GetTheDoWhenChangedDelegate;

        //    // The declaring type and method name are being enclosed in this nested function,
        //    // which calls the custom delegate: 'GenHandlerRefGetter' just created (or read from the cache.)
        //    EventHandler<PcGenEventArgs> GetTheDoWhenChangedDelegate(object host)
        //    {
        //        EventHandler<PcGenEventArgs> result = GenHandlerRefGetter(host, declaringType, methodName);
        //        return result;
        //    }
        //}

        public MethodInfo GetMethodAndSubKind(PropDoWhenChangedField pdwcf, Type propertyType, string propertyName, out SubscriptionKind subscriptionKind)
        {
            MethodInfo mi = GetMethodInfo(pdwcf.DeclaringType, pdwcf.MethodName);

            if (HasPcGenEventHandlerSignature(mi))
            {
                subscriptionKind = SubscriptionKind.GenHandler;
                return(mi);
            }
            else if (HasPcTypedEventHandlerSignature(mi))
            {
                subscriptionKind = SubscriptionKind.TypedHandler;
                return(mi);
            }
            else
            {
                throw new ArgumentException($"The method: {mi.Name} on class: {mi.DeclaringType.FullName} doesn't match any of the supported signatures.");
            }
        }