Ejemplo n.º 1
0
        public void setup()
        {
            mocks = new MockRepository();
            dm = new DiscoManager();

            stream = mocks.DynamicMock<XmppStream>();
            tracker = mocks.DynamicMock<IIQTracker>();
            dm.Stream = stream;

            doc = new XmlDocument();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the given items to the cache.
        /// </summary>
        /// <param name="manager">The DiscoManager used to create/cache nodes</param>
        /// <param name="items">Items to add.</param>
        public void AddItems(DiscoManager manager, DiscoItem[] items)
        {
            if (Children == null)
                Children = new Set();

            // items may be null when used from outside.
            if (items != null)
            {
                foreach (DiscoItem di in items)
                    AddItem(manager, di);
            }

            DoCallbacks(m_itemCallbacks);
        }
Ejemplo n.º 3
0
 internal DiscoNode AddItem(DiscoManager manager, DiscoItem di)
 {
     DiscoNode dn = manager.GetNode(di.Jid, di.Node);
     if ((di.Named != null) && (di.Named != ""))
         dn.Name = di.Named;
     Children.Add(dn);
     return dn;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Add a callback for when identities are received.
 /// 
 /// Calls the callback immediately if the features have already been retrieved.
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="callback"></param>
 /// <param name="state"></param>
 /// <returns>True if there were no identities yet, and the callback was queued.</returns>
 public bool AddIdentityCallback(DiscoManager manager, DiscoNodeHandler callback, object state)
 {
     lock (this)
     {
         if (Identities != null)
         {
             if (callback != null)
                 callback(manager, this, state);
             return false;
         }
         else
         {
             m_identCallbacks.Add(new NodeCallback(manager, callback, state));
             return true;
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Add a callback for when items are received.
 /// 
 /// Calls the callback immediately if the items have already been retrieved.
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="callback"></param>
 /// <param name="state"></param>
 /// <returns>True if there were no items yet, and the callback was queued.</returns>
 public bool AddItemsCallback(DiscoManager manager, DiscoNodeHandler callback, object state)
 {
     lock (this)
     {
         if (Children != null)
         {
             if (callback != null)
                 callback(manager, this, state);
             return false;
         }
         else
         {
             if (callback != null)
                 m_itemCallbacks.Add(new NodeCallback(manager, callback, state));
             return true;
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Add a callback for when features are received.
 /// 
 /// Calls the callback immediately if the features have already been retrieved.
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="callback"></param>
 /// <param name="state"></param>
 /// <returns>True if there were no features yet, and the callback was queued.</returns>
 public bool AddFeatureCallback(DiscoManager manager, DiscoNodeHandler callback, object state)
 {
     lock (this)
     {
         if (Features != null)
         {
             if (callback != null)
                 callback(manager, this, state);
             return false;
         }
         else
         {
             if (callback != null)
                 m_featureCallbacks.Add(new NodeCallback(manager, callback, state));
             return true;
         }
     }
 }
Ejemplo n.º 7
0
 public NodeCallback(DiscoManager m, DiscoNodeHandler h, object s)
 {
     manager = m;
     callback = h;
     state = s;
 }
Ejemplo n.º 8
0
 public void GotRootItems(DiscoManager manager, DiscoNode node, object state)
 {
     m_outstanding = node.Children.Count;
     foreach (DiscoNode n in node.Children)
         manager.BeginGetFeatures(n, new DiscoNodeHandler(GotFeatures), state);
 }
Ejemplo n.º 9
0
            public void GotFeatures(DiscoManager manager, DiscoNode node, object state)
            {

                // yes, yes, this may call the handler more than once in multi-threaded world.  Punt for now.
                if (m_handler != null)
                {
                    if (node.HasFeature(m_URI))
                    {
                        m_handler(manager, node, state);
                        m_handler = null;
                    }
                }

                if (Interlocked.Decrement(ref m_outstanding) == 0)
                {
                    if (m_handler != null)
                        m_handler(manager, null, state);
                }
            }
Ejemplo n.º 10
0
        public void IntialDiscoTest()
        {
            IEventRaiser onAuth;

            IQ sentIq = null;
            IqCB sentCallback = null;

            mocks.BackToRecordAll();
            using (mocks.Record())
            {
                Expect.Call(stream.Server).Return(jid);
                stream.OnAuthenticate += null;
                onAuth = LastCall.IgnoreArguments().GetEventRaiser();

                Expect.Call(stream.Document).Return(doc);
                SetupTrackerBeginIq(
                    delegate(IQ arg0, IqCB arg1, object arg2)
                    {
                        // Grab the iq and callback so this part of
                        // the code can finish. Call the callback later.
                        sentIq = arg0;
                        sentCallback = arg1;

                        string id = arg0.GetAttribute("id");
                        string original = arg0.OuterXml.Replace(" ", "");
                        string comparison = GetInfoXml(id).Replace(" ", "");
                        return original == comparison;
                    });

                Expect.Call(stream.Document).Return(doc);
                SetupTrackerBeginIq(
                    delegate(IQ arg0, IqCB arg1, object arg2)
                    {
                        string id = arg0.GetAttribute("id");
                        string original = arg0.OuterXml;
                        return original.Replace(" ", "") ==
                               GetItemsForServiceXml(id).Replace(" ", "");
                    });
            }

            using (mocks.Playback())
            {
                DiscoManager newDm = new DiscoManager();
                newDm.Stream = stream;

                onAuth.Raise(new object[] { null });

                if (sentIq != null)
                {
                    string id = sentIq.GetAttribute("id");
                    if (sentCallback != null)
                        sentCallback(null, CreateDiscoInfoResponse(id), newDm.Root);
                }
            }
        }
Ejemplo n.º 11
0
        private void GotCaps(DiscoManager m, DiscoNode node, object state)
        {
            // timeout
            if (node == null)
                return;

            string ver = (string)state;
            string calc = CalculateVer(node);
            if (ver != calc)
            {
                Debug.WriteLine("WARNING: invalid caps ver hash: '" + ver + "' != '" + calc + "'");
                if (node.Info != null)
                    Debug.WriteLine(node.Info.OuterXml);
                return;
            }
            m_cache[ver] = node.Info;
        }