Пример #1
0
        /// <summary>
        /// 获取队列
        /// </summary>
        /// <returns></returns>
        public List <QueueEntity.QueueModel> GetQueueList()
        {
            var uname = MediinfoConfig.GetValue("RabbitMQConfig.xml", "username");
            var pwd   = MediinfoConfig.GetValue("RabbitMQConfig.xml", "password");
            var hosts = MediinfoConfig.GetValue("RabbitMQConfig.xml", "hostnames");

            using (WebClient webClient = new WebClient())
            {
                webClient.Credentials = new NetworkCredential(uname, pwd);
                string queue = webClient.DownloadString("http://" + hosts.Split(',')[0] + ":15672/api/queues");
                List <QueueEntity.QueueModel> list =
                    JsonConvert.DeserializeObject <List <QueueEntity.QueueModel> >(queue);
                return(list);
            }
        }
Пример #2
0
        private RabitMQChannel(string vHost)
        {
            try
            {
                var uname = MediinfoConfig.GetValue("RabbitMQConfig.xml", "username");
                var pwd   = MediinfoConfig.GetValue("RabbitMQConfig.xml", "password");
                var hosts = MediinfoConfig.GetValue("RabbitMQConfig.xml", "hostnames");

                if (string.IsNullOrWhiteSpace(hosts) || string.IsNullOrWhiteSpace(uname) || string.IsNullOrWhiteSpace(pwd))
                {
                    LogHelper.Intance.Warn("消息队列", "消息队列未配置", "消息队列未配置,username:"******",password:"******"HIS_USERMSG_EXCHANGE", ExchangeType.Direct, true, false, null);
            }
            catch (Exception ex)
            {
                LogHelper.Intance.Error("消息队列", "消息初始化失败",
                                        "异常原因: " + ex.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// 处理消息
        /// </summary>
        /// <param name="dbMessage"></param>
        public virtual void Handler(DBContextBase dbContext)
        {
            if (!IsCallHandler())
            {
                return;
            }
            if (!dbMessage.Changed)
            {
                return;
            }

            // 获取服务信息
            string pathAndQuery = apiController.ActionContext.Request.RequestUri.PathAndQuery;
            string moKuaiMc     = pathAndQuery.Split('/')[1];
            string yeWuMc       = pathAndQuery.Split('/')[2];
            string caoZuoMc     = pathAndQuery.Split('/')[3];

            var            controller             = apiController.ActionContext.ControllerContext.Controller;
            var            serviceContextProperty = controller.GetType().BaseType.GetProperty("ServiceContext", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            ServiceContext serviceContext         = serviceContextProperty.GetValue(controller) as ServiceContext;

            // 记录当前服务的基本信息
            serviceInfo.Context  = serviceContext;
            serviceInfo.MoKuaiMc = moKuaiMc;
            serviceInfo.YeWuMc   = yeWuMc;
            serviceInfo.CaoZuoMc = caoZuoMc;

            bool async     = false;
            var  asyncList = MediinfoConfig.GetValue("SystemConfig.xml", "AsyncInterfaceServiceList").Split(',');

            foreach (var item in asyncList)
            {
                var list = item.Split('/');
                if (list.Count() != 3)
                {
                    continue;
                }
                var mokuaiming = list[0];
                var yewuming   = list[1];
                var caozuoming = list[2];

                if ((mokuaiming == "*" || mokuaiming.ToUpper() == serviceInfo.MoKuaiMc.ToUpper()) &&
                    (yewuming == "*" || yewuming.ToUpper() == serviceInfo.YeWuMc.ToUpper()) &&
                    (caozuoming == "*" || caozuoming.ToUpper() == serviceInfo.CaoZuoMc.ToUpper())
                    )
                {
                    async = true;
                    break;
                }
            }

            if (async)
            {
                Task.Run(() =>
                {
                    OracleConnectionStringBuilder haloOraConn = new OracleConnectionStringBuilder(MediinfoConfig.GetValue("DbConfig.xml", "HIS6"));
                    OracleConnection haloconn   = new OracleConnection();
                    haloconn.ConnectionString   = haloOraConn.ConnectionString;
                    DBContextBase haloDbContext = new DBContextBase(haloconn, true, haloOraConn.UserID.ToUpper());

                    OracleConnectionStringBuilder pgOraConn = new OracleConnectionStringBuilder(PluginDBConfig);
                    OracleConnection pgconn   = new OracleConnection();
                    pgconn.ConnectionString   = pgOraConn.ConnectionString;
                    DBContextBase pgDbContext = new DBContextBase(pgconn, true, pgOraConn.UserID.ToUpper());

                    var haloTrans = haloDbContext.Database.BeginTransaction();
                    var pgTrans   = pgDbContext.Database.BeginTransaction();

                    try
                    {
                        var pluginDll = Mediinfo.Enterprise.Config.MediinfoConfig.GetValue("SystemConfig.xml", "MessagePlugin");
                        var assembly  = Assembly.Load(pluginDll);

                        var types = assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IDbMessageHandler))).ToArray();

                        var impls = types.Where(t => !t.IsInterface).ToList();

                        foreach (var impl in impls)
                        {
                            var implInstance = (IDbMessageHandler)assembly.CreateInstance(impl.FullName);
                            implInstance.Handler(haloDbContext, pgDbContext, serviceInfo, dbMessage);
                        }

                        haloTrans.Commit();
                        pgTrans.Commit();
                    }
                    catch (Exception ex)
                    {
                        haloTrans.Rollback();
                        pgTrans.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        haloDbContext.Dispose();
                        pgDbContext.Dispose();
                        dbMessage = new DbMessage.DbMessage();
                    }
                });
            }
            else
            {
                OracleConnectionStringBuilder pgOraConn = new OracleConnectionStringBuilder(PluginDBConfig);
                OracleConnection pgconn = new OracleConnection();
                pgconn.ConnectionString = pgOraConn.ConnectionString;
                DBContextBase pgDbContext = new DBContextBase(pgconn, true, pgOraConn.UserID.ToUpper());

                var pgTrans = pgDbContext.Database.BeginTransaction();

                try
                {
                    var pluginDll = Mediinfo.Enterprise.Config.MediinfoConfig.GetValue("SystemConfig.xml", "MessagePlugin");
                    var assembly  = Assembly.Load(pluginDll);
                    var types     = assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IDbMessageHandler))).ToArray();

                    var impls = types.Where(t => !t.IsInterface).ToList();

                    foreach (var impl in impls)
                    {
                        var implInstance = (IDbMessageHandler)assembly.CreateInstance(impl.FullName);
                        implInstance.Handler(dbContext, pgDbContext, serviceInfo, dbMessage);
                    }

                    pgTrans.Commit();
                }
                catch (Exception ex)
                {
                    pgTrans.Rollback();
                    throw ex;
                }
                finally
                {
                    pgDbContext.Dispose();
                    dbMessage = new DbMessage.DbMessage();
                }
            }
        }