Пример #1
0
        private void OnDBChanged(object source, RestEventArgs args)
        {
            switch (args.message)
            {
            case "Read DB Success":
                Console.WriteLine(args.TimeStamp.ToString() + " : Read Database Success");
                break;

            case "Read DB Fail":
                Console.WriteLine(args.TimeStamp.ToString() + " : Read Database Fail");
                break;

            case "Reset":
                Console.WriteLine(args.TimeStamp.ToString() + " : Reset DB");
                break;

            case "Connected":
                //UpdateActivityMonitor(args, "Activity");
                _dBStatus = true;
                UpdateConnectionStatus(args, "DBStatus", _dBStatus);    //Update CSV File Status
                break;

            case "Disconnected":
                //UpdateActivityMonitor(args, "Activity");
                _dBStatus = false;
                UpdateConnectionStatus(args, "DBStatus", _dBStatus);    //Update Database File Status
                break;

            default:
                Console.WriteLine(DateTime.Now.ToString() + " : Main Alarm List No Msg. match");
                break;
            }
        }
Пример #2
0
        private void UpdateConnectionStatus(RestEventArgs args, string _target, bool state)
        {
            //EventChangedEventArgs LogArg = new EventChangedEventArgs();

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

            if (_target == "CSVStatus")
            {
                CSVLastModify = _mAlarmList.CSVLastModify;
                strCSVStatus  = state ? "Connection OK" : "Connection Fail";

                CSVFile            = this._connCfg.CsvFile;
                CSVLastAlarm       = LastCsvItem != null ? (LastCsvItem.Time.ToString() + " : " + LastCsvItem.PointName) : "Non";
                CSVBackgroundColor = state ? Brushes.Green : Brushes.Red;
            }
            else if (_target == "DBStatus")
            {
                //var db = new RestorationAlarmDbContext();
                DBLastAccess = args.TimeStamp;
                strDBStatus  = state ? "Database Connected" : "Can't Connect to Database";

                DBName            = this._connCfg.Server + ": " + this._connCfg.Database;
                DBSLastRec        = LastRestAlarmPoint != null ? (LastRestAlarmPoint.DateTime.ToString() + " : " + LastRestAlarmPoint.ShortName) : "Non";
                DBBackgroundColor = state ? Brushes.Green : Brushes.Red;
            }
        }
Пример #3
0
        private void UpdateActivityMonitor(RestEventArgs args, string _target)
        {
            EventChangedEventArgs LogArg = new EventChangedEventArgs();

            LogArg.TimeStamp = args.TimeStamp;
            LogArg.Message   = args.message;
            LogArg.Target    = _target;

            onUpdateActivityMonitor(LogArg);
        }
Пример #4
0
        private async void OnAlarmListChanged(object source, RestEventArgs args)
        {
            // throw new NotImplementedException();

            EventChangedEventArgs LogArg = new EventChangedEventArgs();

            switch (args.message)
            {
            case "Read CSV Success":
                Console.WriteLine(args.TimeStamp.ToString() + " : Read AlarmList.csv Success");
                onCheckCSVData();
                UpdateConnectionStatus(args, "CSVStatus", true);    //Update CSV File Status

                break;

            case "Read CSV Fail":
                Console.WriteLine(args.TimeStamp.ToString() + " : Read AlarmList.csv Fail");
                //updateLogConsole((int)EventLogPosition.CSV_STATUS , "Read CSV Fail");
                UpdateActivityMonitor(args, "Activity");
                UpdateConnectionStatus(args, "CSVStatus", false);    //Update CSV File Status

                break;

            case "Has New Alarm":
                Console.WriteLine(args.TimeStamp.ToString() + " : "
                                  + (_mAlarmList.ListAlarm.Count - _mAlarmList.nStartIndex - 1).ToString() + " New Alarm(s)");
                await this.onHasNewAlarm(args);

                break;

            case "No New Alarm":
                Console.WriteLine(args.TimeStamp.ToString() + " : No New Alarm");
                UpdateActivityMonitor(args, "Activity");

                break;

            case "Start Process":
                Console.WriteLine(args.TimeStamp.ToString() + " : Start Data Processing");
                await this.onStartProcess(args);

                //UpdateActivityMonitor(args, "Activity");
                break;

            default:
                Console.WriteLine(DateTime.Now.ToString() + " : Main Alarm List No Msg. match");
                //UpdateActivityMonitor(args, "Activity");
                break;
            }
        }
Пример #5
0
        private async Task <bool> onHasNewAlarm(RestEventArgs args)
        {
            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);
            }

            //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(_mAlarmList.nStartIndex, args));
        }
Пример #6
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);
        }
Пример #7
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));
        }