Пример #1
0
        public DomLoader(string xml, Document d)
        {
            doc	= d;
            sp = new StreamParser();

            sp.OnStreamStart	+= new StreamHandler(sp_OnStreamStart);
            sp.OnStreamElement	+= new StreamHandler(sp_OnStreamElement);
            sp.OnStreamEnd		+= new StreamHandler(sp_OnStreamEnd);

            byte[] b = System.Text.Encoding.UTF8.GetBytes(xml);
            sp.Push(b, 0, b.Length);
        }
Пример #2
0
 public DomLoader(StreamReader sr, Document d)
     : this(sr.ReadToEnd(), d)
 {
 }
Пример #3
0
        private void OnGetSessionRequestResponse(IAsyncResult result)
        {
            // grab the custom state object
            WebRequestState state = (WebRequestState)result.AsyncState;
            HttpWebRequest request = (HttpWebRequest)state.WebRequest;

            //state.TimeOutTimer.Dispose();

            // get the Response
            HttpWebResponse resp = (HttpWebResponse)request.EndGetResponse(result);

            // The server must always return a 200 response code,
            // sending any session errors as specially-formatted identifiers.
            if (resp.StatusCode != HttpStatusCode.OK)
            {
                //FireOnError(new PollSocketException("unexpected status code " + resp.StatusCode.ToString()));
                return;
            }

            Stream rs = resp.GetResponseStream();

            int readlen;
            byte[] readbuf = new byte[1024];
            MemoryStream ms = new MemoryStream();
            while ((readlen = rs.Read(readbuf, 0, readbuf.Length)) > 0)
            {
                ms.Write(readbuf, 0, readlen);
            }

            byte[] recv = ms.ToArray();

            if (recv.Length > 0)
            {
                string body = null;
                string stanzas = null;

                string res = Encoding.UTF8.GetString(recv, 0, recv.Length);

                ParseResponse(res, ref body, ref stanzas);

                Document doc = new Document();
                doc.LoadXml(body);
                Body boshBody = doc.RootElement as Body;

                sid         = boshBody.Sid;
                polling     = boshBody.Polling;
                m_MaxPause  = boshBody.MaxPause;

                byte[] bin = Encoding.UTF8.GetBytes(DummyStreamHeader + stanzas);

                base.FireOnReceive(bin, bin.Length);

                // cleanup webrequest resources
                ms.Close();
                rs.Close();
                resp.Close();

                waitingRequests--;

                if (waitingRequests == 0)
                    StartWebRequest();
            }
        }