Example #1
0
        /// <summary>
        /// Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.
        /// </summary>
        /// <param name="type">Annotation type.</param>
        /// <param name="response">Annotation response.</param>
        /// <param name="target">Target of annotation response.</param>
        /// <param name="definition">Associated metadata definition for response.</param>
        /// <param name="datapoint">Time series values data point for response.</param>
        /// <param name="source">Metadata of source definitions.</param>
        /// <returns>Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.</returns>
        public static void PopulateResponse(this AnnotationType type, AnnotationResponse response, string target, DataRow definition, double[] datapoint, DataSet source)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if ((object)target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            if (datapoint == null)
            {
                throw new ArgumentNullException(nameof(datapoint));
            }

            switch (type)
            {
            case AnnotationType.RaisedAlarms:
            case AnnotationType.ClearedAlarms:
                DataRow metadata = GetTargetMetaData(source, definition["SignalID"]);
                response.title = $"Alarm {(type == AnnotationType.RaisedAlarms ? "Raised" : "Cleared")}";
                response.text  = $"{definition["Description"]}<br/>Condition:&nbsp;{GetAlarmCondition(definition)}<br/>Severity:&nbsp;{definition["Severity"]}<br/>[{metadata["ID"]}]:&nbsp;{metadata["SignalReference"]}";
                response.tags  = $"{metadata["PointTag"]},{target}";
                break;

            default:
                throw new InvalidOperationException("Cannot populate response information for specified annotation type.");
            }
        }
        /// <summary>
        /// Queries openHistorian for annotations in a time-range (e.g., Alarms).
        /// </summary>
        /// <param name="request">Annotation request.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Queried annotations from data source.</returns>
        public async Task<List<AnnotationResponse>> Annotations(AnnotationRequest request, CancellationToken cancellationToken)
        {
            bool useFilterExpression;
            AnnotationType type = request.ParseQueryType(out useFilterExpression);
            Dictionary<string, DataRow> definitions = request.ParseSourceDefinitions(type, Metadata, useFilterExpression);
            List<TimeSeriesValues> annotationData = await Query(request.ExtractQueryRequest(definitions.Keys, MaximumAnnotationsPerRequest), cancellationToken);
            List<AnnotationResponse> responses = new List<AnnotationResponse>();

            foreach (TimeSeriesValues values in annotationData)
            {
                string target = values.target;
                DataRow definition = definitions[target];

                foreach (double[] datapoint in values.datapoints)
                {
                    if (type.IsApplicable(datapoint))
                    {
                        AnnotationResponse response = new AnnotationResponse
                        {
                            annotation = request.annotation,
                            time = datapoint[TimeSeriesValues.Time]
                        };

                        type.PopulateResponse(response, target, definition, datapoint, Metadata);

                        responses.Add(response);
                    }
                }
            }

            return responses;
        }
Example #3
0
        /// <summary>
        /// Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.
        /// </summary>
        /// <param name="type">Annotation type.</param>
        /// <param name="response">Annotation response.</param>
        /// <param name="target">Target of annotation response.</param>
        /// <param name="definition">Associated metadata definition for response.</param>
        /// <param name="datapoint">Time series values data point for response.</param>
        /// <returns>Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.</returns>
        public static void PopulateResponse(this AnnotationType type, AnnotationResponse response, string target, DataRow definition, double[] datapoint)
        {
            if ((object)response == null)
                throw new ArgumentNullException(nameof(response));

            if ((object)target == null)
                throw new ArgumentNullException(nameof(target));

            if ((object)definition == null)
                throw new ArgumentNullException(nameof(definition));

            if ((object)datapoint == null)
                throw new ArgumentNullException(nameof(datapoint));

            switch (type)
            {
                case AnnotationType.RaisedAlarms:
                case AnnotationType.ClearedAlarms:
                    response.title = $"Alarm {(type == AnnotationType.RaisedAlarms ? "Raised" : "Cleared")}";
                    response.text = $"{definition["Description"]}<br>Severity = {definition["Severity"]}<br>{definition["TagName"]}";
                    response.tags = $"{GetTargetFromGuid(definition["SignalID"].ToString())}, {target}";
                    break;
                default:
                    throw new InvalidOperationException("Cannot populate response information for specified annotation type.");
            }
        }
        /// <summary>
        /// Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.
        /// </summary>
        /// <param name="type">Annotation type.</param>
        /// <param name="response">Annotation response.</param>
        /// <param name="target">Target of annotation response.</param>
        /// <param name="definition">Associated metadata definition for response.</param>
        /// <param name="datapoint">Time series values data point for response.</param>
        /// <param name="source">Metadata of source definitions.</param>
        /// <returns>Populates an annotation response title, text and tags for specified annotation <paramref name="type"/>.</returns>
        public static void PopulateResponse(this AnnotationType type, AnnotationResponse response, string target, DataRow definition, double[] datapoint, DataSet source)
        {
            if ((object)response == null)
                throw new ArgumentNullException(nameof(response));

            if ((object)target == null)
                throw new ArgumentNullException(nameof(target));

            if ((object)definition == null)
                throw new ArgumentNullException(nameof(definition));

            if ((object)datapoint == null)
                throw new ArgumentNullException(nameof(datapoint));

            switch (type)
            {
                case AnnotationType.RaisedAlarms:
                case AnnotationType.ClearedAlarms:
                    DataRow metadata = GetTargetMetaData(source, definition["SignalID"]);
                    response.title = $"Alarm {(type == AnnotationType.RaisedAlarms ? "Raised" : "Cleared")}";
                    response.text = $"{definition["Description"]}<br/>Condition:&nbsp;{GetAlarmCondition(definition)}<br/>Severity:&nbsp;{definition["Severity"]}<br/>[{metadata["ID"]}]:&nbsp;{metadata["SignalReference"]}";
                    response.tags = $"{metadata["PointTag"]}, {target}";
                    break;
                default:
                    throw new InvalidOperationException("Cannot populate response information for specified annotation type.");
            }
        }