Example #1
0
        public void TestContactTree()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            string json = string.Empty;

            using (StreamReader sr = new StreamReader(path + "\\data\\addMessage.json"))
            {
                json = sr.ReadToEnd();
            }

            MessageContactTree tree = JsonConvert.DeserializeObject <MessageContactTree>(json);

            tree.Initial();

            //UserInfo.Instance.SetContact(tree.ContactList);

            //UserInfo.Instance.SyncKeyInfo = tree.SyncKey;

            foreach (var msg in tree.AddMsgList)
            {
                int    s       = msg.Content.Replace("<br />", "<br/>").LastIndexOf("<br/>") + "<br/>".Length;
                string content = msg.Content.Substring(s, msg.Content.Length - s);
            }
        }
Example #2
0
        public override string Monitor()
        {
            string msgs  = string.Empty;
            string value = HttpHelper.GetResponseValue(userManager.UserInfo.SyncCheckUrl, userManager.UserInfo.Cookies);

            using (StreamWriter sw = new StreamWriter(Path + "\\sync.txt", true))
            {
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + value);
            }

            string[] tempArr = value.Trim().Split('=');

            if (tempArr.Length >= 2)
            {
                SyncCheck sc = JsonConvert.DeserializeObject <SyncCheck>(tempArr[1]);
                if (sc.retcode == "0" && sc.selector != "0")
                {
                    var data = new
                    {
                        BaseRequest = new
                        {
                            Uin = userManager.UserInfo.UIN,
                            Sid = userManager.UserInfo.SID,
                        },

                        SyncKey = userManager.UserInfo.SyncKeyInfo,
                        rr      = userManager.UserInfo.DateTimeDelt,
                    };

                    string jsonData = JsonConvert.SerializeObject(data);

                    using (StreamWriter sw = new StreamWriter(DataFilePath, true))
                    {
                        sw.WriteLine(value);
                    }

                    WebResponse webResponse = HttpHelper.CreateRequest(userManager.UserInfo.SyncUrl, HttpMethod.POST, jsonData, userManager.UserInfo.Cookies).GetResponse();
                    value = HttpHelper.GetResponseValue(webResponse);

                    CookieCollection cookies = ((HttpWebResponse)webResponse).Cookies;
                    if (cookies != null && cookies.Count > 0)
                    {
                        userManager.UserInfo.Cookies = ((HttpWebResponse)webResponse).Cookies;
                    }

                    using (StreamWriter sw = new StreamWriter(MessageFilePath, true))
                    {
                        sw.WriteLine(value);
                    }

                    try
                    {
                        MessageContactTree mct = JsonConvert.DeserializeObject <MessageContactTree>(value);
                        mct.Initial();

                        if (mct.SyncKey.Count > 0)
                        {
                            userManager.UserInfo.SyncKeyInfo = mct.SyncKey;
                        }

                        if (mct.AddMsgCount > 0)
                        {
                            foreach (var msg in mct.AddMsgList)
                            {
                                string content = msg.Content.Replace("<br />", "<br/>");

                                if (string.IsNullOrEmpty(content) || !content.Contains("<br/>"))
                                {
                                    continue;
                                }

                                int    s        = content.LastIndexOf("<br/>") + "<br/>".Length;
                                string message  = msg.Content.Substring(s, msg.Content.Length - s);
                                string sendUser = msg.Content.Substring(0, s - ":<br/>".Length);


                                BaseContactModel bcm = userManager.UserInfo[msg.FromUserName];
                                if (bcm == null)
                                {
                                    GetContact(msg.FromUserName);
                                }

                                bcm = userManager.UserInfo[msg.FromUserName];

                                if (bcm != null)
                                {
                                    MemberModel mm = bcm[sendUser];

                                    if (string.IsNullOrEmpty(mm.NickName) && string.IsNullOrEmpty(mm.DisplayName))
                                    {
                                        GetContact(msg.FromUserName);
                                    }

                                    mm = userManager.UserInfo[msg.FromUserName][sendUser];

                                    if (mm != null)
                                    {
                                        using (StreamWriter sw = new StreamWriter(Path + $"\\{bcm.NickName}_{DateTime.Now.ToString("yyyyMMdd")}.txt", true))
                                        {
                                            sw.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} {(string.IsNullOrEmpty(mm.DisplayName) ? mm.NickName : mm.DisplayName)}: {message}");
                                        }
                                    }
                                }

                                msgs += message + "<br />";
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(msgs);
        }