예제 #1
0
        public void UnregisterService(Type serviceType)
        {
            if (Services.ContainsKey(serviceType))
            {
                Services.Remove(serviceType);
            }

            if (ActiveServices.ContainsKey(serviceType))
            {
                ActiveServices.Remove(serviceType);
            }
        }
예제 #2
0
        /// <summary>
        /// Removes a logic handler from our list.  Logic handlers are automatically removed if they set their state to completed
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public bool RemoveLogic(Logic log)
        {
            bool bRet = false;

            lock (LogicLock)
            {
                if (ActiveServices.Contains(log) == true)
                {
                    ActiveServices.Remove(log);
                    bRet = true;
                }
            }
            return(bRet);
        }
예제 #3
0
        protected virtual bool OnPresence(PresenceMessage pres)
        {
            bool bHandled = false;

            Logic[]      LogicList  = null;
            List <Logic> RemoveList = new List <Logic>();

            lock (LogicLock)
            {
                LogicList = ActiveServices.ToArray();
            }

            foreach (Logic log in LogicList)
            {
                bHandled = log.NewPresence(pres);

                if (log.IsCompleted == true)
                {
                    RemoveList.Add(log);
                }
                if (bHandled == true)
                {
                    break;
                }
            }

            lock (LogicLock)
            {
                foreach (Logic log in RemoveList)
                {
                    if (ActiveServices.Contains(log) == true)
                    {
                        ActiveServices.Remove(log);
                    }
                }
            }
            return(bHandled);
        }
예제 #4
0
        protected virtual void XMPPConnection_OnStanzaReceived(XMPPStanza stanza, object objFrom)
        {
            bool bHandled = false;
            /// See if any of our handlers
            ///
            List <Logic> RemoveList = new List <Logic>();

            lock (LogicLock)
            {
                foreach (Logic log in ActiveServices)
                {
                    bHandled = log.NewXMLFragment(stanza);
                    if (log.IsCompleted == true)
                    {
                        RemoveList.Add(log);
                    }
                    if (bHandled == true)
                    {
                        break;
                    }
                }

                foreach (Logic log in RemoveList)
                {
                    ActiveServices.Remove(log);
                }
            }

            if (bHandled == true)
            {
                return;
            }

            /// Now see if this stanza is a higher level IQ or message
            ///
            try
            {
                XElement        elem = XElement.Parse(stanza.XML);
                XMPPMessageBase msg  = null;
                if (elem.Name == "iq")
                {
                    msg = XMPPMessageFactory.BuildIQ(elem, stanza.XML);
                }
                else if (elem.Name == "message")
                {
                    msg = XMPPMessageFactory.BuildMessage(elem, stanza.XML);
                }
                else if (elem.Name == "presence")
                {
                    msg = XMPPMessageFactory.BuildPresence(elem, stanza.XML);
                    //msg = new PresenceMessage(stanza.XML);
                }
                /// TODO.. log IQ, MESSAGE or PRESENCE event, maybe have an event handler
                ///
                if (msg != null)
                {
                    if (msg is IQ)
                    {
                        bHandled = OnIQ(msg as IQ);
                    }
                    else if (msg is Message)
                    {
                        bHandled = OnMessage(msg as Message);
                    }
                    else if (msg is PresenceMessage)
                    {
                        bHandled = OnPresence(msg as PresenceMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            if (bHandled == true)
            {
                return;
            }
        }