Esempio n. 1
0
        private void ResponseCompletedScript()
        {
            StringBuilder strB = new StringBuilder();

            strB.Append("<script type=\"text/javascript\">");
            strB.Append("\n" + SubmitButton.GetResetAllParentButtonsScript(false));
            strB.AppendFormat("\nparent.document.getElementById(\"{0}\").click();", "RefreshButton");
            strB.Append("</script>");

            this.Response.Write(strB.ToString());
            this.Response.End();
        }
        private void Synchronize()
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);
                List <WeChatFriend> allFriends = new List <WeChatFriend>();

                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)
                        {
                            WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 100, WeChatRequestContext.Current.LoginInfo);
                            Thread.Sleep(1000);

                            foreach (var friend in friends)
                            {
                                friend.AccountID = account.AccountID;
                                allFriends.Add(friend);
                            }

                            if (friends.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)
                    {
                        WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 100, WeChatRequestContext.Current.LoginInfo);
                        Thread.Sleep(1000);

                        foreach (var friend in friends)
                        {
                            friend.AccountID = account.AccountID;
                            allFriends.Add(friend);
                        }
                        if (friends.Count == 0)
                        {
                            flag = false;
                        }
                        else
                        {
                            curIndex++;
                        }

                        ProcessProgress.Current.Response();
                    }
                }

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

                foreach (var friend in allFriends)
                {
                    WeChatFriendAdapter.Instance.Update(friend);
                    ProcessProgress.Current.Increment();
                    ProcessProgress.Current.Response();
                }

                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.StatusText  = "";
                ProcessProgress.Current.Response();
            }
            catch (Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }
Esempio n. 3
0
        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);

                if (ddlGroups.SelectedIndex == 0)
                {
                    var allGroups = ConditionalGroupAdapter.Instance.LoadAll();
                    ProcessProgress.Current.MaxStep    = allGroups.Count;
                    ProcessProgress.Current.StatusText = "开始计算...";
                    ProcessProgress.Current.Response();
                    foreach (var group in allGroups)
                    {
                        var result = Common.GetCalculatedGroupMembers(group.Condition);
                        using (TransactionScope scope = TransactionScopeFactory.Create())
                        {
                            GroupAndMemberAdapter.Instance.DeleteByGroupID(group.GroupID);
                            foreach (var member in result)
                            {
                                GroupAndMember gm = new GroupAndMember();
                                gm.GroupID  = group.GroupID;
                                gm.MemberID = member.MemberID;
                                GroupAndMemberAdapter.Instance.Update(gm);
                            }
                            scope.Complete();
                        }

                        ProcessProgress.Current.StatusText = "";
                        ProcessProgress.Current.Increment();
                        ProcessProgress.Current.Response();
                    }
                }
                else
                {
                    var group = ConditionalGroupAdapter.Instance.Load(p => p.AppendItem("GroupID", ddlGroups.SelectedValue)).FirstOrDefault();

                    var result = Common.GetCalculatedGroupMembers(group.Condition);

                    ProcessProgress.Current.MaxStep = result.Count;
                    ProcessProgress.Current.Response();

                    using (TransactionScope scope = TransactionScopeFactory.Create())
                    {
                        GroupAndMemberAdapter.Instance.DeleteByGroupID(group.GroupID);
                        foreach (var member in result)
                        {
                            GroupAndMember gm = new GroupAndMember();
                            gm.GroupID  = group.GroupID;
                            gm.MemberID = member.MemberID;
                            GroupAndMemberAdapter.Instance.Update(gm);

                            ProcessProgress.Current.Increment();
                            ProcessProgress.Current.Response();
                        }

                        scope.Complete();
                    }
                }

                ProcessProgress.Current.StatusText  = "";
                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.Response();
            }
            catch (Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }
        private void Send()
        {
            ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);

            if (VerifyInput())
            {
                try
                {
                    if (ddlAccount.SelectedIndex == 0)
                    {
                        WeChatAppMessage appMessage = null;
                        ProcessProgress.Current.MaxStep     = ddlAccount.Items.Count - 1;
                        ProcessProgress.Current.CurrentStep = 0;
                        ProcessProgress.Current.StatusText  = "";
                        ProcessProgress.Current.Response();

                        foreach (ListItem accountItem in ddlAccount.Items)
                        {
                            try
                            {
                                if (accountItem.Value == "-1")
                                {
                                    continue;
                                }

                                appMessage = SendOne(accountItem.Value, ddlGroups.SelectedItem);
                                ProcessProgress.Current.StatusText = string.Format("对帐号 {0} 发送成功!", accountItem.Text);
                                ProcessProgress.Current.Response();
                                Thread.Sleep(1000);
                            }
                            catch (Exception ex)
                            {
                                //WebUtility.ResponseShowClientErrorScriptBlock(ex);
                                ProcessProgress.Current.StatusText = string.Format("对帐号 {0} 发送失败,原因:{1}", accountItem.Text, ex.Message);
                                ProcessProgress.Current.Response();
                                Thread.Sleep(2000);
                            }
                            finally
                            {
                                ProcessProgress.Current.Increment();
                                ProcessProgress.Current.Response();
                            }
                        }

                        if (appMessage != null)
                        {
                            WeChatAppMessageAdapter.Instance.Update(appMessage);
                        }

                        ProcessProgress.Current.CurrentStep = 0;
                        ProcessProgress.Current.StatusText  = "";
                        ProcessProgress.Current.Response();
                    }
                    else
                    {
                        ProcessProgress.Current.MaxStep     = 1;
                        ProcessProgress.Current.CurrentStep = 0;
                        ProcessProgress.Current.StatusText  = "";
                        ProcessProgress.Current.Response();

                        var appMessage = SendOne(ddlAccount.SelectedValue, ddlGroups.SelectedItem);
                        WeChatAppMessageAdapter.Instance.Update(appMessage);

                        ProcessProgress.Current.Increment();
                        ProcessProgress.Current.Response();
                    }

                    //ClientScript.RegisterStartupScript(this.GetType(), "sendComplete", "alert('发送完毕!');", true);
                }
                catch (Exception ex)
                {
                    WebUtility.ResponseShowClientErrorScriptBlock(ex);
                }
                finally
                {
                    this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
                    this.Response.End();
                }
            }
            else
            {
                this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
            }
        }
Esempio n. 5
0
        private void SynchronizeToWeChat()
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);

                var allGroups = ConditionalGroupAdapter.Instance.LoadAll();
                var accounts  = AccountInfoAdapter.Instance.LoadAll();

                WeChatGroupCollection weChatGroups = WeChatGroupAdapter.Instance.LoadAll();

                ProcessProgress.Current.MaxStep     = allGroups.Count * accounts.Count;
                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.StatusText  = "开始同步...";
                ProcessProgress.Current.Response();

                foreach (var account in accounts)
                {
                    WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);

                    Thread.Sleep(1000);

                    foreach (var group in allGroups)
                    {
                        var fakeIDs = WeChatFriendAdapter.Instance.GetFakeIDsByLocalGroupID(group.GroupID).ToArray(); //找到本组里成员的fakeID

                        var matchedGroup = weChatGroups.Find(p => p.Name == group.Name && p.AccountID == WeChatRequestContext.Current.LoginInfo.AccountID);

                        int groupID = 0;
                        if (matchedGroup == null)
                        {
                            var modifiedGroup = WeChatHelper.AddGroup(group.Name, WeChatRequestContext.Current.LoginInfo);
                            var newGroup      = new WeChatGroup()
                            {
                                AccountID = account.AccountID,
                                GroupID   = modifiedGroup.GroupId,
                                Name      = group.Name,
                                Count     = modifiedGroup.MemberCnt
                            };

                            WeChatGroupAdapter.Instance.Update(newGroup);
                            Thread.Sleep(1000);
                            groupID = modifiedGroup.GroupId;
                        }
                        else
                        {
                            groupID = matchedGroup.GroupID;
                        }

                        if (fakeIDs.Length > 0)
                        {
                            WeChatHelper.ChangeFriendsGroup(groupID, fakeIDs, WeChatRequestContext.Current.LoginInfo);
                        }

                        ProcessProgress.Current.Increment();
                        ProcessProgress.Current.StatusText = string.Format("帐号\"{0}\",同步组\"{1}\"完成", account.UserID, group.Name);
                        ProcessProgress.Current.Response();
                        Thread.Sleep(1000);
                    }
                }

                ProcessProgress.Current.StatusText = string.Format("同步完成");
                ProcessProgress.Current.Response();
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }