Exemplo n.º 1
0
 /// <summary>
 /// Sets both the 'sequence' and 'sequencetype' attributes based on the specified value.
 /// </summary>
 public static CloudEvent SetSequence(this CloudEvent cloudEvent, object value)
 {
     if (value is null)
     {
         cloudEvent[SequenceAttribute]     = null;
         cloudEvent[SequenceTypeAttribute] = null;
     }
     else if (value is int)
     {
         // TODO: Validation? Would be nice to get a sort of "surrogate" attribute here...
         cloudEvent[SequenceAttribute]     = SurrogateIntegerAttribute.Format(value);
         cloudEvent[SequenceTypeAttribute] = IntegerType;
     }
     else
     {
         throw new ArgumentException($"No sequence type known for type {value.GetType()}");
     }
     return(cloudEvent);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves the <see cref="SequenceAttribute"/> value from the event,
        /// parsing it according to the value of <see cref="SequenceTypeAttribute"/>.
        /// If no type is present in the event, the string value is
        /// returned without further transformation.
        /// </summary>
        public static object GetSequenceValue(this CloudEvent cloudEvent)
        {
            var sequence = GetSequenceString(cloudEvent);

            if (sequence is null)
            {
                return(null);
            }
            var type = GetSequenceType(cloudEvent);

            if (type == null)
            {
                return(sequence);
            }
            if (type == IntegerType)
            {
                return(SurrogateIntegerAttribute.Parse(sequence));
            }
            throw new InvalidOperationException($"Unknown sequence type '{type}'");
        }