示例#1
0
        public string GetEventFrames()
        {
            var    db = InitializeAf();
            string result;

            if (db != null)
            {
                AFNamedCollectionList <AFEventFrame> eventFrames = AFEventFrame.FindEventFrames(db, null, "*", AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 0, 1000);
                var listEventFrames = new List <EventFrame>();
                foreach (var eventFrame in eventFrames)
                {
                    listEventFrames.Add(new EventFrame
                    {
                        Name     = eventFrame.Name,
                        Id       = eventFrame.ID.ToString(),
                        DateTime = eventFrame.EndTime.ToString()
                    });
                }

                var serializer = new JavaScriptSerializer();
                result = serializer.Serialize(listEventFrames);
            }
            else
            {
                result = "no db found";
            }

            return(result);
        }
示例#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);
                    }
                }
            }
        }
示例#3
0
        static void Main()
        {
            PISystems myPISystems = new PISystems();
            PISystem  myPISystem  = myPISystems.DefaultPISystem;

            Console.WriteLine("Please Enter the name of the AF Database");
            string     resp   = Console.ReadLine();
            AFDatabase myAFDB = myPISystem.Databases[resp];

            //Console.WriteLine("Please Enter a search start time");
            //string starttime = Console.ReadLine();

            //Console.WriteLine("Please Enter a search end time");
            //string endtime = Console.ReadLine();

            bool      MaxedEF;
            int       loopcount = 0;
            Stopwatch stopWatch = new Stopwatch();

            do
            {
                ++loopcount;
                Console.WriteLine("current loops count: {0}. Last iteration in ms: {1}", loopcount, stopWatch.ElapsedMilliseconds);
                //Console.WriteLine("current loops count: {0}.", loopcount);
                stopWatch.Reset();
                stopWatch.Start();
                OSIsoft.AF.AFNamedCollectionList <AFEventFrame> EventFrameList = AFEventFrame.FindEventFrames(myAFDB, null,
                                                                                                              null, AFSearchField.Description, true, AFSortField.StartTime, AFSortOrder.Ascending, 1000, 1000);

                if (EventFrameList.Count == 1000)
                {
                    MaxedEF = true;
                }
                else
                {
                    MaxedEF = false;
                }

                Parallel.ForEach(EventFrameList, EventFrame =>
                {
                    // Try Deleting the Event Frame
                    try
                    {
                        EventFrame.Delete();
                        EventFrame.CheckIn();
                        Console.WriteLine("Sucessfully Deleted Event Frame: {0}", EventFrame.Name);
                    }
                    catch
                    {
                        Console.WriteLine("Error, unable to Delete Event Frame: {0}", EventFrame.Name);
                    }
                });
                stopWatch.Stop();
            }while (MaxedEF == true);

            Console.WriteLine("Press Enter to Exit");
            Console.ReadKey();
        }
示例#4
0
        public string A_FindEventFrames(int threadNum = 0)
        {
            AFStopwatch myWatch = new AFStopwatch();

            AFNamedCollectionList <AFEventFrame> myEFs = AFEventFrame.FindEventFrames(_afDatabase, null, "*", AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 0, int.MaxValue);

            return($"A{threadNum}; Avg time = " + Math.Round((double)myWatch.ElapsedMilliseconds / myEFs.Count, 3) +
                   "ms per event frame, NumberofEFs = " + myEFs.Count + ", Time = " + myWatch.ElapsedMilliseconds);
        }
示例#5
0
        private void CleanEventFrames(DateTime startTime, DateTime endTime, string template)
        {
            this.Enabled = false;
            try {
                var efTemplate = _afDb.ElementTemplates[template];
                if (efTemplate == null)
                {
                    throw new Exception(string.Format("{0} not found", template));
                }

                int count = 0;
                while (true)
                {
                    var frames = AFEventFrame.FindEventFrames(_afDb, null, AFSearchMode.Overlapped, startTime, endTime, "*", "*", null,
                                                              efTemplate, null, false, AFSortField.StartTime, AFSortOrder.Ascending, 0, 1000);

                    if (frames.Count <= 0)
                    {
                        break;
                    }

                    progressBar1.Maximum = frames.Count;
                    progressBar1.Step    = 1;
                    progressBar1.Value   = 0;

                    foreach (AFEventFrame frame in frames)
                    {
                        double ts = frame.EndTime.UtcSeconds - frame.StartTime.UtcSeconds;

                        if (ts < 1.0 && string.Equals(frame.Template.Name, template))
                        {
                            try {
                                frame.Delete();
                                count++;

                                if (count >= 1000)
                                {
                                    _afDb.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisThread);
                                    count = 0;
                                }
                            } catch (Exception) {
                                // event frames may be locked by users
                            }
                        }

                        progressBar1.PerformStep();
                        Application.DoEvents();
                    }
                }
            } finally {
                this.Enabled = true;
                MessageBox.Show("Cleaning finished");
            }
        }
示例#6
0
        /// <summary>
        /// Starts a simple Name search using the text from the textbox.
        /// Updates the AFViewControl of elements that match the criteria.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bEFSearch_Click(object sender, EventArgs e)
        {
            string searchEF = tbEventFrameSearch.Text;
            AFNamedCollectionList <AFEventFrame> frames = null;

            frames = AFEventFrame.FindEventFrames(afDatabasePicker1.AFDatabase, null, "*" + searchEF + "*", AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 0, Int32.MaxValue);

            if (frames.Count > 0)
            {
                avcEventFrames.AFSetObject(frames, afDatabasePicker1.AFDatabase, null, null);

                avcEventFrames.AFSelection = frames[0];
                object selected = avcEventFrames.AFSelection;
                avcEventFrames_ItemSelected(this, null);
            }
        }
示例#7
0
        public string DeleteEventFrame(string mask)
        {
            if (currentDb == null)
            {
                currentDb = InitializeAf();
            }
            string result = String.Empty;
            AFNamedCollectionList <AFEventFrame> eventFrames = AFEventFrame.FindEventFrames(currentDb, null, mask + "*", AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 0, 10000);

            foreach (var eventFrame in eventFrames)
            {
                eventFrame.Delete();
                eventFrame.CheckIn();
            }
            return(eventFrames.Count.ToString());
        }
示例#8
0
        protected override List <Action> GetActions()
        {
            List <Action> actions = Constants.SourceSystemUniqueIds.Select(sourceSystemUniqueId => (Action)(() =>
            {
                var actionStopwatch = new AFStopwatch();
                actionStopwatch.Start();

                var eventFrames = AFEventFrame.FindEventFrames(AfDatabase, null, "*", AFSearchField.Name, true,
                                                               AFSortField.Name, AFSortOrder.Ascending, 0, int.MaxValue);
                TestOutput.AddActionResult(
                    new ActionPerformanceResult
                {
                    ActionMillis = actionStopwatch.ElapsedMilliseconds,
                    ResultCount = eventFrames.Count
                });
            })).ToList();

            return(actions);
        }
示例#9
0
        public void CreateEventFrameTest()
        {
            string path = Constants.AF_DATABASE_PATH;

            PIEventFrame eventFrame = new PIEventFrame()
            {
                Name      = Constants.AF_EVENT_FRAME_NAME + "3",
                StartTime = "*-2d",
                EndTime   = "*-1d"
            };

            instance.CreateEventFrame(webId, eventFrame);

            AFDatabase db = AFObject.FindObject(path) as AFDatabase;

            var results = AFEventFrame.FindEventFrames(db, null, string.Empty, AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 0, 100);

            Assert.IsTrue(results.Where(ev => ev.Name == eventFrame.Name).Count() == 1);
        }
示例#10
0
        /// <summary>
        /// Searches event frames that where ACTIVE at the specified time
        /// </summary>
        /// <remarks>There are a lot of ways to search event frames, this is just one way of doing it</remarks>
        /// <param name="afDatabase"></param>
        /// <param name="time"></param>
        /// Search mode is the key to understand how EFs are found, in this scenario we look for overlapped:
        /// <see cref="https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/T_OSIsoft_AF_Asset_AFSearchMode.htm"/>
        private void SearchEventFrames(AFDatabase afDatabase, string time)
        {
            try
            {
                var searchTime = new AFTime(time);

                Logger.InfoFormat("Searching for event frames in {0} database at time {1}", afDatabase.Name, searchTime);

                var eventFrames = AFEventFrame.FindEventFrames(
                    database: afDatabase,
                    searchRoot: null,
                    searchMode: AFSearchMode.Overlapped,
                    startTime: searchTime,
                    endTime: searchTime,
                    nameFilter: string.Empty,
                    referencedElementNameFilter: string.Empty,
                    eventFrameCategory: null,
                    eventFrameTemplate: null,
                    referencedElementTemplate: null,
                    durationQuery: null,
                    searchFullHierarchy: false,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: 0,
                    maxCount: 1000
                    );

                Logger.InfoFormat("Found {0} event frames: ", eventFrames.Count);
                foreach (var ef in eventFrames)
                {
                    Logger.InfoFormat("{0}-ST:{1}-ET:{2}", ef.Name, ef.StartTime, ef.EndTime);
                }
            }

            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];

            const int pageSize    = 1000;
            int       startIndex  = 0;
            int       returnLimit = 100000;

            do
            {
                AFElementTemplate efTemplate = afDatabase.ElementTemplates["BasicEventFrameTemplate"];

                // Get event frames that started the past two days.
                AFNamedCollectionList <AFEventFrame> eventFrames = AFEventFrame.FindEventFrames(
                    database: afDatabase,
                    searchRoot: null,
                    startTime: "t-2d",
                    startIndex: startIndex,
                    maxCount: pageSize,
                    searchMode: AFEventFrameSearchMode.ForwardFromStartTime,
                    nameFilter: "*",
                    referencedElementNameFilter: "BoilerA",
                    elemCategory: null,
                    elemTemplate: efTemplate,
                    searchFullHierarchy: true);

                foreach (AFEventFrame ef in eventFrames)
                {
                    //Note: We should make a bulk call on the attribute values via AFAttributeList if we had many event frames.
                    Console.WriteLine("Name: {0}, Start: {1}, End: {2}, Max temp: {3}",
                                      ef.Name, ef.StartTime, ef.EndTime, ef.Attributes["Maximum temperature"].GetValue());
                }

                startIndex += pageSize;
            } while (startIndex < returnLimit);
        }