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
  • 相关阅读:
    According to TLD or attribute directive in tag file, attribute end does not accept any expressions
    Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are already in use.
    sql注入漏洞
    Servlet—简单的管理系统
    ServletContext与网站计数器
    VS2010+ICE3.5运行官方demo报错----std::bad_alloc
    java 使用相对路径读取文件
    shell编程 if 注意事项
    Ubuntu12.04下eclipse提示框黑色背景色的修改方法
    解决Ubuntu环境变量错误导致无法正常登录
  • 原文地址:https://www.cnblogs.com/happyqiang/p/10791277.html
Copyright © 2011-2022 走看看