예제 #1
0
 public CustomEventCallbackData(CustomEventCallback callback, float aheadTime, bool callIfBeforeStartTime)
 {
     this.callback              = callback;
     this.aheadTime             = aheadTime;
     this.callIfBeforeStartTime = callIfBeforeStartTime;
     nextEventIndex             = 0;
 }
예제 #2
0
        public CustomEventCallbackData AddCustomEventCallback(CustomEventCallback callback, float aheadTime = 0, bool callIfBeforeStartTime = true)
        {
            CustomEventCallbackData customEventCallbackData = new CustomEventCallbackData(callback, aheadTime, callIfBeforeStartTime);

            _customEventCallbackData.Add(customEventCallbackData);
            return(customEventCallbackData);
        }
예제 #3
0
        /// <summary>
        /// Called when the form is loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnLoadRoomForm(object sender, System.EventArgs e)
        {
            lblWelcome.Text = "Welcome, " + _userName + "!";

            /// Subscribe to custom notifications, so that we can listen to room events.
            _appEvent = new CustomEventCallback(this.OnAppEvent);
            NCache.Web.Caching.NCache.Caches[Helper.CacheName].CustomEvent += new CustomEventCallback(this.OnAppEvent);

            PopulateUsersList();
        }
예제 #4
0
 /// <summary>
 /// Called when the form is closing.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnRoomFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     try
     {
         ///unregister the custom event handler.
         NCache.Web.Caching.NCache.Caches[Helper.CacheName].CustomEvent -= _appEvent;
         _appEvent = null;
         ///Notifiy that an existing user has left the conversation.
         NCache.Web.Caching.NCache.Caches[Helper.CacheName].RaiseCustomEvent(Msg.Code.UserLeft, _userName);
         /// Remove our user key from the cache.
         NCache.Web.Caching.NCache.Caches[Helper.CacheName].Remove("<user>" + _userName);
     }
     catch (Exception)
     {
     }
 }
        public virtual void OnCustomNotification(object notifId, object data, bool notifyAsync)
        {
            try
            {
                BitSet flag = new BitSet();
                notifId = _parent.SafeDeserialize(notifId, _parent._serializationContext, flag);
                data    = _parent.SafeDeserialize(data, _parent._serializationContext, flag);
                if (_parent.CustomEventHandle != null)
                {
                    Delegate[] dltList = _parent.CustomEventHandle.GetInvocationList();
                    for (int i = dltList.Length - 1; i >= 0; i--)
                    {
                        CustomEventCallback subscriber = (CustomEventCallback)dltList[i];
                        try
                        {
                            if (notifyAsync)
                            {
#if !NETCORE
                                subscriber.BeginInvoke(notifId, data, null, null);
#elif NETCORE
                                TaskFactory factory = new TaskFactory();
                                Task        task    = factory.StartNew(() => subscriber(notifId, data));
#endif
                            }
                            else
                            {
                                subscriber(notifId, data);
                            }

                            if (_parent._perfStatsCollector != null)
                            {
                                _parent._perfStatsCollector.IncrementEventsProcessedPerSec();
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    }
                }
            }

            catch
            {
            }
        }