/// <summary> /// Convert read processed details /// </summary> /// <param name="codec"></param> /// <param name="details"></param> /// <returns></returns> public static JToken Encode(this IVariantEncoder codec, ReadProcessedValuesDetailsModel details) { if (details == null) { throw new ArgumentNullException(nameof(details)); } if (details.EndTime == null && details.StartTime == null) { throw new ArgumentException("Start time and end time cannot both be null", nameof(details)); } // Convert aggregate id with a temporary namespace table that will contain the aggregate namespace var context = new ServiceMessageContext(); var aggregate = details.AggregateTypeId?.ToNodeId(context); return(codec.Encode(new ExtensionObject(new ReadProcessedDetails { EndTime = details.EndTime ?? DateTime.MinValue, StartTime = details.StartTime ?? DateTime.MinValue, AggregateType = aggregate == null ? null : new NodeIdCollection(aggregate.YieldReturn()), ProcessingInterval = details.ProcessingInterval ?? 0, AggregateConfiguration = details.AggregateConfiguration == null ? null : new AggregateConfiguration { PercentDataBad = details.AggregateConfiguration.PercentDataBad ?? 0, PercentDataGood = details.AggregateConfiguration.PercentDataGood ?? 0, TreatUncertainAsBad = details.AggregateConfiguration.TreatUncertainAsBad ?? false, UseServerCapabilitiesDefaults = details.AggregateConfiguration.UseServerCapabilitiesDefaults ?? false, UseSlopedExtrapolation = details.AggregateConfiguration.UseSlopedExtrapolation ?? false } }), context)); // Reapplies the aggregate namespace uri during encoding using the context's table }
/// <summary> /// Create from service model /// </summary> /// <param name="model"></param> public ReadProcessedValuesDetailsApiModel(ReadProcessedValuesDetailsModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } StartTime = model.StartTime; EndTime = model.EndTime; ProcessingInterval = model.ProcessingInterval; AggregateTypeId = model.AggregateTypeId; AggregateConfiguration = model.AggregateConfiguration == null ? null : new AggregateConfigApiModel(model.AggregateConfiguration); }
/// <summary> /// Create api model /// </summary> public static ReadProcessedValuesDetailsApiModel ToApiModel( this ReadProcessedValuesDetailsModel model) { if (model == null) { return(null); } return(new ReadProcessedValuesDetailsApiModel { EndTime = model.EndTime, StartTime = model.StartTime, ProcessingInterval = model.ProcessingInterval, AggregateConfiguration = model.AggregateConfiguration.ToApiModel(), AggregateTypeId = model.AggregateTypeId }); }
/// <summary> /// Convert read processed details /// </summary> /// <param name="codec"></param> /// <param name="details"></param> /// <returns></returns> public static JToken Encode(this IVariantEncoder codec, ReadProcessedValuesDetailsModel details) { if (details == null) { throw new ArgumentNullException(nameof(details)); } if (details.EndTime == null && details.StartTime == null) { throw new ArgumentException("Start time and end time cannot both be null", nameof(details)); } var aggregate = details.AggregateTypeId?.ToNodeId(codec.Context); return(codec.Encode(new ExtensionObject(new ReadProcessedDetails { EndTime = details.EndTime ?? DateTime.MinValue, StartTime = details.StartTime ?? DateTime.MinValue, AggregateType = aggregate == null ? null : new NodeIdCollection(aggregate.YieldReturn()), ProcessingInterval = details.ProcessingInterval ?? 0, AggregateConfiguration = details.AggregateConfiguration.ToStackModel() }))); // Reapplies the aggregate namespace uri during encoding using the context's table }