Esempio n. 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);
        }
Esempio n. 2
0
 public DomLoader(StreamReader sr, Document d)
     : this(sr.ReadToEnd(), d)
 {
 }
Esempio n. 3
0
        /// <summary>
        /// 设置发送消息的快捷键
        /// </summary>
        /// <param name="value"></param>
        public void SetSendKeyType(int value)
        {
            CSS.IM.XMPP.Xml.Dom.Document doc_setting = new CSS.IM.XMPP.Xml.Dom.Document();

            Settings.Settings config = new Settings.Settings();
            doc_setting.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
            Settings.Paths path = doc_setting.RootElement.SelectSingleElement(typeof(Settings.Paths), false) as Settings.Paths;
            path.SendKeyType = value;
            CSS.IM.UI.Util.Path.SendKeyType = value;
            config.Paths = path;
            config.Font = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SFont)) as Settings.SFont;
            config.Color = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SColor)) as Settings.SColor;

            doc_setting.Clear();
            doc_setting.ChildNodes.Add(config);
            doc_setting.Save(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
        }
        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();
            }
        }