コード例 #1
0
        public RestorationAlarmList GetRestorationAlarmPoint(AlarmList al, IEnumerable <DigitalPointInfo> groupByStations)
        {
            var RestorationAlarm = new RestorationAlarmList();

            var pointInfo = groupByStations.Where(c => c.PointName.Trim() == al.PointName.Trim()).FirstOrDefault();

            if (pointInfo == null)
            {
                return(null);
            }

            try
            {
                RestorationAlarm.DateTime    = al.Time;
                RestorationAlarm.PointType   = (Byte)al.pointType;
                RestorationAlarm.FkIndexID   = (int)al.FkIndex;
                RestorationAlarm.StationName = al.StationName;
                RestorationAlarm.PointName   = al.PointName;
                RestorationAlarm.ShortName   = pointInfo.ShortName;
                RestorationAlarm.AlarmType   = (int)al.AlarmType;
                RestorationAlarm.Flashing    = al.Flashing;
                RestorationAlarm.ActualValue = al.ActualValue;
                RestorationAlarm.Message     = al.Message;
                RestorationAlarm.SourceName  = al.SourceName;
                RestorationAlarm.SourceID    = al.SourceID;
                RestorationAlarm.SourceType  = (Byte)al.SourceType;
                RestorationAlarm.AlarmFlag   = (Byte)al.AlarmFlag;
                RestorationAlarm.DeviceID    = pointInfo.DeviceID;
                RestorationAlarm.DeviceType  = pointInfo.DeviceType;
                RestorationAlarm.MACName     = pointInfo.MACName;
                RestorationAlarm.Priority    = pointInfo.Priority;

                return(RestorationAlarm);
            }
            catch
            {
                Console.WriteLine($"Convertion Error");
                return(null);
            }
        }
コード例 #2
0
        public void RefreshConnection(ConnectionConfig connCfg)
        {
            _connCfg = connCfg;

            //Set Connection for CSV Repo [ Change only file Info]
            _mAlarmList.ConnCfg = _connCfg;

            //Re Create Database Repository [Can not set by only Connection string]
            _mRestorationAlarmList = new RestorationAlarmDBRepo(_connCfg);
            _mRestorationAlarmList.RestAlarmDBChanged += OnDBChanged; //Subcribe to RestAlarmDBChanged Event

            LastRestAlarmPoint = null;

            _mAlarmList.nLastAlarmRecIndex = -1; //Start Mode
            _flgMatchingInProgress         = false;
            this._nNewRestPoint            = 0;
            this.nLastAlarmRecIndex        = -1;
            this._dBStatus = false;

            _mAlarmList.CSVLastModify = DateTime.Now.AddYears(-1); //Reset CSV file's Last Mod date

            GetCSVData();                                          //Restart Get CSV data
        }
コード例 #3
0
        public DataProcessLogic(ConnectionConfig connCfg)
        {
            _connCfg = connCfg;

            _mAlarmList            = new AlarmListCSVRepo(_connCfg);
            _mRestorationAlarmList = new RestorationAlarmDBRepo(_connCfg);

            //_mRestAlarmList = new RestAlarmDBRepo();                //Test EF

            //AlarmListCSVRepo.RestAlarmCSVChanged += OnAlarmListChanged;
            _mAlarmList.RestAlarmCSVChanged += OnAlarmListChanged;

            //RestorationAlarmDBRepo.RestAlarmDBChanged += OnDBChanged;
            _mRestorationAlarmList.RestAlarmDBChanged += OnDBChanged;

            LastRestAlarmPoint = null;

            // _mRestorationAlarmList.RestAlarmDBChanged += OnDBChanged;

            _flgMatchingInProgress  = false;
            this._nNewRestPoint     = 0;
            this.nLastAlarmRecIndex = -1;
            this._dBStatus          = false;
        }
コード例 #4
0
        private async Task <bool> ProcessPoint(int StartIndex, RestEventArgs args)
        {
            this._nNewRestPoint = 0;

            this.RestAlarmList.Clear();

            if (_flgMatchingInProgress == true)
            {
                return(false);
            }

            _flgMatchingInProgress = true;

            for (int iIndex = StartIndex + 1; iIndex < _mAlarmList.ListAlarm.Count; iIndex++)
            {
                AlarmList al = _mAlarmList.ListAlarm[iIndex];
                if (al.pointType != PointType.Digital)
                {
                    continue;
                }

                var groupByStations = _DigitalPointInfoList.Where(c => c.StationName.Trim() == al.StationName.Trim()); // Grouping Station before Mapping

                RestorationAlarmList point = _mAlarmList.GetRestorationAlarmPoint(al, groupByStations);                //Mapping CSV Point --> DigitalPointInfo Table

                if (point != null)
                {
                    try
                    {
                        this.RestAlarmList.Add(point);
                        _nNewRestPoint++;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }

            //_mAlarmList.nStartIndex = _mAlarmList.ListAlarm.Count - 1; // Index start with 0
            //this.nLastAlarmRecIndex = _mAlarmList.nLastAlarmRecIndex;  //Update LastAlarmRecIndex Display


            try
            {
                _mRestorationAlarmList.RestAlarmContext.RestorationAlarmList.AddRange(this.RestAlarmList);
                _mRestorationAlarmList.Complete();

                var RestAlarmPointList = await Task.Run(() => _mRestorationAlarmList.GetRestorationAlarmListTimeDscAsync()); //Read RestorationAlarmList Table from DB

                if (RestAlarmPointList != null)
                {
                    LastRestAlarmPoint = RestAlarmPointList.FirstOrDefault(); //Get Last Record
                }
                args.message = args.message + " " + (_mAlarmList.ListAlarm.Count - StartIndex - 1).ToString() + $" Alarm(s),:=> { _nNewRestPoint} Restoration Alarm(s)";

                _mAlarmList.nStartIndex        = _mAlarmList.ListAlarm.Count - 1;                                      // Index start with 0
                _mAlarmList.nLastAlarmRecIndex = (int)_mAlarmList.ListAlarm[_mAlarmList.ListAlarm.Count - 1].RecIndex; //Update LastAlarm Index
                this.nLastAlarmRecIndex        = _mAlarmList.nLastAlarmRecIndex;                                       //Update LastAlarmRecIndex Display
                Console.WriteLine("Current Index : " + nLastAlarmRecIndex);

                Console.WriteLine($"{DateTime.Now.ToString()} : Finish Matching--> Has {_nNewRestPoint} Restoration Alarm(s)");

                UpdateActivityMonitor(args, "Activity");        //Upadte Activity after Dataprocessing
                UpdateConnectionStatus(args, "DBStatus", true); //Update Database Status

                //_mAlarmList.ListAlarm.Clear(); //Clear Data after using
            }
            catch
            {
                Console.WriteLine("Error while Inser to DB");
                args.message = "Error while inser to DB";
                UpdateActivityMonitor(args, "Activity");
                return(true);
            }
            finally
            {
                _flgMatchingInProgress = false;
            }

            //updateLogConsole((int)EventLogPosition.REST_NEW_POINT, $"Has {_nNewRestPoint} Restoration Alarm(s)");

            return(true);
        }
コード例 #5
0
        private async Task <bool> onStartProcess(RestEventArgs args)
        {
            this._nNewRestPoint = 0;

            this.RestAlarmList.Clear();

            if (!isDBConnected())
            {
                Console.WriteLine("DBConnection Error");
                _mAlarmList.nLastAlarmRecIndex = -1;             // Reset to Ready State for Start Next time when DB Connected

                UpdateConnectionStatus(args, "DBStatus", false); //Update Database File Status
                return(false);
            }


            var RestAlarmPointList = await _mRestorationAlarmList.GetRestorationAlarmListTimeDscAsync(); //Read RestorationAlarmList Table from DB

            if (RestAlarmPointList != null)
            {
                LastRestAlarmPoint = RestAlarmPointList.FirstOrDefault(); //Get Last Record
            }

            var LastCsvItem = _mAlarmList.ListAlarm.FirstOrDefault(); //Get First CSV Item

            this.nLastAlarmRecIndex = _mAlarmList.nLastAlarmRecIndex; //Update LastAlarmRecIndex Display

            if (RestAlarmPointList.Count == 0 ||
                LastRestAlarmPoint.DateTime < LastCsvItem.Time) //Empty Database
            {
                //Refresh Point from Database
                _DigitalPointInfoList = await _mRestorationAlarmList.GetAllDigitalPointInfoAsync();

                if (_DigitalPointInfoList == null)
                {
                    return(false);                         //Can't Access Database
                }
                return(await ProcessPoint(_mAlarmList.nStartIndex, args));
            }


            //Step 1 Compare Last DigitalPointInfoList Point
            int       StartIndex = 0;
            AlarmList StartPoint = null;

            foreach (var item in _mAlarmList.ListAlarm)
            {
                StartIndex++;

                if (item.StationName.Trim() != LastRestAlarmPoint.StationName.Trim())
                {
                    continue;
                }
                if (item.PointName.Trim() != LastRestAlarmPoint.PointName.Trim())
                {
                    continue;
                }
                if (item.Time == LastRestAlarmPoint.DateTime)
                {
                    StartPoint = item; //Start Position
                    break;
                }
            }

            if (StartPoint == null)     //No Match point
            {
                StartIndex = -1;
            }

            //Refresh Point from Database
            _DigitalPointInfoList = await _mRestorationAlarmList.GetAllDigitalPointInfoAsync();

            if (_DigitalPointInfoList == null)
            {
                return(false);                         //Can't Access Database
            }
            // UpdateConnectionStatus(args, "DBStatus", true);//Update Database File Status
            return(await ProcessPoint(StartIndex, args));
        }