コード例 #1
0
ファイル: Form1.cs プロジェクト: gewebber/PI-AF-SDK
        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
ファイル: Form1.cs プロジェクト: gewebber/PI-AF-SDK
        private void bntShowTrend_Click(object sender, EventArgs e)
        {
            lbData.Items.Clear();

            //Set time-range
            AFTime startTime = new AFTime(afStartDate.Text);
            AFTime endTime = new AFTime(afEndTime.Text);
            AFTimeRange timeRange = new AFTimeRange(startTime, endTime);


            //Clear chart of any previous data
            afDataChart.Series["dataSeries"].Points.Clear();

            //Set UoM
            UOM selectedUOM = cbUOM.SelectedItem as UOM;

            if (afTreeView2.AFSelection != null)
            {
                AFAttribute selectedAttribute = afTreeView2.AFSelection as AFAttribute;
                AFValues vals;
                if (selectedAttribute != null)
                {
                    //Get values and convert to desired UoM if necessary
                    if (selectedAttribute.DefaultUOM != null)
                    {
                        vals = selectedAttribute.GetValues(timeRange, 0, null).Convert(selectedUOM);
                    } else
                    {
                        vals = selectedAttribute.GetValues(timeRange, 0, null);
                    }
                    
                    //Fill out list and chart of values.
                    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;
                        }
                    }
                }
            }

        }
コード例 #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();
                }
            }
        }