| | | 1 | | using pva.SuperV.Engine.Exceptions; |
| | | 2 | | using pva.SuperV.Engine.Processing; |
| | | 3 | | using System.Text.Json.Serialization; |
| | | 4 | | |
| | | 5 | | namespace pva.SuperV.Engine.HistoryStorage |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// History repository to store history of instance values. |
| | | 9 | | /// </summary> |
| | 158 | 10 | | public class HistoryRepository(string name) |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets the history repository name. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <value> |
| | | 16 | | /// The name. |
| | | 17 | | /// </value> |
| | 891 | 18 | | public string Name { get; } = IdentifierValidation.ValidateIdentifier("history repository", name); |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the history storage engine used to store values. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <value> |
| | | 24 | | /// The history storage engine. |
| | | 25 | | /// </value> |
| | | 26 | | [JsonIgnore] |
| | 774 | 27 | | public IHistoryStorageEngine? HistoryStorageEngine { get; set; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets of sets the history storage ID. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <value> The history storage ID</value> |
| | 379 | 33 | | public string? HistoryStorageId { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Upserts the repository in storage engine. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <param name="projectName">Name of project.</param> |
| | | 39 | | /// <param name="historyStorageEngine">History storage engine.</param> |
| | | 40 | | internal void UpsertRepository(string projectName, IHistoryStorageEngine historyStorageEngine) => |
| | 111 | 41 | | HistoryStorageId = historyStorageEngine.UpsertRepository(projectName, this); |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Upserts a time series in storage engine. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <typeparam name="T"></typeparam> |
| | | 47 | | /// <param name="projectName">Name of project.</param> |
| | | 48 | | /// <param name="className">Name of class.</param> |
| | | 49 | | /// <param name="historizationProcessing">History processing for which the time series is to be created.</param> |
| | | 50 | | /// <returns></returns> |
| | | 51 | | /// <exception cref="NoHistoryStorageEngineException"></exception> |
| | | 52 | | internal string UpsertClassTimeSerie<T>(string projectName, string className, HistorizationProcessing<T> histori |
| | 220 | 53 | | { |
| | 220 | 54 | | if (HistoryStorageEngine is null) |
| | 0 | 55 | | { |
| | 0 | 56 | | throw new NoHistoryStorageEngineException(); |
| | | 57 | | } |
| | 220 | 58 | | return HistoryStorageEngine.UpsertClassTimeSerie(HistoryStorageId!, projectName, className, historizationPro |
| | 219 | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Historize instance values in storage engine |
| | | 63 | | /// </summary> |
| | | 64 | | /// <param name="classTimeSerieId">The time series ID.</param> |
| | | 65 | | /// <param name="instance">The instance.</param> |
| | | 66 | | /// <param name="timestamp">the timestamp of the values</param> |
| | | 67 | | /// <param name="fieldsToHistorize">List of fields to be historized.</param> |
| | | 68 | | public void HistorizeValues(string classTimeSerieId, IInstance instance, DateTime timestamp, QualityLevel? quali |
| | 26 | 69 | | { |
| | 26 | 70 | | HistoryStorageEngine?.HistorizeValues(HistoryStorageId!, classTimeSerieId, instance.Name, timestamp, quality |
| | 26 | 71 | | } |
| | | 72 | | } |
| | | 73 | | } |