public void Execute(IInnerContent parameter)
 {
     if (_specification.IsSatisfiedBy(parameter))
     {
         _instance.Execute(parameter);
     }
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
                public void Execute(IInnerContent parameter)
                {
                    var contexts = _contexts.Get(parameter.Get());

                    contexts.Push(parameter);
                    _handler.Execute(parameter);
                    contexts.Pop();
                }
コード例 #5
0
        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);
        }
コード例 #6
0
 public InnerContent(IInnerContent content, ConditionMonitor monitor, bool apply)
 {
     _content = content;
     _monitor = monitor;
     if (apply)
     {
         monitor.Apply();
     }
 }
コード例 #7
0
                public bool IsSatisfiedBy(IInnerContent parameter)
                {
                    var contexts = _contexts.Get(parameter.Get());

                    contexts.Push(parameter);
                    var result = _handler.IsSatisfiedBy(parameter);

                    contexts.Pop();
                    return(result);
                }
コード例 #8
0
        public bool IsSatisfiedBy(IInnerContent parameter)
        {
            var result = _specification.IsSatisfiedBy(parameter);

            if (result)
            {
                _handler.Handle((IListInnerContent)parameter, _item);
            }

            return(result);
        }
コード例 #9
0
        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));
     }
 }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
 public void Execute(IInnerContent parameter) => _handler.Handle((IListInnerContent)parameter, _item);
コード例 #14
0
 public object Get(IInnerContent parameter)
 => (parameter.Current as IActivationContext)?.Get() ?? _result.Get(parameter);
コード例 #15
0
 public void Assign(IInnerContent contents, IMemberAccess access, object value)
 => access.Assign(contents.Current, value);
コード例 #16
0
 public void Handle(IInnerContent contents, IMemberSerializer member) => _member.Handle(contents, member);
コード例 #17
0
 public bool IsSatisfiedBy(IInnerContent parameter)
 => _members.IsSatisfiedBy(parameter) || _collection.IsSatisfiedBy(parameter);
コード例 #18
0
 public IMemberSerialization Get(IInnerContent parameter) => Get(parameter.Current);
コード例 #19
0
 public InnerContent(IInnerContent content, ConditionMonitor monitor)
 {
     _content = content;
     _monitor = monitor;
 }
コード例 #20
0
 public bool IsSatisfiedBy(IInnerContent parameter)
 => _specification.IsSatisfiedBy(parameter) && _instance.IsSatisfiedBy(parameter);
コード例 #21
0
 public object Get(IInnerContent parameter)
 {
     _command.Execute(parameter);
     return(_results.Get(parameter));
 }
コード例 #22
0
ファイル: InnerContentResult.cs プロジェクト: wtf3505/home
 public object Get(IInnerContent parameter) => parameter.Current;
コード例 #23
0
 public InnerContent(IInnerContent content, bool apply)  : this(content, new ConditionMonitor(), apply)
 {
 }
コード例 #24
0
 static IDeferredCommand Member(IInnerContent current, ISource <object> source)
 => new DeferredMemberAssignmentCommand(current.Current,
                                        ContentsContext.Default.Get(current)
                                        .AsValid <IMemberAccess>(),
                                        source);
コード例 #25
0
 public void Handle(IInnerContent contents, IMemberSerializer member)
 {
     ContentsContext.Default.Assign(contents, member.Access);
     _handler.Handle(contents, member);
     ContentsContext.Default.Remove(contents);
 }