Exemplo n.º 1
0
 /// <summary>
 /// Clone sample
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static SubscriberSampleModel Clone(this SubscriberSampleModel model)
 {
     return(new SubscriberSampleModel {
         SubscriptionId = model.SubscriptionId,
         EndpointId = model.EndpointId,
         DataSetId = model.DataSetId,
         NodeId = model.NodeId,
         ServerPicoseconds = model.ServerPicoseconds,
         ServerTimestamp = model.ServerTimestamp,
         SourcePicoseconds = model.SourcePicoseconds,
         SourceTimestamp = model.SourceTimestamp,
         Timestamp = model.Timestamp,
         Value = model.Value
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Try to convert json to sample model
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        internal static SubscriberSampleModel ToSubscriberSampleModel(this JToken message)
        {
            if (message.Type != JTokenType.Object || !(message is JObject sampleRoot))
            {
                // Not a publisher sample object - not accepted
                return(null);
            }

            var value = sampleRoot.Property("Value", StringComparison.InvariantCultureIgnoreCase)?
                        .Value;

            if (value == null)
            {
                // No value
                return(null);
            }

            var result = new SubscriberSampleModel()
            {
                Timestamp = DateTime.Now
            };

            // check if value comes from the legacy publisher:
            var applicationUri = sampleRoot.GetValueOrDefault <string>("ApplicationUri",
                                                                       StringComparison.InvariantCultureIgnoreCase);

            if (applicationUri == null || applicationUri == string.Empty)
            {
                result.EndpointId = sampleRoot.GetValueOrDefault <string>("EndpointId",
                                                                          StringComparison.InvariantCultureIgnoreCase);
                result.SubscriptionId = sampleRoot.GetValueOrDefault <string>("SubscriptionId",
                                                                              StringComparison.InvariantCultureIgnoreCase);
                result.DataSetId = sampleRoot.GetValueOrDefault <string>("DataSetId",
                                                                         StringComparison.InvariantCultureIgnoreCase);
            }
            else
            {
                result.EndpointId     = applicationUri;
                result.SubscriptionId = "LegacyPublisher";
                result.DataSetId      = sampleRoot.GetValueOrDefault <string>("DisplayName",
                                                                              StringComparison.InvariantCultureIgnoreCase);
            }

            result.NodeId = sampleRoot.GetValueOrDefault <string>("NodeId",
                                                                  StringComparison.InvariantCultureIgnoreCase);

            // Check if the value is a data value or if the value was flattened into the root.
            var dataValue = sampleRoot;

            if (IsDataValue(value))
            {
                dataValue    = value as JObject;
                result.Value = dataValue.GetValueOrDefault <JToken>("Value",
                                                                    StringComparison.InvariantCultureIgnoreCase);
            }
            else
            {
                result.Value = value;
            }

            result.SourcePicoseconds = dataValue.GetValueOrDefault <ushort?>("SourcePicoseconds",
                                                                             StringComparison.InvariantCultureIgnoreCase);
            result.ServerPicoseconds = dataValue.GetValueOrDefault <ushort?>("ServerPicoseconds",
                                                                             StringComparison.InvariantCultureIgnoreCase);
            result.SourceTimestamp = dataValue.GetValueOrDefault <DateTime?>("SourceTimestamp",
                                                                             StringComparison.InvariantCultureIgnoreCase);
            result.ServerTimestamp = dataValue.GetValueOrDefault <DateTime?>("ServerTimestamp",
                                                                             StringComparison.InvariantCultureIgnoreCase);
            return(result);
        }