• c#+cad2010+MQ接收消息


    cad2015+版本可以使用TrayItem气泡显示消息

       static TrayItem trayItem = new TrayItem();
            public static void testtrayitem()
            {
                try
                {
    
                    //新建一个气泡通知窗口
                    TrayItemBubbleWindow window = new TrayItemBubbleWindow();
                    window.Title = "气泡标题";
                    window.HyperText = "气泡内容连接";
                    window.Text = "气泡内容";
                    window.IconType = IconType.Information;
    
                    Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.TrayItems.Add(trayItem);
                    trayItem.ShowBubbleWindow(window);
                    Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update();
                    //气泡窗口关闭事件
                    //window.Closed += (sender, e) =>
                    //{
                    //    if (e.CloseReason == TrayItemBubbleWindowCloseReason.HyperlinkClicked)
                    //    {
                    //        System.Windows.MessageBox.Show("关闭气泡消息");
    
                    //    }
                    //    //气泡窗口关闭后,将托盘从状态栏删除
                    //    //Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.TrayItems.Remove(trayItem);
                    //    //Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update();
                    //};
                    System.Timers.Timer t = new System.Timers.Timer(10000);
                    t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_ChangePos);//到达时间的时候执行事件;                  
                    t.AutoReset = false;//设置是执行一次(false)还是一直执行(true);                
                    t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
                }
                catch (System.Exception ex)
                {
                    trayItem.CloseBubbleWindows();
                }
    
            }
            private static void Timer_ChangePos(object sender, System.Timers.ElapsedEventArgs e)
            {
                trayItem.CloseBubbleWindows();
            }
    

      cad2010+mq+dotnetbar的 DevComponents.DotNetBar.Balloon窗体:

    IExtensionApplication接口下:

    //为了能及时接收消息
    RabbitMQClient mq = new RabbitMQClient();

      public  class RabbitMQClient
        {
            private string exchangeName = "topic_logs"; //
            private string exchangeType = ExchangeType.Topic;//交换机类型
            Action<string, Form> SetText;
            public RabbitMQClient()
            {
                if (CommandFun.frmmsg==null)
                {
                    CommandFun.frmmsg = new FrmMsg();
                }
                ReceiveMsg(CommandFun.frmmsg);
                SetText += CommandFun.ShowLoadAlert;
            }
            public  void ReceiveMsg(Form frm)
            {
                var factory = new ConnectionFactory()
                {
                    HostName = "iporlocalhost",
                    Port = 端口,
                    UserName = "administrator",
                    Password = "密码"
                };
                try
                {
    
                    var connection = factory.CreateConnection();
                    var channel = connection.CreateModel();
    
                    channel.ExchangeDeclare(exchangeName, exchangeType);
                    var queueName = channel.QueueDeclare().QueueName;
    
    
                        channel.QueueBind(queueName, exchangeName, "*.*.two");
                        channel.QueueBind(queueName, exchangeName, "two.#");
    
                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var msg = Encoding.UTF8.GetString(ea.Body);
                        if (msg!=null && msg.ToString().Length>0)
                        {
                            if (frm == null)
                            {
                                frm =CommandFun.frmmsg;
                            }
                            frm.Invoke(SetText, msg, frm);
                        }
                    };
                    channel.BasicConsume(queueName, true, consumer);
                }
                catch (System.Exception ex)
                {
    
                }
            }
        }
    View Code
    接收到消息时调用方法show出窗体:
       public class CommandFun
        {
           public static FrmMsg frmmsg;//接收到消息
           //弹出右下角消息窗口
           public static void ShowLoadAlert(string msg, System.Windows.Forms.Form frmmsg)
           {
               FrmMsg m_AlertOnLoad = new FrmMsg();
               Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;// GetWorkingArea(this);
               m_AlertOnLoad.Location = new Point(r.Right - m_AlertOnLoad.Width, r.Bottom - m_AlertOnLoad.Height);
               m_AlertOnLoad.AutoClose = true;
               m_AlertOnLoad.AutoCloseTimeOut = 60;
               m_AlertOnLoad.AlertAnimation = eAlertAnimation.BottomToTop;
               m_AlertOnLoad.AlertAnimationDuration = 2000;
               m_AlertOnLoad.SetLableText(msg);
               m_AlertOnLoad.Show(false);
           }
    
         
        }
    CommandFun

    窗体:

      public partial class FrmMsg : DevComponents.DotNetBar.Balloon
        {
            public FrmMsg()
            {
                CheckForIllegalCrossThreadCalls = false;
                InitializeComponent();
            }
    
            public void SetLableText(string msg)
            {
                lbl_msg.Text = string.Format("{0}
    ", msg);
            }
        }
    FrmMsg
  • 相关阅读:
    Asp.Net Core 2.0 项目实战(11) 基于OnActionExecuting全局过滤器,页面操作权限过滤控制到按钮级 郑州
    NET项目反编译+VS解决方案整理流程 郑州
    iis 目录枚举文件枚举解决方案 郑州
    Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员、后台管理员同时登录 郑州
    SqlServer mssql 按月统计所有部门 郑州
    无法获得数据库 'model' 上的排他锁 解决方法 郑州
    Asp.Net Core 2.0 项目实战(5)Memcached踩坑,基于EnyimMemcachedCore整理MemcachedHelper帮助类。 郑州
    谈谈前端怎样布局切图,程序可以方便快捷添加程序 郑州
    各种UIColor颜色的设置
    iOS
  • 原文地址:https://www.cnblogs.com/happyqiang/p/10791277.html
Copyright © 2020-2023  润新知