Ejemplo n.º 1
0
        public void Start(MessageConnectionCollection channels,
                          string url,
                          string groupName)
        {
            this.Url       = url;
            this.GroupName = groupName;
            this.Channels  = channels;

            //Channels.Login += _channels_Login;
            Channels.AddMessage -= _channels_AddMessage;
            Channels.AddMessage += _channels_AddMessage;

            Channels.ConnectionStateChange -= _channels_ConnectionStateChange;
            Channels.ConnectionStateChange += _channels_ConnectionStateChange;

            this.BeginThread();
        }
Ejemplo n.º 2
0
        public void Start(
            MessageConnectionCollection channels,
            string url,
            string groupName,
            string userName,
            string password)
        {
            this.Url       = url;
            this.UserName  = userName;
            this.Password  = password;
            this.GroupName = groupName;

            this.Channels = channels;

            Channels.Login      += _channels_Login;
            Channels.AddMessage += _channels_AddMessage;

            this.BeginThread();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="channels">通道集合</param>
        /// <param name="url"></param>
        /// <param name="groupName"></param>
        public void Start(MessageConnectionCollection channels,
                          string url,
                          string groupName)
        {
            this.Url       = url;
            this.GroupName = groupName;
            this.Channels  = channels;

            // 通道消息事件,一有消息就立即收到,与getmessage公众号这边主动获取是两个类别。
            // 注意设置消息接管事件时先减再加
            Channels.AddMessage -= _channels_AddMessage;
            Channels.AddMessage += _channels_AddMessage;

            // 通道连接状态变化消息
            Channels.ConnectionStateChange -= _channels_ConnectionStateChange;
            Channels.ConnectionStateChange += _channels_ConnectionStateChange;

            // 开始
            this.BeginThread();
        }
Ejemplo n.º 4
0
        /*
         * 微信公众号新图书馆dp2mserver账号
         * 命名:weixin_图书馆英文或中文简称(如weixin_cctb,weixin_tjsyzx)
         * 权限:getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes
         * 义务:空
         * 单位:图书馆名称
         * 群组:gn:_lib_bb
         * gn:_lib_book
         * gn:_lib_homePage
         *
         * ===
         * 新图书馆安装dp2capo时创建的dp2mserver账号
         * 命名:capo_图书馆英文或中文简称(如capo_cctb,capo_tjsyzx)
         * 权限:空
         * 义务:getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes
         * 单位:图书馆名称
         * 群组:gn:_patronNotify|-n
         * */

        async Task <bool> CreateCapoUser()
        {
            string strError = "";

            EnableControls(false);
            try
            {
                using (MessageConnectionCollection _channels = new MessageConnectionCollection())
                {
                    _channels.Login += _channels_LoginSupervisor;

                    MessageConnection connection = await _channels.GetConnectionAsyncLite(
                        this.textBox_url.Text,
                        "supervisor");

                    // 记忆用过的超级用户名和密码
                    this.ManagerUserName = connection.UserName;
                    this.ManagerPassword = connection.Password;

                    CancellationToken cancel_token = _cancel.Token;

                    string id = Guid.NewGuid().ToString();

                    string strDepartment = InputDlg.GetInput(
                        this,
                        "图书馆名",
                        "请指定图书馆名: ",
                        "",
                        this.Font);
                    if (strDepartment == null)
                    {
                        return(false);
                    }

                    bool bEanbleWebCall = false;
                    this.Invoke(new Action(() =>
                    {
                        DialogResult temp_result = MessageBox.Show(this,
                                                                   "是否允许 webCall (通过 dp2Router 访问 dp2library)?",
                                                                   "安装 dp2Capo",
                                                                   MessageBoxButtons.YesNo,
                                                                   MessageBoxIcon.Question,
                                                                   MessageBoxDefaultButton.Button2);
                        if (temp_result == System.Windows.Forms.DialogResult.Yes)
                        {
                            bEanbleWebCall = true;
                        }
                    }));

                    List <User> users = new List <User>();

                    User user = new User();
                    user.userName = this.textBox_userName.Text;
                    user.password = this.textBox_password.Text;
                    user.rights   = "";
                    // TODO: 看看除了 weixin_xxx 以外是否还有其他请求者需要许可
                    user.duty = ":weixinclient|" + MakeWeixinUserName(this.textBox_userName.Text) + ",getPatronInfo,searchBiblio,searchPatron,bindPatron,getBiblioInfo,getBiblioSummary,getItemInfo,circulation,getUserInfo,getRes,getSystemParameter";
                    if (bEanbleWebCall)
                    {
                        user.duty += ",webCall:router";
                    }
                    user.groups     = new string[] { "gn:_patronNotify|-n" };
                    user.department = strDepartment;
                    user.binding    = "ip:[current]";
                    user.comment    = "dp2Capo 专用账号";

                    users.Add(user);

                    MessageResult result = await connection.SetUsersAsyncLite("create",
                                                                              users,
                                                                              new TimeSpan(0, 1, 0),
                                                                              cancel_token);

                    if (result.Value == -1)
                    {
                        strError = "创建用户 '" + this.textBox_userName.Text + "' 时出错: " + result.ErrorInfo;
                        goto ERROR1;
                    }

                    return(true);
                }
            }
            catch (MessageException ex)
            {
                if (ex.ErrorCode == "Unauthorized")
                {
                    strError             = "以用户名 '" + ex.UserName + "' 登录时, 用户名或密码不正确";
                    this.ManagerUserName = "";
                    this.ManagerPassword = "";
                    goto ERROR1;
                }
                if (ex.ErrorCode == "HttpRequestException")
                {
                    strError = "dp2MServer URL 不正确,或 dp2MServer 尚未启动";
                    goto ERROR1;
                }
                strError = ex.Message;
                goto ERROR1;
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                EnableControls(true);
            }
ERROR1:
            this.Invoke(new Action(() =>
            {
                MessageBox.Show(this, strError);
            }));
            return(false);
        }
Ejemplo n.º 5
0
        async Task <bool> DetectUser()
        {
            string strError = "";

            EnableControls(false);
            try
            {
                using (MessageConnectionCollection _channels = new MessageConnectionCollection())
                {
                    _channels.Login += _channels_Login;

                    MessageConnection connection = await _channels.GetConnectionAsyncLite(
                        this.textBox_url.Text,
                        "");

                    CancellationToken cancel_token = _cancel.Token;

                    string            id      = Guid.NewGuid().ToString();
                    GetMessageRequest request = new GetMessageRequest(id,
                                                                      "",
                                                                      "gn:<default>", // "" 表示默认群组
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      0,
                                                                      1);
                    GetMessageResult result = await connection.GetMessageAsyncLite(
                        request,
                        new TimeSpan(0, 1, 0),
                        cancel_token);

                    if (result.Value == -1)
                    {
                        strError = "检测用户时出错: " + result.ErrorInfo;
                        goto ERROR1;
                    }

                    return(true);
                }
            }
            catch (MessageException ex)
            {
                if (ex.ErrorCode == "Unauthorized")
                {
                    strError = "以用户名 '" + ex.UserName + "' 登录时, 用户名或密码不正确";
                    goto ERROR1;
                }
                if (ex.ErrorCode == "HttpRequestException")
                {
                    strError = "dp2MServer URL 不正确,或 dp2MServer 尚未启动";
                    goto ERROR1;
                }
                strError = ex.Message;
                goto ERROR1;
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                EnableControls(true);
            }
ERROR1:
            this.Invoke(new Action(() =>
            {
                MessageBox.Show(this, strError);
            }));
            return(false);
        }
Ejemplo n.º 6
0
        async Task <bool> CreateRouterUser()
        {
            string strError = "";

            EnableControls(false);
            try
            {
                using (MessageConnectionCollection _channels = new MessageConnectionCollection())
                {
                    _channels.Login += _channels_LoginSupervisor;

                    MessageConnection connection = await _channels.GetConnectionAsyncLite(
                        this.textBox_url.Text,
                        "supervisor");

                    // 记忆用过的超级用户名和密码
                    this.ManagerUserName = connection.UserName;
                    this.ManagerPassword = connection.Password;

                    CancellationToken cancel_token = _cancel.Token;

                    string id = Guid.NewGuid().ToString();

                    List <User> users = new List <User>();

                    User user = new User();
                    user.userName = this.textBox_userName.Text;
                    user.password = this.textBox_password.Text;
                    user.rights   = "webCall";
                    user.duty     = "";
                    user.groups   = null;
                    user.comment  = "dp2Router 专用账号";
                    user.binding  = "ip:[current]";

                    users.Add(user);

                    MessageResult result = await connection.SetUsersAsyncLite("create",
                                                                              users,
                                                                              new TimeSpan(0, 1, 0),
                                                                              cancel_token);

                    if (result.Value == -1)
                    {
                        strError = "创建用户 '" + this.textBox_userName.Text + "' 时出错: " + result.ErrorInfo;
                        goto ERROR1;
                    }

                    return(true);
                }
            }
            catch (MessageException ex)
            {
                if (ex.ErrorCode == "Unauthorized")
                {
                    strError             = "以用户名 '" + ex.UserName + "' 登录时, 用户名或密码不正确";
                    this.ManagerUserName = "";
                    this.ManagerPassword = "";
                    goto ERROR1;
                }
                if (ex.ErrorCode == "HttpRequestException")
                {
                    strError = "dp2MServer URL 不正确,或 dp2MServer 尚未启动";
                    goto ERROR1;
                }
                strError = ex.Message;
                goto ERROR1;
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                EnableControls(true);
            }
ERROR1:
            this.Invoke(new Action(() =>
            {
                MessageBox.Show(this, strError);
            }));
            return(false);
        }