示例#1
0
        private void cbUOM_SelectedIndexChanged(object sender, EventArgs e)
        {
            UOM selectedUOM = cbUOM.SelectedItem as UOM;
            AFAttribute selectedAttribute = afTreeView2.AFSelection as AFAttribute;

            //Clear list of values
            lbData.Items.Clear();

            //Convert current value to new UoM
            lbCurrentVal.Text = selectedAttribute.GetValue().Convert(selectedUOM).ToString();
            lbTimestamp.Text = selectedAttribute.GetValue().Timestamp.ToString();

            //Clear chart
            afDataChart.Series["dataSeries"].Points.Clear();

            if (lbData.Items != null)
            {
                //Get time-range
                AFTime startTime = new AFTime(afStartDate.Text);
                AFTime endTime = new AFTime(afEndTime.Text);
                AFTimeRange timeRange = new AFTimeRange(startTime, endTime);

                AFValues vals;

                if (selectedAttribute != null)
                {
                    //Convert to new Uom if required
                    if (selectedAttribute.DefaultUOM != null)
                    {
                        vals = selectedAttribute.GetValues(timeRange, 0, null).Convert(selectedUOM);
                    }
                    else
                    {
                        vals = selectedAttribute.GetValues(timeRange, 0, null);
                    }

                    //Fill out list and chart
                    foreach (AFValue val in vals)
                    {
                        string s = String.Format("{0} \t {1} {2}", val.Timestamp.LocalTime, val.Value,
                                                    selectedUOM != null ? selectedUOM.Abbreviation : null);
                        lbData.Items.Add(s);

                        try
                        {
                            afDataChart.Series["dataSeries"].Points.AddXY(val.Timestamp.ToString(), val.Value);
                        }
                        catch (System.ArgumentException)
                        {
                            continue;
                        }
                    }
                }
            }
        }
示例#2
0
        private void afTreeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {
            AFAttribute selectedAttribute = afTreeView2.AFSelection as AFAttribute;

            //Clear data items
            lbCurrentVal.Text = "";
            lbTagName.Text = "";
            lbTimestamp.Text = "";
            lbData.Items.Clear();
            cbUOM.Items.Clear();
            btnInspectTag.Hide();
            afDataChart.Series["dataSeries"].Points.Clear();

            //Set timerange to default value
            afStartDate.Text = "*-12h";
            afEndTime.Text = "*";


            if (selectedAttribute != null)
            {
                if (selectedAttribute.DefaultUOM != null)
                {
                    cbUOM.Text = null;

                    //Fill out the UoM drop-down list
                    UOMClass selectedUOMClass = selectedAttribute.DefaultUOM.Class;
                    cbUOM.Items.AddRange(selectedUOMClass.UOMs.ToArray());
                    cbUOM.SelectedItem = selectedAttribute.DefaultUOM;
                }

                lbAttribName.Text = selectedAttribute.ToString();
                
                if (selectedAttribute.GetValue() != null) //Check that an attribute has been selected
                {
                    //Set lbCurrentVal to hold the current attribute value and timestamp
                    lbCurrentVal.Text = selectedAttribute.GetValue().ToString();
                    lbTimestamp.Text = selectedAttribute.GetValue().Timestamp.ToString();
                }
                    
                try//Check attribute for association with a PI Tag
                {
                    lbTagName.Text = selectedAttribute.PIPoint.Name.ToString(); //Set lbTagName to hold associated PI tag name
                    btnInspectTag.Show();
                } catch (OSIsoft.AF.PI.PIPointInvalidException) { //No tag association exists
                    lbTagName.Text = "INVALID PI POINT";
                } catch (System.NullReferenceException)
                {
                    lbTagName.Text = "NO PI POINT";
                }

                bntShowTrend.PerformClick();
            }
        }
示例#3
0
        public GraphQlAfAttribute(AFAttribute aAfAttribute, Field afAttributesField = null, Field tsPlotValuesField = null)
        {
            AFValue aAfValue = aAfAttribute.GetValue();

            name            = aAfAttribute.Name;
            ThisAfAttribute = aAfAttribute;
            value           = aAfValue.Value?.ToString();
            uom             = aAfAttribute.DisplayUOM?.Abbreviation;

            if (aAfAttribute.DataReference?.Name == "PI Point")
            {
                timeStamp = aAfValue.Timestamp.UtcTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
            }

            if (afAttributesField != null)
            {
                var afAttributesNameFilterStrings = GraphQlHelpers.GetArgumentStrings(afAttributesField, "nameFilter");
                var afAttributesChildField        = GraphQlHelpers.GetFieldFromSelectionSet(afAttributesField, "afAttributes");

                var returnAttributesObject = new ConcurrentBag <GraphQlAfAttribute>();
                var afAttributeList        = aAfAttribute.Attributes.ToList <AFAttribute>();
                Parallel.ForEach(afAttributeList, aAfChildAttribute =>
                {
                    if (afAttributesNameFilterStrings.Count == 0 || afAttributesNameFilterStrings.Contains(aAfChildAttribute.Name))
                    {
                        returnAttributesObject.Add(new GraphQlAfAttribute(aAfAttribute, afAttributesChildField));
                    }
                });
                afAttributes = returnAttributesObject.OrderBy(x => x.name).ToList();
            }

            if (tsPlotValuesField != null)
            {
                if (aAfAttribute.DataReference?.Name == "PI Point")
                {
                    var plotDensity   = GraphQlHelpers.GetArgumentDouble(tsPlotValuesField, "plotDensity");
                    var startDateTime = GraphQlHelpers.GetArgumentDateTime(tsPlotValuesField, "startDateTime");
                    var endDateTime   = GraphQlHelpers.GetArgumentDateTime(tsPlotValuesField, "endDateTime");

                    var timeRange = new AFTimeRange(startDateTime, endDateTime);

                    AFValues asdf = ThisAfAttribute.GetValues(timeRange, (int)plotDensity, null);

                    var returnObject = new ConcurrentBag <GraphQlTsValue>();
                    foreach (AFValue aAfTsValue in asdf)
                    {
                        returnObject.Add(new GraphQlTsValue()
                        {
                            timeStamp = aAfTsValue.Timestamp.UtcTime.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                            value     = aAfTsValue.Value.ToString()
                        });
                    }
                    tsPlotValues = returnObject.OrderBy(x => x.timeStamp).ToList();
                }
            }
        }
示例#4
0
        public void CreateAttribute()
        {
            AFElement element = new AFElement();

            string name = "Test Element 1";

            element.Name = name;
            Assert.Equals(element.Name, name);

            string desc = "Lazy PI Unit Test Element";

            element.Description = desc;
            Assert.Equals(element.Description, desc);

            Console.WriteLine("Test element creation.");

            Assert.IsTrue(_db.CreateElement(element), "Assert creation passed");

            element = _db.Elements[element.Name];

            //Check that the the element can be found through the AFDB
            Assert.IsNotNull(element, "Check AFDB element collection for new element.");

            AFAttribute attr = new AFAttribute();

            attr.Name        = "Test Attribute";
            attr.Description = "Created by WebAPI tests";

            element.Attributes.Add(attr);
            element.CheckIn();

            Assert.Equals(element.Attributes.Count, 1);
            attr = element.Attributes[attr.Name];

            Assert.IsNotNull(attr);
            Assert.IsNotNull(attr.ID);
            Assert.IsNotNull(attr.Name);
            Assert.IsNotNull(attr.Description);
            Assert.IsNotNull(attr.Path);

            string val = "Test string";

            // Test set and get of AFValue object
            attr.SetValue(new AFValue(val));
            AFValue valObj = attr.GetValue();

            Assert.Equals(valObj.Value, val);

            element.Delete();
            Assert.IsTrue(element.IsDeleted);

            element.CheckIn();
            Assert.IsNull(AFElement.Find(_conn, element.WebID));
        }
示例#5
0
 private void ShowAttribute(AFAttribute attr)
 {
     WriteAttributeDepthString();
     Console.WriteLine("-Name:{0}", attr.Name);
     WriteAttributeDepthString();
     Console.WriteLine("Value:{0}", attr.GetValue());
     WriteAttributeDepthString();
     Console.WriteLine("Type: {0}", attr.Type);
     if (attr.DataReference != null)
     {
         WriteAttributeDepthString();
         Console.WriteLine("DataReference: {0}", attr.DataReference.Name);
         WriteAttributeDepthString();
         Console.WriteLine("DataReference ConfigString: {0}", attr.ConfigString);
     }
 }
        public void SetValueTest()
        {
            DateTime     time  = DateTime.Today;
            PITimedValue value = new PITimedValue("t", null, true, false, false, 153);

            value.Substituted = null;
            instance.SetValue(webId, value);

            string     path = Constants.AF_ATTRIBUTE_PATH;
            AFDatabase db   = StandardPISystem.Databases[Constants.AF_DATABASE_NAME];

            db.Refresh();
            AFAttribute myAttribute = AFObject.FindObject(path) as AFAttribute;
            float       v1          = myAttribute.GetValue().ValueAsSingle();
            float       v2          = Convert.ToSingle(value.Value);

            Assert.IsTrue(v1 == v2);
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFElement nuGreen         = afDatabase.Elements["NuGreen"];
            AFElement houston         = nuGreen.Elements["Houston"];
            AFElement crackingProcess = houston.Elements["Cracking Process"];
            AFElement equipment       = crackingProcess.Elements["Equipment"];
            AFElement b210            = equipment.Elements["B-210"];

            AFAttribute processFeedRate = b210.Attributes["Process Feedrate"];

            AFValue val = processFeedRate.GetValue();

            Console.WriteLine("Timestamp: {0}, Value: {1}", val.Timestamp, val.Value.ToString());
        }
        private AFValue Convert(AFValue inVal, AFDatabase db, AFAttribute uomAttr)
        {
            AFValue result;

            if (uomAttr == null)
            {
                throw new ArgumentException("No UOM attribute " + Attribute.Name + "|UOM");
            }
            else
            {
                var targetUOMVal = uomAttr.GetValue().Value as string;
                if (string.IsNullOrEmpty(targetUOMVal))
                {
                    throw new ArgumentException("UOM attribute " + Attribute.Name + "|UOM is empty");
                }
                else
                {
                    result = inVal.Convert(db.UOMs[targetUOMVal]);
                }
            }

            return(result);
        }
        protected string SubstituteAttributeValues(object context, object timeContext, string value)
        {
            lock (fSubstituteLock) {
                if (fInSubstituteAttributeValues)
                {
                    return(value);
                }
                try {
                    fInSubstituteAttributeValues = true;
                    int    num  = 0;
                    string text = value;
                    int    num2 = 0;
                    while (num < value.Length && IsAttributeSubstitute(value, num))
                    {
                        if (num2 == 100)
                        {
                            return(text);
                        }
                        string attributeSubstitute = GetAttributeSubstitute(value, ref num);
                        num2++;
                        try {
                            int num3;
                            if (num > 0 && (num3 = value.LastIndexOf("=", num, StringComparison.Ordinal)) > 12 && value.Substring(num3 - 12, 12).Equals("RELATIVETIME", StringComparison.OrdinalIgnoreCase))
                            {
                                num++;
                            }
                            else
                            {
                                AFAttribute attribute = GetAttribute(attributeSubstitute);
                                if (attribute != null)
                                {
                                    AFValue value2;
                                    if (context is AFCase)
                                    {
                                        value2 = attribute.GetValue((AFCase)context);
                                    }
                                    else if (timeContext is AFTime)
                                    {
                                        value2 = attribute.GetValue((AFTime)timeContext);
                                    }
                                    else if (timeContext is AFTimeRange)
                                    {
                                        value2 = attribute.GetValue((AFTimeRange)timeContext);
                                    }
                                    else
                                    {
                                        value2 = attribute.GetValue();
                                    }

                                    if (value2.Value != null && value2.IsGood)
                                    {
                                        string text2;
                                        if (value2.Value is DateTime)
                                        {
                                            text2 = ((DateTime)value2.Value).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
                                        }
                                        else
                                        {
                                            text2 = Convert.ToString(value2.Value, CultureInfo.InvariantCulture);
                                        }

                                        if (text2.Contains(" ") || text2.Contains("\"") || text2.Contains(";"))
                                        {
                                            text2 = text2.Replace("\"", "\"\"");

                                            /*if (!value.Contains("\"%@" + attributeSubstitute + "%\"")) {
                                             *  text2 = "\"" + text2 + "\"";
                                             * }*/
                                        }
                                        value = value.Replace("%@" + attributeSubstitute + "%", text2);
                                    }
                                    else
                                    {
                                        num++;
                                    }
                                }
                                else
                                {
                                    num++;
                                }
                            }
                        } catch {
                            num++;
                        }
                    }
                } finally {
                    fInSubstituteAttributeValues = false;
                }
            }
            return(value);
        }