LiveCodingChat.Livecoding.LivecodingSession.OpenChat C# (CSharp) Метод

OpenChat() приватный Метод

private OpenChat ( string room ) : ChatRoom
room string
Результат ChatRoom
        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;
        }