LiveCodingChat.Livecoding.ChatRoom.Load C# (CSharp) Метод

Load() публичный Метод

public Load ( string json, string promiseID ) : void
json string
promiseID string
Результат void
        public void Load(string json,string promiseID)
        {
            PromiseID = promiseID;
            json = json.Replace ("}", "").Replace ("{", "");
            string[] pairs = json.Split(',');
            foreach (string pair in pairs) {
                string[] p = System.Text.RegularExpressions.Regex.Unescape(pair.Trim ()).Split (new []{':'}, 2);
                switch (p [0]) {
                case "resource":
                    Resource = HtmlHelper.getString(p [1].Trim());
                    break;
                case "roomJid":
                    RoomJID = HtmlHelper.getString(p [1].Trim());
                    break;
                case "chatUrlWs":
                    WebsocketURL = HtmlHelper.getString(p [1].Trim());
                    break;
                }
            }
        }

Usage Example

Пример #1
0
        private ChatRoom OpenChat(string room)
        {
            string         url = PAGE + "chat/" + room + "/";
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

            req.UserAgent       = UserAgent;
            req.CookieContainer = cookies;
            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                ChatRoom chatRoom = new ChatRoom(this, room);
                using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) {
                    string data = sr.ReadToEnd();
                    int    fInd = data.IndexOf("window.Chat.init(");
                    //Console.WriteLine (data);
                    if (fInd == -1)
                    {
                        return(null);
                    }
                    Console.WriteLine("Found start");
                    fInd += "window.Chat.init(".Length;
                    int eInd = data.IndexOf(");", fInd);
                    if (eInd == -1)
                    {
                        return(null);
                    }
                    Console.WriteLine("Found end");
                    string json = data.Substring(fInd, eInd - fInd - 1);
                    fInd = data.IndexOf("window.Chat.connect(", eInd);
                    if (fInd == -1)
                    {
                        return(null);
                    }
                    eInd = data.IndexOf(");", fInd);
                    if (eInd == -1)
                    {
                        return(null);                       //TODO: exception trowing?
                    }
                    string tmp = data.Substring(fInd, eInd - fInd - 1);
                    tmp = tmp.Split(',') [1];
                    tmp = tmp.Split(':') [1].Trim().Replace("\"", "");
                    chatRoom.Load(json, tmp);
                }
                chatRoom.Login();
                return(chatRoom);
            }
            Console.WriteLine("Not OK");
            return(null);
        }
All Usage Examples Of LiveCodingChat.Livecoding.ChatRoom::Load