private void CreateEventFrames(AFDatabase afDatabase)
        {
            AFElementTemplate efTemplate = afDatabase.ElementTemplates["BasicEventFrameTemplate"];
            for (int i = 0; i < 5; i++)
            {
                AFEventFrame ef = new AFEventFrame(afDatabase, "EF_" + i, efTemplate);
                ef.SetStartTime(new AFTime(string.Format("t-{0}d", i + 1)));
                ef.SetEndTime(new AFTime(string.Format("t-{0}d", i)));

                AFElement element = afDatabase.Elements["Region_0"].Elements["BoilerA"];
                ef.PrimaryReferencedElement = element;
            }

            // Do a bulk check in of all changes made so far.
            afDatabase.CheckIn();
        }
Exemplo n.º 2
0
        public bool CreateEventFrame(string name, AFTime start, AFTime end, AFElement primaryReferencedElement, AFElementTemplate efTemplate)
        {
            try
            {
                AFEventFrame newEF = new AFEventFrame(_db, name, efTemplate);
                newEF.SetStartTime(start);
                newEF.SetEndTime(end);
                newEF.PrimaryReferencedElement = primaryReferencedElement;
                newEF.CheckIn();

                _db.CheckIn(AFCheckedOutMode.ObjectsCheckedOutThisThread);
                _db.Refresh();
              
                return true;
            }
            catch
            {
                return false;
            }

        }
        public void CreateEventFrames()
        {
            const int pageSize = 1000;
            int startIndex = 0;
            int totalCount;
            do
            {
                AFNamedCollectionList<AFBaseElement> results = _database.ElementTemplates["MeterBasic"].FindInstantiatedElements(
                    includeDerived: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount
                    );

                IList<AFElement> meters = results.Select(elm => (AFElement)elm).ToList();

                foreach (AFElement meter in meters)
                {
                    foreach (int day in Enumerable.Range(1, 31))
                    {
                        DateTime start = new DateTime(2015, 12, day, 0, 0, 0, DateTimeKind.Local);
                        AFTime startTime = new AFTime(start);
                        AFTime endTime = new AFTime(start.AddDays(1));
                        AFEventFrame ef = new AFEventFrame(_database, "*", _eventFrameTemplate);
                        ef.SetStartTime(startTime);
                        ef.SetEndTime(endTime);
                        ef.PrimaryReferencedElement = meter;
                    }
                }

                _database.CheckIn();

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }
Exemplo n.º 4
0
        private void AddAttributes(AFDatabase afDatabase, AFEventFrame eventFrame)
        {
            try
            {
                // random number generator, to create different attributes for each event frames
                var randomGen = new Random(DateTime.Now.Millisecond);

                // creates an int attribute on the event frame
                var attribute = eventFrame.Attributes.Add("Value1");
                attribute.Type = typeof(int);
                attribute.SetValue(new AFValue(randomGen.Next(10, 1000)));

                // double attribute
                attribute = eventFrame.Attributes.Add("Value2");
                attribute.Type = typeof(double);
                attribute.SetValue(new AFValue(randomGen.Next(10, 1000)));

                // here we are adding a tag that is normally present on all PI Data Archive Servers.
                // to show how to add a PIPoint data reference attribute
                attribute = eventFrame.Attributes.Add("Value3");
                attribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem);
                attribute.ConfigString = @"\\optimus\sinusoid";

            }
            catch (Exception ex)
            {
                Logger.Warn("Error when adding demonstration attributes to the event frame.", ex);
            }
        }
Exemplo n.º 5
0
        private void CreateEventFrame(AFDatabase afDatabase, string name, string startTime = null, string endTime = null, string template = null)
        {
            // look to get the template, if template=null then aftemplate will be null as well
            var afTemplate = GetEventFrameTemplate(afDatabase, template);

            var eventFrame = new AFEventFrame(afDatabase, name, afTemplate);
            if (!string.IsNullOrEmpty(startTime)) eventFrame.SetStartTime(startTime);
            if (!string.IsNullOrEmpty(endTime)) eventFrame.SetEndTime(endTime);

            // when using a template, you'll want to assign a primary element to the event frame:
            // here is an example:
            eventFrame.PrimaryReferencedElement = null;
            eventFrame.Description = "";

            // for demonstration purpose, we add some attributes to the event frame created, only if there was no template passed.
            if (afTemplate == null)
                AddAttributes(afDatabase, eventFrame);

            // the checkin writes the event frame to the database
            eventFrame.CheckIn();

            Logger.InfoFormat("EventFrameCreated: name: {0} GUID: {1}", eventFrame.Name, eventFrame.ID);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the data of the EventFrame attribute chosen.
 /// </summary>
 /// <param name="server_database"> Unique string representing the server and database</param>
 /// <param name="AttributeName"> The name of the AFEventFrame AFAttribute.</param>
 /// <param name="MatlabName"> The name of the variable in the Matlab workspace. </param>
 /// <param name="frame"> The AFEventFrame object.</param>
 /// <param name="addToListView"> true: adds input into the LogSystem. (Generally true)</param>
 public static void getEventFrameData(string server_database, string AttributeName, string MatlabName, AFEventFrame frame, bool addToListView)
 {
     getData(server_database, AttributeName, MatlabName, frame.StartTime.ToString(), frame.EndTime.ToString(), frame, true);
 }
        static void CreateEventFrames(AFDatabase database, AFElementTemplate eventFrameTemplate)
        {
            const int pageSize = 1000;
            int startIndex = 0;
            int totalCount;
            do
            {
                AFNamedCollectionList<AFBaseElement> results = database.ElementTemplates["MeterBasic"].FindInstantiatedElements(
                    includeDerived: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount
                    );

                IList<AFElement> meters = results.Select(elm => (AFElement)elm).ToList();

                DateTime timereference = DateTime.Now.AddDays(-7);
                //AFTime startTime = new AFTime(new DateTime(timereference.Year, timereference.Month, timereference.Day, 0, 0, 0, DateTimeKind.Local));
                foreach (AFElement meter in meters)
                {
                    foreach (int day in Enumerable.Range(1, 7))
                    {
                        AFTime startTime = new AFTime(timereference.AddDays(day - 1));
                        AFTime endTime = new AFTime(startTime.LocalTime.AddDays(1));
                        AFEventFrame ef = new AFEventFrame(database, "*", eventFrameTemplate);
                        ef.SetStartTime(startTime);
                        ef.SetEndTime(endTime);
                        ef.PrimaryReferencedElement = meter;
                    }
                }

                database.CheckIn();

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

            database.CheckIn();
        }
Exemplo n.º 8
0
        public void EventFrameAttributeSetValueTest()
        {
            AFDatabase db = Fixture.AFDatabase;

            string       ef1Name        = $"OSIsoftTests_AF_EFAttrSrchTst - {DateTime.UtcNow.ToString(AFFixture.DateTimeFormat, CultureInfo.InvariantCulture)}_EF1";
            const string Attribute1Name = "OSIsoftTests_EFAttr#1";
            const string Attribute2Name = "OSIsoftTests_EFAttr#2";
            const string Attribute3Name = "OSIsoftTests_EFAttr#3";
            const double DoubleValue1   = 123.456;
            const int    IntegerValue2  = 2;
            const string StringValue3   = "value";

            try
            {
                Output.WriteLine($"Create event frame [{ef1Name}] and add 3 attributes.");
                var newEF = new AFEventFrame(db, ef1Name);

                Output.WriteLine($"Create attribute [{Attribute1Name}] with a double value.");
                var attr1 = newEF.Attributes.Add(Attribute1Name);
                attr1.Type = typeof(double);
                attr1.SetValue(DoubleValue1, null);

                Output.WriteLine($"Create attribute [{Attribute2Name}] with an integer value.");
                var attr2 = newEF.Attributes.Add(Attribute2Name);
                attr2.Type = typeof(int);
                attr2.SetValue(IntegerValue2, null);

                Output.WriteLine($"Create attribute [{Attribute3Name}] with a string value.");
                var attr3 = newEF.Attributes.Add(Attribute3Name);
                attr3.Type = typeof(string);
                attr3.SetValue(StringValue3, null);
                db.CheckIn();

                Output.WriteLine($"Confirm event frame creation.");
                db = Fixture.ReconnectToDB(); // This operation clears AFSDK cache and assures retrieval from AF server
                var readEventFrame = AFEventFrame.FindEventFrame(db.PISystem, newEF.ID);

                Output.WriteLine($"Check attribute 1 value.");
                var actualAttribute1Value = readEventFrame.Attributes[Attribute1Name].GetValue();
                var actualAttribute1Type  = actualAttribute1Value.ValueType;
                Assert.True(actualAttribute1Type == typeof(double), $"Value read from Attribute [{Attribute1Name}] " +
                            $"did not have expected type [{actualAttribute1Type}], expected [{typeof(double)}].");
                Assert.True(actualAttribute1Value.ValueAsDouble() == DoubleValue1, $"Value for Attribute [{Attribute1Name}]" +
                            $" was [{actualAttribute1Value.ValueAsDouble()}], expected [{DoubleValue1}].");

                Output.WriteLine($"Check attribute 2 value.");
                var actualAttribute2Value = readEventFrame.Attributes[Attribute2Name].GetValue();
                var actualAttribute2Type  = actualAttribute2Value.ValueType;
                Assert.True(actualAttribute2Type == typeof(int), $"Value read from Attribute [{Attribute2Name}]" +
                            $" did not have expected type [{actualAttribute2Type}], expected [{typeof(int)}].");
                Assert.True(actualAttribute2Value.ValueAsDouble() == IntegerValue2, $"Value for Attribute [{Attribute2Name}]" +
                            $" was [{actualAttribute2Value.ValueAsInt32()}], expected [{IntegerValue2}].");

                Output.WriteLine($"Check attribute 3 value.");
                var actualAttribute3Value = readEventFrame.Attributes[Attribute3Name].GetValue();
                var actualAttribute3Type  = actualAttribute3Value.ValueType;
                Assert.True(actualAttribute3Type == typeof(string), $"Value read from Attribute [{Attribute3Name}]" +
                            $" did not have expected type [{actualAttribute3Type}], expected [{typeof(string)}].");
                Assert.True(actualAttribute3Value.Value.ToString() == StringValue3, $"Value for Attribute [{Attribute3Name}]" +
                            $" was [{actualAttribute3Value.Value.ToString()}], expected [{StringValue3}].");

                attr1 = readEventFrame.Attributes[Attribute1Name];
                attr2 = readEventFrame.Attributes[Attribute2Name];
                attr3 = readEventFrame.Attributes[Attribute3Name];

                Output.WriteLine("Set attribute values for the second time.");
                attr1.SetValue(DoubleValue1, null);
                attr2.SetValue(IntegerValue2, null);
                attr3.SetValue(StringValue3, null);
                db.CheckIn();

                db             = Fixture.ReconnectToDB();
                readEventFrame = AFEventFrame.FindEventFrame(db.PISystem, newEF.ID);

                Output.WriteLine($"Recheck attribute 1 value.");
                var actualAttribute1Value2 = readEventFrame.Attributes[Attribute1Name].GetValue();
                var actualAttribute1Type2  = actualAttribute1Value2.ValueType;
                Assert.True(actualAttribute1Type2 == typeof(double), $"Value read from Attribute [{Attribute1Name}]" +
                            $" did not have expected type [{actualAttribute1Type2}], expected [{typeof(double)}].");
                Assert.True(actualAttribute1Value2.ValueAsDouble() == DoubleValue1, $"Value for Attribute [{Attribute1Name}]" +
                            $" was [{actualAttribute1Value2.ValueAsDouble()}], expected [{DoubleValue1}].");

                Output.WriteLine($"Recheck attribute 2 value.");
                var actualAttribute2Value2 = readEventFrame.Attributes[Attribute2Name].GetValue();
                var actualAttribute2Type2  = actualAttribute2Value2.ValueType;
                Assert.True(actualAttribute2Type2 == typeof(int), $"Value read from Attribute [{Attribute2Name}]" +
                            $" did not have expected type [{actualAttribute2Type2}], expected [{typeof(int)}].");
                Assert.True(actualAttribute2Value2.ValueAsDouble() == IntegerValue2, $"Value for Attribute [{Attribute2Name}]" +
                            $" was [{actualAttribute2Value.ValueAsInt32()}], expected [{IntegerValue2}].");

                Output.WriteLine($"Check attribute 3 value.");
                var actualAttribute3Value2 = readEventFrame.Attributes[Attribute3Name].GetValue();
                var actualAttribute3Type2  = actualAttribute3Value2.ValueType;
                Assert.True(actualAttribute3Type2 == typeof(string), $"Value read from Attribute [{Attribute3Name}]" +
                            $" did not have expected type [{actualAttribute3Type2}], expected [{typeof(string)}].");
                Assert.True(actualAttribute3Value2.Value.ToString() == StringValue3, $"Value for Attribute [{Attribute3Name}]" +
                            $" was [{actualAttribute3Value2.Value.ToString()}], expected [{StringValue3}].");
            }
            finally
            {
                Fixture.RemoveEventFrameIfExists(ef1Name, Output);
            }
        }