コード例 #1
0
        private AsyncXmppReader arrangeXmppReader(XmlParsingStates parseStates)
        {
            var reader = new AsyncXmppReader(new XmlDocument());

            // set wait handle when any of these has run
            reader.OnXmlDocumentStart += (node) =>
            {
                parseStates.WaitHandle.Set();
                parseStates.StartCalled = true;
            };
            reader.OnXmlElementComplete += (node) =>
            {
                parseStates.WaitHandle.Set();
                parseStates.ElementCount++;
            };
            reader.OnXmlDocumentEnd += (node) =>
            {
                parseStates.WaitHandle.Set();
                parseStates.EndCalled = true;
            };
            reader.OnXmlException += (exception) =>
            {
                parseStates.WaitHandle.Set();
                parseStates.XmlExceptionRaised  = exception != null;
                parseStates.XmlExceptionMessage = exception != null ? exception.Message : "";
            };

            return(reader);
        }
コード例 #2
0
        private void actConnectSleepDisconnect(AsyncXmppReader reader, byte[] buffer, WaitHandle waitHandle)
        {
            // connect
            reader.ParseXmppElements(buffer, buffer.Length);

            // wait up to a maximum of 5 sec for background thread to process
            // this merely indicates that the process has started
            waitHandle.WaitOne(5000);

            if (System.Diagnostics.Debugger.IsAttached)
            {
                // wait for a long time in debugging mode so there's time to debug
                Thread.Sleep(1000000);
            }
            else
            {
                // wait another 1 sec to make sure the process has completed
                Thread.Sleep(1000);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates an asynchronous client that deals with the xmpp protocol
        /// </summary>
        /// <param name="hostname"></param>
        /// <param name="port"></param>
        /// <param name="usesSslConnection"></param>
        public XmppClient(string hostname, int port, bool usesSslConnection)
        {
            this.Hostname          = hostname;
            this.Port              = port;
            this.UsesSslConnection = usesSslConnection;

            // create socket
            this.asyncSocket                           = new AsyncSocket(this.Hostname, this.Port, this.UsesSslConnection);
            this.asyncSocket.OnConnected              += onConnected;
            this.asyncSocket.OnConnectException       += onConnectionException;
            this.asyncSocket.OnDataReceived           += onDataReceived;
            this.asyncSocket.OnSocketUnexpectedClosed += onSocketUnexpectedlyClosed;

            // init received document
            receivedDocument = new XmlDocument();

            // create reader object and bind events
            this.asyncXmppReader = new AsyncXmppReader(receivedDocument);
            this.asyncXmppReader.OnXmlDocumentStart   += onXmppDocumentStart;
            this.asyncXmppReader.OnXmlDocumentEnd     += onXmppDocumentEnd;
            this.asyncXmppReader.OnXmlElementComplete += onXmppElement;
            this.asyncXmppReader.OnXmlException       += onXmlException;
        }