Esempio n. 1
0
        public override IMessage Invoke(IMessage msg)
        {
            var mc     = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            var method = mc.MethodBase as MethodInfo;

            if (method == null)
            {
                throw new NullReferenceException("Method is null");
            }

            var    args = ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.SpecialName) ? mc.InArgs : mc.Args;
            object res;

            var argumentkey = cacheManager.GetArgumentKey(cacheName, method, args);
            var key         = argumentkey ?? cacheManager.GetKey(method.Name, ApplicationArgs(args));

            if (IsCached(key, out res))
            {
                return(CreateReturnMessage(mc, res));
            }
            using (cacheManager.AcquireLock(cacheName, key))
            {
                if (IsCached(key, out res))
                {
                    return(CreateReturnMessage(mc, res));
                }
                res = InvokeMethod(method, args);
                AddToCache(key, res);
            }

            return(CreateReturnMessage(mc, res));
        }
Esempio n. 2
0
        /// <summary>
        /// 获得所有活动告警
        /// <para>
        /// 活动告警未排序,获得后需手动排序
        /// </para>
        /// </summary>
        public List <AlmStore <A_AAlarm> > AllAlarms()
        {
            if (_cachedAllAlarms != null)
            {
                return(_cachedAllAlarms);
            }

            // 缓存活动告警,减小服务器压力
            List <A_AAlarm> _allAlarms = null;

            #region 正常告警
            IEnumerable <AlmStore <A_AAlarm> > _actAlarms = null;
            if (!_cacheManager.IsSet(GlobalCacheKeys.Active_Alarms))
            {
                //临界锁,防止多个请求同时计算并缓存告警
                using (_cacheManager.AcquireLock("LOCK:ACTIVE:ALARM", 10))
                {
                    if (!_cacheManager.IsSet(GlobalCacheKeys.Active_Alarms))
                    {
                        if (_allAlarms == null)
                        {
                            _allAlarms = _aalarmService.GetAlarms();
                        }
                        var _alarms = _allAlarms.FindAll(a => !Common.IsSystemAlarm(a.FsuId));
                        if (_alarms.Count > 0)
                        {
                            var _signals = _signalService.GetSimpleSignals(_alarms.Select(a => new Kv <string, string>(a.DeviceId, a.PointId)));
                            var _points  = this.GetALPoints();
                            var _devices = this.GetAllDevices();
                            _actAlarms = from alarm in _alarms
                                         join signal in _signals on new { alarm.DeviceId, alarm.PointId } equals new { signal.DeviceId, signal.PointId }
                            join point in _points on alarm.PointId equals point.Id
                            join device in _devices on alarm.DeviceId equals device.Id
                                 select new AlmStore <A_AAlarm>
                            {
                                Current         = alarm,
                                PointName       = signal.PointName,
                                AlarmName       = point.Name,
                                DeviceName      = device.Name,
                                DeviceTypeId    = device.Type.Id,
                                SubDeviceTypeId = device.SubType.Id,
                                SubLogicTypeId  = device.SubLogicType.Id,
                                RoomName        = device.RoomName,
                                RoomTypeId      = device.RoomTypeId,
                                StationName     = device.StationName,
                                StationTypeId   = device.StaTypeId,
                                AreaName        = device.AreaName,
                                SubCompany      = device.SubCompany ?? ""
                            };

                            _cacheManager.AddItemsToList <AlmStore <A_AAlarm> >(GlobalCacheKeys.Active_Alarms, _actAlarms, GlobalCacheInterval.ActAlarm_Interval);
                        }
                    }
                    else
                    {
                        _actAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.Active_Alarms);
                    }
                }
            }
            else
            {
                _actAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.Active_Alarms);
            }
            #endregion

            #region SC告警
            IEnumerable <AlmStore <A_AAlarm> > _scAlarms = null;
            if (!_cacheManager.IsSet(GlobalCacheKeys.System_SC_Alarms))
            {
                //临界锁,防止多个请求同时计算并缓存告警
                using (_cacheManager.AcquireLock("LOCK:SYSTEM:SC:ALARM", 10))
                {
                    if (!_cacheManager.IsSet(GlobalCacheKeys.System_SC_Alarms))
                    {
                        if (_allAlarms == null)
                        {
                            _allAlarms = _aalarmService.GetAlarms();
                        }
                        var _alarms = _allAlarms.FindAll(a => Common.IsSystemSCAlarm(a.FsuId));
                        if (_alarms.Count > 0)
                        {
                            var _points = this.GetALPoints();
                            var _groups = this.GetGroups();
                            _scAlarms = from alarm in _alarms
                                        join point in _points on alarm.PointId equals point.Id
                                        join sc in _groups on alarm.DeviceId equals sc.Id
                                        select new AlmStore <A_AAlarm>
                            {
                                Current         = alarm,
                                PointName       = point.Name,
                                AlarmName       = point.Name,
                                DeviceName      = sc.Name,
                                DeviceTypeId    = SSHSystem.SC.Type.Id,
                                SubDeviceTypeId = SSHSystem.SC.SubType.Id,
                                SubLogicTypeId  = SSHSystem.SC.SubLogicType.Id,
                                RoomName        = SSHSystem.Room.Name,
                                RoomTypeId      = SSHSystem.Room.Type.Id,
                                StationName     = SSHSystem.Station.Name,
                                StationTypeId   = SSHSystem.Station.Type.Id,
                                AreaName        = SSHSystem.Area.Name,
                                SubCompany      = ""
                            };

                            _cacheManager.AddItemsToList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_SC_Alarms, _scAlarms, GlobalCacheInterval.ActAlarm_Interval);
                        }
                    }
                    else
                    {
                        _scAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_SC_Alarms);
                    }
                }
            }
            else
            {
                _scAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_SC_Alarms);
            }
            #endregion

            #region FSU告警
            IEnumerable <AlmStore <A_AAlarm> > _fsuAlarms = null;
            if (!_cacheManager.IsSet(GlobalCacheKeys.System_FSU_Alarms))
            {
                //临界锁,防止多个请求同时计算并缓存告警
                using (_cacheManager.AcquireLock("LOCK:SYSTEM:FSU:ALARM", 10))
                {
                    if (!_cacheManager.IsSet(GlobalCacheKeys.System_FSU_Alarms))
                    {
                        if (_allAlarms == null)
                        {
                            _allAlarms = _aalarmService.GetAlarms();
                        }
                        var _alarms = _allAlarms.FindAll(a => Common.IsSystemFSUAlarm(a.FsuId));
                        if (_alarms.Count > 0)
                        {
                            var _points = this.GetALPoints();
                            var _fsus   = this.GetAllFsus();
                            _fsuAlarms = from alarm in _alarms
                                         join point in _points on alarm.PointId equals point.Id
                                         join fsu in _fsus on alarm.DeviceId equals fsu.Id
                                         select new AlmStore <A_AAlarm>
                            {
                                Current         = alarm,
                                PointName       = point.Name,
                                AlarmName       = point.Name,
                                DeviceName      = fsu.Name,
                                DeviceTypeId    = SSHSystem.FSU.Type.Id,
                                SubDeviceTypeId = SSHSystem.FSU.SubType.Id,
                                SubLogicTypeId  = SSHSystem.FSU.SubLogicType.Id,
                                RoomName        = fsu.RoomName,
                                RoomTypeId      = fsu.RoomTypeId,
                                StationName     = fsu.StationName,
                                StationTypeId   = fsu.StaTypeId,
                                AreaName        = fsu.AreaName,
                                SubCompany      = ""
                            };

                            _cacheManager.AddItemsToList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_FSU_Alarms, _fsuAlarms, GlobalCacheInterval.ActAlarm_Interval);
                        }
                    }
                    else
                    {
                        _fsuAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_FSU_Alarms);
                    }
                }
            }
            else
            {
                _fsuAlarms = _cacheManager.GetItemsFromList <AlmStore <A_AAlarm> >(GlobalCacheKeys.System_FSU_Alarms);
            }
            #endregion

            _cachedAllAlarms = new List <AlmStore <A_AAlarm> >();
            if (_actAlarms != null && _actAlarms.Any())
            {
                _cachedAllAlarms.AddRange(_actAlarms);
            }
            if (_scAlarms != null && _scAlarms.Any())
            {
                _cachedAllAlarms.AddRange(_scAlarms);
            }
            if (_fsuAlarms != null && _fsuAlarms.Any())
            {
                _cachedAllAlarms.AddRange(_fsuAlarms);
            }

            return(_cachedAllAlarms = _cachedAllAlarms.OrderByDescending(a => a.Current.AlarmTime).ToList());
        }