public SubscriberCallbackAttribute(Type eventType, NotifyPriority priority = DEFAULT_PRIORITY, ThreadMode threadMode = DEFAULT_THREAD_MODE) { EventType = eventType; Priority = priority; ThreadMode = threadMode; }
public void Notify(NotificationType type, string notification, NotifyPriority priority) { if (Muted) { return; } lock (notifications) { IEnumerable <INotifier> notifiers; if (this.notifications.TryGetValues(type, out notifiers)) { foreach (var n in notifiers) { n.Notify(type, notification, priority); } } } if (SpeechReceiver != null) { lock (speechNotifiers) { IEnumerable <ITextToSpeech> speakers; if (this.speechNotifiers.TryGetValues(type, out speakers)) { foreach (var n in speakers) { SpeechReceiver.Receive(n.AudioSource, n.GetSpeech(notification)); } } } } }
//>>>>>>>>>>the slowest /*var target1 = Expression.Property(Expression.Constant(_subscriber), typeof(WeakReference), "Target"); * var target = Expression.Constant(Subscriber); * MethodCallExpression methodCall = Expression.Call(target, method); * _callback = Expression.Lambda<Action>(methodCall).Compile();*/ //>>>>>>>>>>it will keep the object reference //_callback = (Action) method.CreateDelegate(typeof(Action), Subscriber); //>>>>>>>>>30% slower than delegate //_callback = method.Invoke(Subscriber); public Subscription(object subscriber, MethodInfo method, Type eventType, NotifyPriority priority, ThreadMode threadMode) { _subscriber = new WeakReference(subscriber); Priority = priority; EventType = eventType; ThreadMode = threadMode; InitMethod(subscriber, method); }
/* --------------------------------------------------------------------- */ /// /// Clear /// /// <summary> /// 指定された優先度に設定されている通知をすべて削除します。 /// </summary> /// /// <param name="priority">優先度</param> /// /* --------------------------------------------------------------------- */ public void Clear(NotifyPriority priority) { var result = false; lock (_lock) _inner.Remove(priority); if (result) { OnCollectionChanged(new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Reset)); } }
public void Notify(NotificationType type, string notification, string nickname, string phonetic, NotifyPriority priority) { if (Muted) { return; } lock (notifications) { IEnumerable <INotifier> notifiers; if (this.notifications.TryGetValues(type, out notifiers)) { foreach (var n in notifiers) { n.Notify(type, String.Format(notification, nickname), priority); } } } if (SpeechReceiver != null) { lock (speechNotifiers) { IEnumerable <ITextToSpeech> speakers; if (this.speechNotifiers.TryGetValues(type, out speakers)) { foreach (var n in speakers) { SpeechReceiver.Receive(n.AudioSource, n.GetSpeech(String.Format(notification, (!phonetic.IsNullOrWhitespace()) ? phonetic : nickname))); } } } } }
public void Notify(NotificationType type, string notification, string nickname, string phonetic, NotifyPriority priority) { if (Muted) return; lock (notifications) { IEnumerable<INotifier> notifiers; if (this.notifications.TryGetValues (type, out notifiers)) { foreach (var n in notifiers) n.Notify (type, String.Format (notification, nickname), priority); } } if (SpeechReceiver != null) { lock (speechNotifiers) { IEnumerable<ITextToSpeech> speakers; if (this.speechNotifiers.TryGetValues (type, out speakers)) { foreach (var n in speakers) SpeechReceiver.Receive (n.AudioSource, n.GetSpeech (String.Format (notification, (!phonetic.IsNullOrWhitespace()) ? phonetic : nickname))); } } } }
public void Notify(NotificationType type, string notification, NotifyPriority priority) { if (Muted) return; lock (notifications) { IEnumerable<INotifier> notifiers; if (this.notifications.TryGetValues (type, out notifiers)) { foreach (var n in notifiers) n.Notify (type, notification, priority); } } if (SpeechReceiver != null) { lock (speechNotifiers) { IEnumerable<ITextToSpeech> speakers; if (this.speechNotifiers.TryGetValues (type, out speakers)) { foreach (var n in speakers) SpeechReceiver.Receive (n.AudioSource, n.GetSpeech (notification)); } } } }