zoukankan      html  css  js  c++  java
  • rtx应用和开发

    因为公司内部网络做一定隔离,所以用rtx进行内部通讯,有个需求是对部分人的发送文件权限进行限制,但截图不限制

    根据rtx server  sdk的帮助文档看了一下,做了一个简单的rtx app

    原理是,对需要处理的部分人的信息进行拦截,只要带附件两个字的,都拦截掉,在官方的代码上进行了简单修改(把拦截进行了白名单制,就是放行的才可以通过)

    唯一要注意的是,代码需要用32位进行编译

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using RTXSAPILib;
    using System.Runtime.InteropServices;
    using System.IO;
    
    namespace IMWatch
    {
        public partial class Form1 : Form
        {
            RTXSAPILib.RTXSAPIRootObj RootObj;  //声明一个根对象
            RTXSAPILib.RTXSAPIObj ApiObj;       //声明一个应用对象
    
     
            RTXSAPILib.RTXSAPIDeptManager DeptManagerObj;       //声明一个部门管理对象
            List<string> users;
    
    
    
            public delegate void  ADDText(string RevContent);
            ADDText myDelegate;
    
            public Form1()
            {
                InitializeComponent();
                RootObj = new RTXSAPIRootObj();     //创建根对象
                ApiObj = RootObj.CreateAPIObj();    //通过根对象创建应用对象
    
                DeptManagerObj = RootObj.DeptManager;    //通过根对象创建部门管理对象
    
    
                ApiObj.OnRecvMessage += new _IRTXSAPIObjEvents_OnRecvMessageEventHandler(ApiObj_OnRecvMessage); //订阅一个事件,当收到客户端发过来的消息时触发该事件
    
                 myDelegate = new ADDText(ADDTextMethod);
            }
    
            private void ADDTextMethod(string RevContent)
            {
                txtResult.Text = RevContent;
            }
    
            private void ApiObj_OnRecvMessage(RTXSAPILib.RTXSAPIMessage Message) //接收到插件发来的消息触发该事件
            {
                string RevContent; 
                try
                {
                    RevContent = Message.Sender + "发送:" + Message.Content + "到:" + Message.Receivers; //显示数据
    
                    txtResult.BeginInvoke(myDelegate, RevContent);
                }
                catch (COMException xe)
                {
                    MessageBox.Show(xe.Message);
                }
    
            }
    
            private void btnRegApp_Click(object sender, EventArgs e)
            {
                txtFilterSender.Text = getwhitename();
    
    
                ApiObj.ServerIP = txtServerIP.Text;    //设置服务器IP,,必填参数
                ApiObj.ServerPort = Convert.ToInt16(txtServerPort.Text);    //设置服务器端口,,必填参数
                ApiObj.AppGUID = txtAppGuid.Text;      //设置应用GUID,,必填参数
                ApiObj.AppName = txtAppName.Text;      //设置应用名称,,必填参数
    
    
                if (txtFilterAction.Text == "distill")
                {
                    ApiObj.AppAction = RTXSAPI_APP_ACTION.AA_DISTILL;
                }
                else if (txtFilterAction.Text == "copy")        // 当过滤动作为AA_DISTILL时,ConServer把消息拷贝给应用后删除原来的消息。
                {
                    ApiObj.AppAction = RTXSAPI_APP_ACTION.AA_COPY; //设置过滤动作,当过滤动作为AA_COPY时,ConServer把消息拷贝一份给应用,但不会删除原来的消息。
                }
                else
                {
                    MessageBox.Show("输入有误,请重新输入");
    
                }
    
                ApiObj.FilterAppName = txtFilterApp.Text  ;   // 表示过滤所有应用,必填参数
                ApiObj.FilterRequestType = txtFilterRequestTy.Text; // 过滤消息类型,必填参数
                ApiObj.FilterResponseType =txtFilterResponseType.Text  ; // 无回复消息类型,必填参数
                ApiObj.FilterSender = "anyone";//txtFilterSender.Text  ;    //过滤所有发送人的该类消息,必填参数
                ApiObj.FilterReceiver = txtFilterReceiver.Text  ; //过滤所有接收人的该类消息,必填参数
                ApiObj.FilterReceiverState = txtReceiverState.Text ; // 关注所有状态,必填参数
                ApiObj.FilterKey = txtFilterKey .Text ;
    
    
                try
                {
    
    
                    btnRegApp.Enabled = false;
                    btnStopApp.Enabled = true;
    
    
                    users = new List<string>();
                    getDept("");
    
                    //设置白名单
                    string[] x = txtFilterSender.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = users.Count - 1; i >= 0; i--)
                    {
                        
                        for (int y = 0; y < x.Length; y++)
                        {
                            if (users[i] == x[y])
                            {
                                users.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    ApiObj.FilterSender = "anyone";
                    if (users.Count > 0)
                    {
                        ApiObj.FilterSender= string.Join("|", users.ToArray());
                    }
    
    
                    ApiObj.RegisterApp();   //注册应用
                    MessageBox.Show("注册成功");
                    btnStartApp_Click(null, null);
    
                }
                catch (COMException xe)
                {
                    MessageBox.Show(xe.Message);
                }
    
            }
            private string getwhitename()
            {
                string fp = @"whitename.txt";
                if (!File.Exists(fp))
                {
                    MessageBox.Show("没有找到白名单文件,将全部不能发送文件");
                    return "anyone";
                }
                string f = File.ReadAllText(fp,Encoding.Default);
    
                if (f == "")
                    f = "anyone";
                f= f.Replace("
    ","|");
                f = f.Replace("||", "|");
                while (f.Substring(f.Length-1,1)=="|" )
                {
                    f = f.Substring(0, f.Length - 1);
                }
                return f;
            }
            private void getDept(string dept)
            {
                try
                {
                    string txtChileDepts = DeptManagerObj.GetChildDepts(dept); //'查看某个部门的子部门
                    string[] t = txtChileDepts.Split(new string[] { """ }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 1; i < t.Length; i += 2)
                    {
                        Console.WriteLine("部门名称:" + t[i]);
                        getUser(t[i]);
    
                        getDept(t[i]);
                    }
    
                    //MessageBox.Show(txtChileDepts);
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.Message);
                }
    
            }
            private void getUser(string dept)
            {
                try
                {
                    string deptUsers = DeptManagerObj.GetDeptUsers(dept); //查看部门下的用户列表
    
                    string[] t = deptUsers.Split(new string[] { """ }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 1; i < t.Length; i += 2)
                    {
                        Console.WriteLine("人员名称:" + t[i]);
    
                        users.Add(t[i]);
                    }
    
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            private void btnStartApp_Click(object sender, EventArgs e)
            {
                try
                {
                    ApiObj.StartApp("", 4);     //启动应用
                    MessageBox.Show("启动成功");
                }
                catch (COMException xe)
                {
                    MessageBox.Show(xe.Message);
                }
            }
    
            private void btnStopApp_Click(object sender, EventArgs e)
            {
                try
                {
                    ApiObj.StopApp();   //停止应用
                    MessageBox.Show("停止成功");
                    btnUnregApp_Click(null, null);
                    btnStopApp.Enabled = false;
                    btnRegApp.Enabled = true;
                }
                catch (COMException xe)
                {
                    MessageBox.Show(xe.Message);
                }
            }
    
            private void btnUnregApp_Click(object sender, EventArgs e)
            {
                try
                {
                    ApiObj.ServerIP = txtServerIP.Text;    //设置服务器IP,,必填参数
                    ApiObj.ServerPort = Convert.ToInt16(txtServerPort.Text);    //设置服务器端口,,必填参数
                    ApiObj.AppGUID = txtAppGuid.Text;      //设置应用GUID,,必填参数
                    ApiObj.AppName = txtAppName.Text;      //设置应用名称,,必填参数
                    ApiObj.UnRegisterApp();     //注销应用
                    MessageBox.Show("注销成功");
                }
                catch (COMException xe)
                {
                    MessageBox.Show(xe.Message);
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                txtFilterSender.Text = getwhitename();
            }
        }
    }
    

      

  • 相关阅读:
    firefox ajax async 弹出窗口提示阻止
    Spring加载resource时classpath*:与classpath:的区别(转)
    超链接的href属性 js调用
    jquery easyui tabs layout 记录
    PostgreSQL 中的递归查询 与oracle 的比较
    将字符串中的中文(英文)字符串转化为阿拉伯数字
    用CSS控制文字的宽度,超过省略号代替(转)
    制作gridview 固定列的2种简单解决方案
    自制树型控件(DataGrid) 支持多种响应
    备忘: select 对象的操作js(转)
  • 原文地址:https://www.cnblogs.com/szyicol/p/14049765.html
Copyright © 2011-2022 走看看