Example #1
0
        /// <summary>
        /// Start an XDB request.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="xtype"></param>
        /// <param name="owner"></param>
        /// <param name="ns"></param>
        /// <param name="action"></param>
        /// <param name="cb"></param>
        /// <param name="cbArg"></param>
        public void BeginXdb(XmlElement root, XdbType xtype,
                             string owner, string ns, XdbAction action,
                             XdbCB cb, object cbArg)
        {
            Debug.Assert(owner != null);
            Debug.Assert(ns != null);
            Xdb xdb = new Xdb(m_comp.Document);

            xdb.NS   = ns;
            xdb.Type = xtype;
            xdb.To   = owner;
            xdb.From = m_comp.ComponentID;
            if (action != XdbAction.NONE)
            {
                xdb.Action = action;
            }
            if (root != null)
            {
                xdb.AddChild(root);
            }
            // if no callback, ignore response.
            if (cb != null)
            {
                TrackerData td = new TrackerData();
                td.cb   = cb;
                td.data = cbArg;
                lock (m_pending)
                {
                    m_pending[xdb.ID] = td;
                }
            }
            m_comp.Write(xdb);
        }
        /// <summary>
        /// Received an element.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="tag"></param>
        protected override void OnElement(object sender, System.Xml.XmlElement tag)
        {
            lock (StateLock)
            {
                StartTLS start = tag as StartTLS;
                if (start != null)
                {
                    State = ConnectedState.Instance;
                    InitializeStream();
                    this.Write(new Proceed(this.Document));
                    this.StartTLS();
                    return;
                }
                if (State == HandshakingState.Instance)
                {
                    // sets IsConnected
                    Handshake(tag);
                    return;
                }
            }

            base.OnElement(sender, tag);

            if (OnRoute != null)
            {
                Route route = tag as Route;
                if (route != null)
                {
                    OnRoute(this, route);
                }
            }
            // TODO: add XdbTracker stuff
            if (OnXdb != null)
            {
                Xdb xdb = tag as Xdb;
                if (xdb != null)
                {
                    OnXdb(this, xdb);
                }
            }
            if (OnLog != null)
            {
                Log log = tag as Log;
                if (log != null)
                {
                    OnLog(this, log);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Received an XDB element on Component.
        /// Is this a response to a tracked request?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="xdb"></param>
        private void OnXdb(object sender, Xdb xdb)
        {
            string      id = xdb.ID;
            TrackerData td;

            lock (m_pending)
            {
                td = (TrackerData)m_pending[id];

                // this wasn't one that was being tracked.
                if (td == null)
                {
                    return;
                }
                m_pending.Remove(id);
            }

            // don't need to check for null.  protected by assert below.
            td.cb(this, xdb, td.data);
        }