Exemplo n.º 1
0
 public static void Output(this WeChatRecentMessageCollection messages)
 {
     foreach (WeChatRecentMessage message in messages)
     {
         Console.WriteLine(message.ToString());
     }
 }
Exemplo n.º 2
0
        private void SynchronizeRecentMessages()
        {
            List <WeChatRecentMessage> allMessages = new List <WeChatRecentMessage>();

            var allAccounts = AccountInfoAdapter.Instance.LoadAll();

            foreach (var account in allAccounts)
            {
                WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                var flag     = true;
                var curIndex = 0;
                while (flag)
                {
                    WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                    Thread.Sleep(1000);

                    foreach (var message in messages)
                    {
                        message.AccountID = account.AccountID;
                        allMessages.Add(message);
                    }

                    if (messages.Count == 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        curIndex++;
                    }
                }
            }

            foreach (var message in allMessages)
            {
                WeChatRecentMessageAdapter.Instance.Update(message);
            }
        }
Exemplo n.º 3
0
        protected override void ProcessResponseText(string responseText)
        {
            WeChatRecentMessageCollection result = new WeChatRecentMessageCollection();

            string templateA = "list : ({\"msg_item\":";
            string templateB = "}).msg_item,\r";

            int startIndex = responseText.IndexOf(templateA);

            if (startIndex >= 0)
            {
                int endIndex = responseText.IndexOf(templateB, startIndex);

                if (endIndex >= 0)
                {
                    string data = responseText.Substring(startIndex + templateA.Length, endIndex - startIndex - templateA.Length);

                    result = JSONSerializerExecute.Deserialize <WeChatRecentMessageCollection>(data);
                }
            }

            this._Messages = result;
        }
		protected override void ProcessResponseText(string responseText)
		{
			WeChatRecentMessageCollection result = new WeChatRecentMessageCollection();

			string templateA = "list : ({\"msg_item\":";
			string templateB = "}).msg_item,\r";

			int startIndex = responseText.IndexOf(templateA);

			if (startIndex >= 0)
			{
				int endIndex = responseText.IndexOf(templateB, startIndex);

				if (endIndex >= 0)
				{
					string data = responseText.Substring(startIndex + templateA.Length, endIndex - startIndex - templateA.Length);

					result = JSONSerializerExecute.Deserialize<WeChatRecentMessageCollection>(data);
				}
			}

			this._Messages = result;
		}
Exemplo n.º 5
0
        private void Synchronize()
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);
                List <WeChatRecentMessage> allMessages = new List <WeChatRecentMessage>();

                if (ddlAccount.SelectedIndex == 0)
                {
                    var allAccounts = AccountInfoAdapter.Instance.LoadAll();

                    foreach (var account in allAccounts)
                    {
                        WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                        ProcessProgress.Current.StatusText     = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID);
                        ProcessProgress.Current.Response();
                        Thread.Sleep(1000);

                        var flag     = true;
                        var curIndex = 0;
                        while (flag)
                        {
                            WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                            Thread.Sleep(1000);

                            foreach (var message in messages)
                            {
                                message.AccountID = account.AccountID;
                                allMessages.Add(message);
                            }

                            if (messages.Count == 0)
                            {
                                flag = false;
                            }
                            else
                            {
                                curIndex++;
                            }

                            ProcessProgress.Current.Response();
                        }
                    }
                }
                else
                {
                    var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", ddlAccount.SelectedValue)).FirstOrDefault();
                    WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                    ProcessProgress.Current.StatusText     = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID);
                    ProcessProgress.Current.Response();
                    Thread.Sleep(1000);

                    var flag     = true;
                    var curIndex = 0;
                    while (flag)
                    {
                        WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                        Thread.Sleep(1000);

                        foreach (var message in messages)
                        {
                            message.AccountID = account.AccountID;
                            allMessages.Add(message);
                        }

                        if (messages.Count == 0)
                        {
                            flag = false;
                        }
                        else
                        {
                            curIndex++;
                        }

                        ProcessProgress.Current.Response();
                    }
                }

                ProcessProgress.Current.MaxStep    = allMessages.Count;
                ProcessProgress.Current.StatusText = "开始同步...";
                ProcessProgress.Current.Response();

                foreach (var message in allMessages)
                {
                    WeChatRecentMessageAdapter.Instance.Update(message);
                    ProcessProgress.Current.Increment();
                    ProcessProgress.Current.Response();
                }

                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.StatusText  = "";
                ProcessProgress.Current.Response();
            }
            catch (System.Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(MCS.Web.WebControls.SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }
        public override void Execute(string argument)
        {
            WeChatRecentMessageCollection result = WeChatHelper.GetFriendMessages(argument, WeChatRequestContext.Current.LoginInfo);

            result.Output();
        }