public void Execute(IInnerContent parameter) { if (_specification.IsSatisfiedBy(parameter)) { _instance.Execute(parameter); } }
/// <summary> /// Constructor /// </summary> /// <param name="cloudEvent">CloudEvent</param> /// <param name="contentMode">Content mode. Structured or binary.</param> /// <param name="formatter">Event formatter</param> public CloudEventContent(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter) { if (contentMode == ContentMode.Structured) { inner = new InnerByteArrayContent(formatter.EncodeStructuredEvent(cloudEvent, out var contentType)); // This is optional in the specification, but can be useful. MapHeaders(cloudEvent, includeDataContentType: true); Headers.ContentType = new MediaTypeHeaderValue(contentType.MediaType); return; } if (cloudEvent.Data is byte[]) { inner = new InnerByteArrayContent((byte[])cloudEvent.Data); } else if (cloudEvent.Data is string) { inner = new InnerStringContent((string)cloudEvent.Data); } else if (cloudEvent.Data is Stream) { inner = new InnerStreamContent((Stream)cloudEvent.Data); } else { inner = new InnerByteArrayContent(formatter.EncodeAttribute(cloudEvent.SpecVersion, CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion), cloudEvent.Data, cloudEvent.Extensions.Values)); } var mediaType = cloudEvent.DataContentType?.MediaType ?? throw new ArgumentException(Strings.ErrorContentTypeUnspecified, nameof(cloudEvent)); Headers.ContentType = new MediaTypeHeaderValue(mediaType); MapHeaders(cloudEvent, includeDataContentType: false); }
/// <summary> /// Constructor /// </summary> /// <param name="cloudEvent">CloudEvent</param> /// <param name="contentMode">Content mode. Structured or binary.</param> /// <param name="formatter">Event formatter</param> public CloudEventContent(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter) { if (contentMode == ContentMode.Structured) { inner = new InnerByteArrayContent(formatter.EncodeStructuredEvent(cloudEvent, out var contentType)); Headers.ContentType = new MediaTypeHeaderValue(contentType.MediaType); MapHeaders(cloudEvent); return; } if (cloudEvent.Data is byte[]) { inner = new InnerByteArrayContent((byte[])cloudEvent.Data); } else if (cloudEvent.Data is string) { inner = new InnerStringContent((string)cloudEvent.Data); } else if (cloudEvent.Data is Stream) { inner = new InnerStreamContent((Stream)cloudEvent.Data); } else { inner = new InnerByteArrayContent(formatter.EncodeAttribute(cloudEvent.SpecVersion, CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion), cloudEvent.Data, cloudEvent.Extensions.Values)); } Headers.ContentType = new MediaTypeHeaderValue(cloudEvent.DataContentType?.MediaType); MapHeaders(cloudEvent); }
public void Execute(IInnerContent parameter) { var contexts = _contexts.Get(parameter.Get()); contexts.Push(parameter); _handler.Execute(parameter); contexts.Pop(); }
static IDeferredCommand Command(IInnerContent current, ISource <object> source) { var list = current as IListInnerContent; var result = list != null ? new DeferredCollectionAssignmentCommand(list.List, source) : Member(current, source); return(result); }
public InnerContent(IInnerContent content, ConditionMonitor monitor, bool apply) { _content = content; _monitor = monitor; if (apply) { monitor.Apply(); } }
public bool IsSatisfiedBy(IInnerContent parameter) { var contexts = _contexts.Get(parameter.Get()); contexts.Push(parameter); var result = _handler.IsSatisfiedBy(parameter); contexts.Pop(); return(result); }
public bool IsSatisfiedBy(IInnerContent parameter) { var result = _specification.IsSatisfiedBy(parameter); if (result) { _handler.Handle((IListInnerContent)parameter, _item); } return(result); }
public bool IsSatisfiedBy(IInnerContent parameter) { var content = parameter.Get(); var key = _formatter.Get(content); var member = _serialization.Get(parameter.Current) .Get(key); var result = member != null; if (result) { _handler.Handle(parameter, member); } return(result); }
public void Handle(IInnerContent contents, IMemberSerializer member) { try { _handler.Handle(contents, member); } catch (Exception e) { var line = contents.Get() .Get() .To <IXmlLineInfo>(); throw new InvalidOperationException($"An exception was encountered while deserializing member '{member.Profile.Metadata.ReflectedType}.{member.Profile.Name}'.", new XmlException(e.Message, e, line.LineNumber, line.LinePosition)); } }
/// <summary> /// Constructor /// </summary> /// <param name="cloudEvent">CloudEvent</param> /// <param name="contentMode">Content mode. Structured or binary.</param> /// <param name="formatter">Event formatter</param> public CloudEventHttpContent(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter) { if (contentMode == ContentMode.Structured) { inner = new InnerByteArrayContent(formatter.EncodeStructuredEvent(cloudEvent, out var contentType)); // This is optional in the specification, but can be useful. MapHeaders(cloudEvent, includeDataContentType: true); Headers.ContentType = new MediaTypeHeaderValue(contentType.MediaType); return; } // TODO: Shouldn't we use the formatter in all cases? If I have a JSON formatter and // If we specify that the the data is a byte array, I'd expect to end up with a base64-encoded representation... if (cloudEvent.Data is byte[]) { inner = new InnerByteArrayContent((byte[])cloudEvent.Data); } else if (cloudEvent.Data is string) { inner = new InnerStringContent((string)cloudEvent.Data); } else if (cloudEvent.Data is Stream) { inner = new InnerStreamContent((Stream)cloudEvent.Data); } else { inner = new InnerByteArrayContent(formatter.EncodeData(cloudEvent.Data)); } // We don't require a data content type if there isn't any data. // We may not be able to tell whether the data is empty or not, but we're lenient // in that case. var dataContentType = cloudEvent.DataContentType; if (dataContentType is object) { var mediaType = new ContentType(dataContentType).MediaType; Headers.ContentType = new MediaTypeHeaderValue(mediaType); } else if (TryComputeLength(out var length) && length != 0L) { throw new ArgumentException(Strings.ErrorContentTypeUnspecified, nameof(cloudEvent)); } MapHeaders(cloudEvent, includeDataContentType: false); }
public bool IsSatisfiedBy(IInnerContent parameter) { var content = parameter.Get(); var key = _formatter.Get(content); var serialization = _serialization.Get(parameter); if (serialization != null) { var member = serialization.Get(key); var result = member != null; if (result) { _handler.Handle(parameter, member); return(true); } } return(false); }
public void Execute(IInnerContent parameter) => _handler.Handle((IListInnerContent)parameter, _item);
public object Get(IInnerContent parameter) => (parameter.Current as IActivationContext)?.Get() ?? _result.Get(parameter);
public void Assign(IInnerContent contents, IMemberAccess access, object value) => access.Assign(contents.Current, value);
public void Handle(IInnerContent contents, IMemberSerializer member) => _member.Handle(contents, member);
public bool IsSatisfiedBy(IInnerContent parameter) => _members.IsSatisfiedBy(parameter) || _collection.IsSatisfiedBy(parameter);
public IMemberSerialization Get(IInnerContent parameter) => Get(parameter.Current);
public InnerContent(IInnerContent content, ConditionMonitor monitor) { _content = content; _monitor = monitor; }
public bool IsSatisfiedBy(IInnerContent parameter) => _specification.IsSatisfiedBy(parameter) && _instance.IsSatisfiedBy(parameter);
public object Get(IInnerContent parameter) { _command.Execute(parameter); return(_results.Get(parameter)); }
public object Get(IInnerContent parameter) => parameter.Current;
public InnerContent(IInnerContent content, bool apply) : this(content, new ConditionMonitor(), apply) { }
static IDeferredCommand Member(IInnerContent current, ISource <object> source) => new DeferredMemberAssignmentCommand(current.Current, ContentsContext.Default.Get(current) .AsValid <IMemberAccess>(), source);
public void Handle(IInnerContent contents, IMemberSerializer member) { ContentsContext.Default.Assign(contents, member.Access); _handler.Handle(contents, member); ContentsContext.Default.Remove(contents); }