Esempio n. 1
0
 /// <summary>
 /// Saves <see cref="Statistic"/> information into the database.
 /// </summary>
 /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
 /// <param name="statistic">Information about <see cref="Statistic"/>.</param>
 /// <returns>String, for display use, indicating success.</returns>
 // TODO: For now, this method is just a place holder. In future when we create screen to manage Statistic
 // definitions, we will need to add code to it.
 public static string Save(AdoDataConnection database, Statistic statistic)
 {
     return(string.Empty);
 }
Esempio n. 2
0
        /// <summary>
        /// Gets statistic measurements from the database for current node.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <returns>Collection of <see cref="StatisticMeasurement"/>.</returns>
        public static ObservableCollection <StatisticMeasurement> GetStatisticMeasurements(AdoDataConnection database)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                // Get Statistic Definitions
                ObservableCollection <Statistic> statisticDefinitions = Statistic.Load(database);

                // Get statistics measurements.
                DataTable statisticMeasurements = database.Connection.RetrieveData(database.AdapterType, database.ParameterizedQueryString("SELECT SignalID, ID, DeviceID, PointID, PointTag, SignalReference, Description " +
                                                                                                                                           "FROM StatisticMeasurement WHERE NodeID = {0}", "nodeID"), DefaultTimeout, database.CurrentNodeID());

                // Assign min and max point IDs as we will need them to request data from web service.
                MinPointID = int.MaxValue;
                MaxPointID = int.MinValue;

                foreach (DataRow row in statisticMeasurements.Rows)
                {
                    int pointID = Convert.ToInt32(row.Field <object>("PointID"));
                    MinPointID = Math.Min(MinPointID, pointID);
                    MaxPointID = Math.Max(MaxPointID, pointID);
                }


                // Takes datarow from statisticMeasurements data table, and associates each row to their statistic source and returns KeyValuePair.
                Func <DataRow, KeyValuePair <DataRow, string> > mapFunction = measurement =>
                {
                    string signalReference = measurement.Field <string>("SignalReference");
                    string measurementSource;

                    if (StatisticsEngine.RegexMatch(signalReference, "SYSTEM"))
                    {
                        measurementSource = "System";
                    }
                    else if (StatisticsEngine.RegexMatch(signalReference, "PMU"))
                    {
                        measurementSource = "Device";
                    }
                    else if (StatisticsEngine.RegexMatch(signalReference, "OS"))
                    {
                        measurementSource = "OutputStream";
                    }
                    else if (StatisticsEngine.RegexMatch(signalReference, "IS"))
                    {
                        measurementSource = "InputStream";
                    }
                    else if (StatisticsEngine.RegexMatch(signalReference, "SUB"))
                    {
                        measurementSource = "Subscriber";
                    }
                    else if (StatisticsEngine.RegexMatch(signalReference, "PUB"))
                    {
                        measurementSource = "Publisher";
                    }
                    else
                    {
                        measurementSource = "???";
                    }

                    return(new KeyValuePair <DataRow, string>(measurement, measurementSource));
                };

                // Takes KeyValuePair and generates StatisticMeasurement record by maping statistic measurements with statistic definitions.
                Func <KeyValuePair <DataRow, string>, StatisticMeasurement> selectFunction = keyvaluepair =>
                {
                    DataRow measurement       = keyvaluepair.Key;
                    string  measurementSource = keyvaluepair.Value;
                    Debug.WriteLine(measurementSource);
                    string    signalReference      = measurement.Field <string>("SignalReference");
                    int       signalReferenceIndex = signalReference.LastIndexOf("-ST");
                    int       measurementIndex     = (signalReferenceIndex != -1) ? Convert.ToInt32(signalReference.Substring(signalReference.LastIndexOf("-ST") + 3)) : -1;
                    Statistic statisticDefinition  = null;

                    foreach (Statistic statistic in statisticDefinitions)
                    {
                        if (statistic.Source == measurementSource && statistic.SignalIndex == measurementIndex)
                        {
                            statisticDefinition = statistic;
                            break;
                        }
                    }

                    return(new StatisticMeasurement()
                    {
                        SignalID = database.Guid(measurement, "SignalID"),
                        ID = measurement.Field <string>("ID"),
                        DeviceID = Convert.ToInt32(measurement.Field <object>("DeviceID") ?? -1),
                        PointID = Convert.ToInt32(measurement.Field <object>("PointID")),
                        PointTag = measurement.Field <string>("PointTag"),
                        SignalReference = signalReference,
                        Source = measurementSource,
                        StatisticName = statisticDefinition?.Name ?? measurement.Field <string>("Description"),
                        StatisticDescription = statisticDefinition?.Description ?? measurement.Field <string>("Description"),
                        DataType = statisticDefinition?.DataType ?? "System.Double",
                        DisplayFormat = statisticDefinition?.DisplayFormat ?? "{0}",
                        ConnectedState = statisticDefinition?.IsConnectedState ?? false,
                        LoadOrder = statisticDefinition?.LoadOrder ?? 0,
                        TimeTag = "n/a",
                        Quality = "n/a",
                        Value = "--"
                    });
                };

                return(new ObservableCollection <StatisticMeasurement>(statisticMeasurements.Rows.Cast <DataRow>().Select(mapFunction).OrderBy(pair => pair.Value).Select(selectFunction).OrderBy(s => s.LoadOrder)));
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Saves <see cref="Statistic"/> information into the database.
 /// </summary>
 /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
 /// <param name="statistic">Information about <see cref="Statistic"/>.</param>
 /// <returns>String, for display use, indicating success.</returns>
 // TODO: For now, this method is just a place holder. In future when we create screen to manage Statistic
 // definitions, we will need to add code to it.
 public static string Save(AdoDataConnection database, Statistic statistic)
 {
     return string.Empty;
 }