zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    BZOJ1588_营业额统计_KEY
    关于欧几里得算法的认识
    javacv实战篇
    图像处理里面的的尺度什么?
    改成 否“依然报LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏”问题的解决
    javacv
    以前写过的一些oracle语句
    warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
    在vs环境中跑动sift特征提取(原理部分)
    《sift算法详解》阅读笔记
  • 原文地址:https://www.cnblogs.com/happyqiang/p/10791277.html
Copyright © 2011-2022 走看看