Exemple #1
0
        public string GetEventFrame(string Id)
        {
            var          db = InitializeAf();
            string       result;
            Guid         guid       = new Guid(Id);
            AFEventFrame eventFrame = AFEventFrame.FindEventFrame(db.PISystem, guid);

            var attributes     = eventFrame.Attributes;
            var attributesList = new List <AttributeString>();

            foreach (var attribute in attributes)
            {
                if (attribute.Attributes.Count > 0)
                {
                    var att = attribute.Attributes;
                }
                var a = new AttributeString
                {
                    Name = attribute.Name,
                    Type = attribute.Type.ToString()
                };
                if (attribute.GetValue().Value != null)
                {
                    a.Value = attribute.GetValue().Value.ToString();
                }
                attributesList.Add(a);
            }

            var serializer = new JavaScriptSerializer();

            result = serializer.Serialize(attributesList);
            return(result);
        }
        public void EventFrameHierarchyTest()
        {
            AFDatabase db = Fixture.AFDatabase;

            string uniqueText = DateTime.UtcNow.ToString(AFFixture.DateTimeFormat, CultureInfo.InvariantCulture);
            string rootEFName = $"OSIsoftTests_AF_EventFrameHierarchyTest_{uniqueText}RootElem";
            string ef1Name    = $"OSIsoftTests_AF_EventFrameHierarchyTest_{uniqueText}EF1";
            string ef2Name    = $"OSIsoftTests_AF_EventFrameHierarchyTest_{uniqueText}EF2";
            string ef3Name    = $"OSIsoftTests_AF_EventFrameHierarchyTest_{uniqueText}EF3";
            string ef4Name    = $"OSIsoftTests_AF_EventFrameHierarchyTest_{uniqueText}EF4";

            try
            {
                Output.WriteLine($"Create root Event Frame [{rootEFName}] with hierarchy 4 Event Frames deep.");
                var rootEF = new AFEventFrame(db, ef1Name);
                var ef1    = new AFEventFrame(db, ef1Name);
                var ef2    = new AFEventFrame(db, ef2Name);
                var ef3    = new AFEventFrame(db, ef3Name);
                var ef4    = new AFEventFrame(db, ef4Name);

                rootEF.EventFrames.Add(ef1);
                ef1.EventFrames.Add(ef2);
                ef2.EventFrames.Add(ef3);
                ef3.EventFrames.Add(ef4);
                db.CheckIn();

                Output.WriteLine("Check that event frame hierarchy was created correctly.");
                db = Fixture.ReconnectToDB(); // This operation clears AFSDK cache and assures retrieval from AF server
                var foundRootEF = AFEventFrame.FindEventFrame(db.PISystem, rootEF.ID);
                Assert.True(foundRootEF != null, $"Created Event Frame [{rootEFName}] not found with ID [{rootEF.ID}].");
                AFEventFrame lastEFInHeirarchy =
                    foundRootEF.EventFrames[ef1Name].EventFrames[ef2Name].EventFrames[ef3Name].EventFrames[ef4Name];
                Assert.True(lastEFInHeirarchy != null, $"Search down hierarchy from root did not find Event Frame.");
                Assert.True(lastEFInHeirarchy.Name.Equals(ef4Name,
                                                          StringComparison.OrdinalIgnoreCase),
                            $"Event Frame found at bottom of hierarchy from root [{rootEFName}]" +
                            $" was named [{lastEFInHeirarchy.Name}], expected [{ef4Name}].");
            }
            finally
            {
                Fixture.RemoveEventFrameIfExists(rootEFName, Output);
                Fixture.RemoveEventFrameIfExists(ef1Name, Output);
                Fixture.RemoveEventFrameIfExists(ef2Name, Output);
                Fixture.RemoveEventFrameIfExists(ef3Name, Output);
                Fixture.RemoveEventFrameIfExists(ef4Name, Output);
            }
        }
        public void EventFrameTest()
        {
            AFDatabase db = Fixture.AFDatabase;

            const string EventFrameName   = "OSIsoftTests_AF_InitEF#1A";
            const string EventFrameRename = "OSIsoftTests_AF_EventFrameTest_NewName";

            var testData = new EventFrameTestConfiguration(EventFrameName);

            try
            {
                Output.WriteLine($"Create Event Frame [{EventFrameName}].");
                var evtfr1 = FullEventFrameCreate(db, testData);
                db.CheckIn();

                Output.WriteLine("Confirm Event Frame created and found.");
                db     = Fixture.ReconnectToDB(); // This operation clears AFSDK cache and assures retrieval from AF server
                evtfr1 = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                FullEventFrameVerify(db, evtfr1.ID, testData, Output);

                Output.WriteLine($"Rename Event Frame to [{EventFrameRename}].");
                evtfr1.Name = EventFrameRename;
                db.CheckIn();

                // Update test data with new name
                testData.Name = EventFrameRename;

                Output.WriteLine($"Verify Event Frame [{EventFrameRename}] found on reread.");
                db     = Fixture.ReconnectToDB();
                evtfr1 = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                FullEventFrameVerify(db, evtfr1.ID, testData, Output);

                Output.WriteLine($"Delete Event Frame [{EventFrameRename}].");
                evtfr1.Delete();
                db.CheckIn();

                Output.WriteLine($"Confirm Event Frame deleted.");
                db = Fixture.ReconnectToDB();
                var deletedEFSearch = AFEventFrame.FindEventFrame(db.PISystem, evtfr1.ID);
                Assert.True(deletedEFSearch == null, $"Event Frame [{EventFrameRename}] was not deleted as expected.");
            }
            finally
            {
                Fixture.RemoveElementIfExists(testData.EventFrameElementName, Output);
            }
        }
Exemple #4
0
        /// <summary>
        /// Remove the event frame by id if it exists.
        /// </summary>
        /// <param name="id">The Id of the event frame to remove.</param>
        /// <param name="output">The output logger used for writing messages.</param>
        public void RemoveEventFrameIfExists(Guid id, ITestOutputHelper output)
        {
            Contract.Requires(output != null);

            var preCheckEventFrame = AFEventFrame.FindEventFrame(PISystem, id);

            if (preCheckEventFrame != null)
            {
                output.WriteLine($"Event Frame [{preCheckEventFrame}] exists, delete it.");
                preCheckEventFrame.Delete();
                preCheckEventFrame.CheckIn();
            }
            else
            {
                output.WriteLine($"Event Frame with GUID [{id}] does not exist, can not be deleted.");
            }
        }
        private void EFListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (EFListView.SelectedItems.Count == 1)
            {
                EFAttrView.Items.Clear();
                ListViewItem SelectedEF = EFListView.SelectedItems[0];

                Guid   myEFGUID     = Guid.Empty;
                String myguidstring = SelectedEF.SubItems[4].Text;

                try { myEFGUID = Guid.Parse(myguidstring); }
                catch { MessageBox.Show("Cannot convert GUID"); }

                AFEventFrame myEF      = AFEventFrame.FindEventFrame(myAFServer, myEFGUID);
                AFAttributes myEFAttrs = myEF.Attributes;

                foreach (AFAttribute attr in myEFAttrs)
                {
                    string[] displayvalues = new string[4];
                    displayvalues[0] = attr.Name;
                    try
                    {
                        displayvalues[1] = attr.Data.RecordedValue(myEF.EndTime, AFRetrievalMode.AtOrAfter, null).ToString();
                    }
                    catch
                    {
                        try
                        {
                            displayvalues[1] = attr.GetValue().ToString();
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show(ex2.Message);
                        }
                    }
                    displayvalues[2] = myEF.Name;
                    displayvalues[3] = myEF.UniqueID;
                    ListViewItem lvi = new ListViewItem(displayvalues);
                    EFAttrView.Items.Add(lvi);
                }
            }
        }
        /// <summary>
        /// Verifies a complex event frame object.
        /// </summary>
        /// <param name="db">The AF Database that contains the event frame being verified.</param>
        /// <param name="evtfrmId">ID (GUID) of the event frame to be verified.</param>
        /// <param name="expData">Expected Data to check the event frame.</param>
        /// <param name="output">The output logger used for writing messages.</param>
        /// <remarks>
        /// This routine is used to verify event frames created using the FullEventFrameCreate() routine.
        /// </remarks>
        private void FullEventFrameVerify(AFDatabase db, Guid evtfrmId, EventFrameTestConfiguration expData, ITestOutputHelper output)
        {
            var eventFrameFound = AFEventFrame.FindEventFrame(db.PISystem, evtfrmId);

            Assert.True(eventFrameFound != null, $"Unable to find Event Frame [{expData.Name}] with ID [{evtfrmId}].");
            string actEFName = eventFrameFound.Name;

            Assert.True(actEFName.Equals(expData.Name, StringComparison.OrdinalIgnoreCase),
                        $"Element Template found with ID [{evtfrmId}] had name [{actEFName}], expected [{expData.Name}].");

            Assert.True(db.AttributeCategories[expData.AttributeCategoryName] != null,
                        $"Check Failed. Attribute Category [{expData.AttributeCategoryName}] not found.");
            Assert.True(db.ElementCategories[expData.ElementCategoryName] != null,
                        $"Check Failed. Element Category [{expData.ElementCategoryName}] not found.");

            output.WriteLine("Check Event Frame Attributes.");
            int actualAttributeCount = eventFrameFound.Attributes.Count;

            Assert.True(actualAttributeCount == 3, $"Event Frame Attribute Count Failed. Actual {actualAttributeCount}, expected 3.");
            var attr1 = eventFrameFound.Attributes[expData.Attribute1Name];

            Assert.True(attr1 != null, $"Event Frame [{expData.Name}] did not have attribute [{expData.Attribute1Name}] as expected.");
            Assert.True(attr1.Categories[expData.AttributeCategoryName] != null,
                        $"Attribute [{expData.Attribute1Name}] in Event Frame [{expData.Name}]" +
                        $" did not have category [{expData.AttributeCategoryName}] as expected.");

            var attr2 = eventFrameFound.Attributes[expData.Attribute2Name];

            Assert.True(attr2 != null, $"Event Frame [{expData.Name}] did not have attribute [{expData.Attribute2Name}] as expected.");
            Assert.True(expData.Attribute2Value == attr2.GetValue().ValueAsDouble(),
                        $"Event Frame [{expData.Name}] attribute [{expData.Attribute2Name}] data was" +
                        $" [{attr2.GetValue().ValueAsDouble()}], expected [{expData.Attribute2Value}].");

            var attr3 = eventFrameFound.Attributes[expData.Attribute3Name];

            Assert.True(attr3 != null, $"Event Frame [{expData.Name}] did not have attribute [{expData.Attribute3Name}] as expected.");
            Assert.True(attr3.DataReferencePlugIn == db.PISystem.DataReferencePlugIns[expData.DataReferencePlugInName],
                        $"Attribute [{expData.Attribute3Name}] in Event Frame [{expData.Name}]" +
                        $" did not have data reference PlugIn [{expData.DataReferencePlugInName}] as expected.");
            Assert.True(attr3.ConfigString == expData.DataReferenceConfigString,
                        $"Attribute [{expData.Attribute3Name}] in Event Frame [{expData.Name}] data reference ConfigString was" +
                        $" [{attr3.ConfigString}], expected [{expData.DataReferenceConfigString}].");

            output.WriteLine("Check Event Frame Categories.");
            int       actualEventFrameCategoriesCount   = eventFrameFound.Categories.Count;
            const int ExpectedEventFrameCategoriesCount = 1;

            Assert.True(actualEventFrameCategoriesCount == ExpectedEventFrameCategoriesCount,
                        $"Category Count in Event Frame [{expData.Name}] was " +
                        $"{actualEventFrameCategoriesCount}, expected {ExpectedEventFrameCategoriesCount}.");
            Assert.True(eventFrameFound.Categories[expData.ElementCategoryName] != null,
                        $"Category [{expData.ElementCategoryName}] not found in Event Frame [{expData.Name}] as expected.");

            output.WriteLine("Check Child Event Frames.");
            int       actualEventFrameCount   = eventFrameFound.EventFrames.Count;
            const int ExpectedEventFrameCount = 1;

            Assert.True(actualEventFrameCount == ExpectedEventFrameCount,
                        $"Count in Event Frame [{expData.Name}] was {actualEventFrameCount}, expected {ExpectedEventFrameCount}.");
            Assert.True(eventFrameFound.EventFrames[expData.ChildEventFrame] != null,
                        $"Child Event Frame [{expData.ChildEventFrame}] not found in Event Frame [{expData.Name}] as expected.");

            output.WriteLine("Check Extended properties.");
            int       actualExtPropertiesCount   = eventFrameFound.ExtendedProperties.Count;
            const int ExpectedExtPropertiesCount = 1;

            Assert.True(actualExtPropertiesCount == ExpectedExtPropertiesCount,
                        $"ExtendedProperties Count in Event Frame [{expData.Name}] was {actualExtPropertiesCount}, expected {ExpectedExtPropertiesCount}.");
            string actualExtPropValue = eventFrameFound.ExtendedProperties[expData.ExtPropKey].ToString();

            Assert.True(actualExtPropValue.Equals(expData.ExtPropValue, StringComparison.OrdinalIgnoreCase),
                        $"ExtendedProperty Key [{expData.ExtPropKey}] in Event Frame [{expData.Name}]" +
                        $" had Value [{actualExtPropValue}], expected [{expData.ExtPropValue}].");

            output.WriteLine("Check Referenced Element.");
            int       actualRefdElementsCount   = eventFrameFound.ReferencedElements.Count;
            const int ExpectedRefdElementsCount = 1;

            Assert.True(actualRefdElementsCount == ExpectedRefdElementsCount,
                        $"Referenced Element Count in Event Frame [{expData.Name}] was {actualRefdElementsCount}, expected {ExpectedRefdElementsCount}.");
            Assert.True(actualExtPropValue.Equals(expData.ExtPropValue, StringComparison.OrdinalIgnoreCase),
                        $"Referenced Element [{expData.EventFrameElementName}] not found in Event Frame [{expData.Name}] as expected.");

            output.WriteLine("Check Event Frame Annotations.");
            var       annotations              = eventFrameFound.GetAnnotations();
            int       actualAnnotationsCount   = annotations.Count;
            const int ExpectedAnnotationsCount = 1;

            Assert.True(actualAnnotationsCount == ExpectedAnnotationsCount,
                        $"Annotations Count in Event Frame [{expData.Name}] was {actualAnnotationsCount}, expected {ExpectedAnnotationsCount}.");
            Assert.True(annotations[0].Name.Equals(expData.AnnotationName, StringComparison.OrdinalIgnoreCase),
                        $"Annotations[0] Name in Event Frame [{expData.Name}] was [{annotations[0].Name}], expected [{expData.AnnotationName}].");
            Assert.True(annotations[0].Value.ToString().Equals(expData.AnnotationValue, StringComparison.OrdinalIgnoreCase),
                        $"Annotations[0] Value in Event Frame [{expData.Name}] was [{annotations[0].Value.ToString()}], expected [{expData.AnnotationValue}].");
        }
        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);
            }
        }
        private void AddTrendButton_Click(object sender, EventArgs e)
        {
            if (EFListView.SelectedItems.Count >= 1 && EFAttrView.SelectedItems.Count >= 1)
            {
                for (int i = 0; i < EFListView.SelectedItems.Count; i++)
                {
                    for (int j = 0; j < EFAttrView.SelectedItems.Count; j++)
                    {
                        ListViewItem SelectedEF     = EFListView.SelectedItems[i];
                        ListViewItem SelectedEFattr = EFAttrView.SelectedItems[j];
                        //Get EFName and Attribute Name
                        String EFName     = SelectedEF.SubItems[0].Text;
                        String EFattrName = SelectedEFattr.SubItems[0].Text;
                        String title      = num + "_" + EFName + " : " + EFattrName;

                        //Create GUID for Selected Event Frame
                        Guid   myEFGUID     = Guid.Empty;
                        String myguidstring = SelectedEF.SubItems[4].Text;
                        try { myEFGUID = Guid.Parse(myguidstring); }
                        catch { MessageBox.Show("Cannot convert GUID"); }

                        //Find Selected Event Frame
                        AFEventFrame myEF      = AFEventFrame.FindEventFrame(myAFServer, myEFGUID);
                        AFTime       startTime = myEF.StartTime;
                        AFTime       endTime   = myEF.EndTime;
                        //Set endtime as now for not finishing event frame
                        if (endTime > new AFTime("2099/1/1"))
                        {
                            endTime = DateTime.Now;
                        }
                        AFTimeRange timerange = new AFTimeRange(startTime, endTime);
                        //Find Selected Attribute
                        AFAttribute myEFAttr = myEF.Attributes[SelectedEFattr.Text];

                        DateTime trendstarttime = new DateTime(0);
                        //Check time difference between start time and end time
                        TimeSpan timedif = endTime - startTime;
                        try
                        {
                            AFValues vals = myEFAttr.Data.PlotValues(timerange, 100, null);
                            Int32    chk  = 0;
                            foreach (AFValue val in vals)
                            {
                                //Sometimes System.InvalidOperationException happens.
                                Type t = val.Value.GetType();
                                if (t.FullName != "System.InvalidOperationException")
                                {
                                    if (chk == 0)
                                    {
                                        //Add line to chart1
                                        try
                                        {
                                            //add trend to chart1
                                            chart1.Series.Add(title);
                                            chart1.Series[title].ChartType   = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                                            chart1.Series[title].BorderWidth = 2; // Line width
                                            chart1.Series[title].ToolTip     = "#SERIESNAME\r\nValue : #VALY{N2}\r\nTime : #VALX{N0}";
                                            chart1.ChartAreas[0].AxisX.Title = "Seconds";
                                            //Zoom function
                                            chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                                            chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message);
                                            return;
                                        }
                                        trendstarttime = val.Timestamp.LocalTime;
                                    }
                                    timedif = val.Timestamp.LocalTime - trendstarttime;

                                    //Displaying EnumerationSet value as number
                                    if (t.FullName == "OSIsoft.AF.Asset.AFEnumerationValue")
                                    {
                                        //Errchk = 1;
                                        AFEnumerationValue MyEnumerationValue = (AFEnumerationValue)val.Value;
                                        // last value will be returned as 248. So ignore it
                                        if (MyEnumerationValue.Value != 248)
                                        {
                                            chart1.Series[title].Points.AddXY(timedif.TotalSeconds, MyEnumerationValue.Value.ToString());
                                        }
                                    }
                                    else
                                    {
                                        chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val.Value.ToString());
                                    }
                                    chk = 1;
                                }
                                else
                                {
                                    Errchk = 1;
                                    //Write code for System.InvalidOperationException - Currently ignore it
                                    //AFValue val2 = myEFAttr.GetValue(endTime,null);
                                    //timedif = endTime - startTime;
                                    //chart1.Series[title].Points.AddXY(0, val2.Value.ToString());
                                    //chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val2.Value.ToString());
                                }
                            }
                        }
                        catch
                        {
                            Errchk = 1;
                            //If error happens, write code - Currently ignore it
                            //AFValue val = myEFAttr.GetValue(endTime,null);
                            //chart1.Series[title].Points.AddXY(0, val.Value.ToString());
                            //chart1.Series[title].Points.AddXY(timedif.TotalSeconds, val.Value.ToString());
                        }
                        if (Errchk == 0)
                        {
                            //If there is no error, Set minimum and maximum time
                            chart1.ChartAreas[0].AxisX.Minimum = 0;
                            if (maxtimedif > timedif)
                            {
                                chart1.ChartAreas[0].AxisX.Maximum = maxtimedif.TotalSeconds;
                            }
                            else
                            {
                                chart1.ChartAreas[0].AxisX.Maximum = timedif.TotalSeconds;
                                maxtimedif = timedif;
                            }
                            ++num;
                        }
                        Errchk = 0;
                    }
                }
            }
        }