Example #1
0
        static void Main(string[] args)
        {
            PISystems myPISystems = new PISystems();
            PISystem  myPISystem = myPISystems[EventFrameTest.Properties.Settings.Default.AFSystemName];
            object    sysCookie, dbCookie;

            AFDatabases myDBs = myPISystem.Databases;
            AFDatabase  myDB  = myDBs[EventFrameTest.Properties.Settings.Default.AFDBName];

            myPISystem.FindChangedItems(false, int.MaxValue, null, out sysCookie);
            myDB.FindChangedItems(false, int.MaxValue, null, out dbCookie);

            // Find changes made while application not running.
            List <AFChangeInfo> list = new List <AFChangeInfo>();

            list.AddRange(myPISystem.FindChangedItems(false, int.MaxValue, sysCookie, out sysCookie));
            list.AddRange(myDB.FindChangedItems(false, int.MaxValue, dbCookie, out dbCookie));

            // Refresh objects that have been changed.
            AFChangeInfo.Refresh(myPISystem, list);
            foreach (AFChangeInfo info in list)
            {
                AFChangeInfoAction ac    = info.Action;
                AFObject           myObj = info.FindObject(myPISystem, true);
                AFIdentity         myID  = myObj.Identity;
                if (myID == AFIdentity.EventFrame && ac == AFChangeInfoAction.Added)
                {
                    Console.WriteLine("Found changed object: {0}", myObj);
                }
            }
            Console.ReadLine();
        }
Example #2
0
        internal static void OnChanged(object sender, AFChangedEventArgs e)
        {
            //Console.WriteLine(sender);
            //Console.WriteLine(e);

            // Find changes made while application not running.
            List <AFChangeInfo> list = new List <AFChangeInfo>();

            list.AddRange(myPISystem.FindChangedItems(true, int.MaxValue, sysCookie, out sysCookie));
            list.AddRange(monitoredDB.FindChangedItems(true, int.MaxValue, dbCookie, out dbCookie));

            // Refresh objects that have been changed.
            AFChangeInfo.Refresh(myPISystem, list);
            foreach (AFChangeInfo info in list)
            {
                AFChangeInfoAction ac    = info.Action;
                AFObject           myObj = info.FindObject(myPISystem, true);
                AFIdentity         myID  = myObj.Identity;
                if (myID == AFIdentity.EventFrame && ac == AFChangeInfoAction.Added)
                {
                    AFEventFrame myEFinfo = (AFEventFrame)info.FindObject(myPISystem, true);
                    AFNamedCollectionList <AFEventFrame> myEFList = AFEventFrame.FindEventFrames(monitoredDB, null, new AFTime("*"), 0, 5, AFEventFrameSearchMode.BackwardFromEndTime, "", "", null, myEFinfo.Template, true);
                    foreach (AFEventFrame EF in myEFList)
                    {
                        Console.WriteLine(EF.Name);
                    }
                }
            }
        }
        public DatabaseMonitoring(LimitCalculation calculation)
        {
            this.calculation = calculation;
            afdatabase       = calculation.afdatabase;
            logger.Info($"Monitoring the database: {afdatabase}");
            // Initialize the cookie (bookmark)
            afdatabase.FindChangedItems(false, int.MaxValue, null, out cookie);

            refreshTimer.Elapsed += new ElapsedEventHandler(OnElapsed);
            afdatabase.Changed   += new EventHandler <AFChangedEventArgs>(OnChanged);
            refreshTimer.Start();
        }
        public void RefreshLoadedObjects()
        {
            var changes = _database.FindChangedItems(AFIdentity.Element, false, int.MaxValue, _cookie, out _cookie);

            _logger.InfoFormat("Found {0} changes in the database", changes.Count);
            foreach (var afChangeInfo in changes)
            {
                _logger.DebugFormat("Update found element ID {1},Update is value update: {0}", afChangeInfo.IsValueUpdate, afChangeInfo.ID);
            }

            // Refresh objects that have been changed.
            AFChangeInfo.Refresh(_database.PISystem, changes);
        }
        internal void OnChanged(object sender, AFChangedEventArgs e)
        {
            List <AFChangeInfo> changes = new List <AFChangeInfo>();

            changes.AddRange(afdatabase.FindChangedItems(true, int.MaxValue, cookie, out cookie));
            AFChangeInfo.Refresh(afdatabase.PISystem, changes);

            foreach (AFChangeInfo info in changes.FindAll(change => change.Identity == AFIdentity.EventFrame))
            {
                if (info.Action != AFChangeInfoAction.Removed)
                {
                    AFEventFrame lastestEventFrame = (AFEventFrame)info.FindObject(afdatabase.PISystem, true);
                    logger.Debug($"A new event to verify: {lastestEventFrame.Name}");
                    calculation.performAction(lastestEventFrame, info.Action);
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            myPISystems = new PISystems();
            myPISystem  = myPISystems[EventFrameTest.Properties.Settings.Default.AFSystemName];
            object sysCookie, dbCookie;

            monitoredDBs = myPISystem.Databases;
            monitoredDB  = monitoredDBs[EventFrameTest.Properties.Settings.Default.AFDBName];

            myPISystem.FindChangedItems(false, int.MaxValue, null, out sysCookie);
            monitoredDB.FindChangedItems(false, int.MaxValue, null, out dbCookie);

            //Timer
            elapsedEH             = new System.Timers.ElapsedEventHandler(OnElapsed);
            refreshTimer.Elapsed += elapsedEH;
            changedEH             = new EventHandler <AFChangedEventArgs>(OnChanged);
            monitoredDB.Changed  += changedEH;
            refreshTimer.Start();

            System.Threading.Thread.Sleep(60 * 5000);
            monitoredDB.Changed  -= changedEH;
            refreshTimer.Elapsed -= elapsedEH;
            refreshTimer.Stop();
        }