Exemplo n.º 1
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            bool done     = false;
            int  messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
                while (!done)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind == MessageKind.Completed)
                    {
                        done = true;
                    }
                    observer.OnNext(message.Message);
                    messages++;
                    if (this.numMessages != 0 && messages == this.numMessages)
                    {
                        if (message.Kind != MessageKind.Completed)
                        {
                            observer.OnCompleted();
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }
        }
Exemplo n.º 2
0
        public BinaryIngressStreamable(Stream binaryStream, int numMessages, IIngressScheduler scheduler, StreamProperties <TKey, TPayload> inputProperties, bool readPropertiesFromStream, QueryContainer container, string identifier)
            : base((inputProperties ?? StreamProperties <TKey, TPayload> .Default).SetQueryContainer(container))
        {
            if (readPropertiesFromStream)
            {
                var propSer = StreamableSerializer.Create <SerializedProperties>();
                var props   = propSer.Deserialize(binaryStream);
                this.properties = props.ToStreamProperties <TKey, TPayload>();
            }

            this.stream = binaryStream;
            if (this.stream.CanSeek)
            {
                this.streamStartPosition = binaryStream.Position;
            }
            this.numMessages           = numMessages;
            this.scheduler             = scheduler;
            this.container             = container;
            this.IngressSiteIdentifier = identifier ?? Guid.NewGuid().ToString();
            this.delayed = container != null;
            if (this.delayed)
            {
                container.RegisterIngressSite(identifier);
            }
        }
Exemplo n.º 3
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            int messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(
                    new SerializerSettings()
                {
                    KnownTypes = StreamMessageManager.GeneratedTypes()
                });
                while (true)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind != MessageKind.Completed)
                    {
                        observer.OnNext(message.Message);
                        messages++;
                    }
                    if (message.Kind == MessageKind.Completed ||
                        (this.numMessages != 0 && messages == this.numMessages))
                    {
                        observer.OnCompleted();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }

            this.onSubscriptionCompleted();
        }
Exemplo n.º 4
0
 public BinaryStreamObserver(StreamProperties <TKey, TPayload> streamProperties, Stream stream)
 {
     this.serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(
         new SerializerSettings()
     {
         KnownTypes = StreamMessageManager.GeneratedTypes()
     });
     this.stream = stream;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Serialize streamable into a binary stream
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TPayload"></typeparam>
 /// <param name="container">The query container to which an egress point is being added.</param>
 /// <param name="identifier">A string that can uniquely identify the point of egress in the query.</param>
 /// <param name="input"></param>
 /// <param name="binaryStream"></param>
 /// <param name="writePropertiesToStream"></param>
 public static void RegisterBinaryOutput <TKey, TPayload>(this QueryContainer container, IStreamable <TKey, TPayload> input, Stream binaryStream, bool writePropertiesToStream = false, string identifier = null)
 {
     if (writePropertiesToStream)
     {
         var propSer = StreamableSerializer.Create <SerializedProperties>();
         propSer.Serialize(binaryStream, SerializedProperties.FromStreamProperties(input.Properties));
     }
     container.RegisterOutputAsStreamMessages(input, identifier)
     .Subscribe(new BinaryStreamObserver <TKey, TPayload>(input.Properties, binaryStream));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Serialize streamable into a binary stream
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TPayload"></typeparam>
 /// <param name="input"></param>
 /// <param name="binaryStream"></param>
 /// <param name="writePropertiesToStream"></param>
 public static void ToBinaryStream <TKey, TPayload>(this IStreamable <TKey, TPayload> input, Stream binaryStream, bool writePropertiesToStream = false)
 {
     if (writePropertiesToStream)
     {
         var propSer = StreamableSerializer.Create <SerializedProperties>();
         propSer.Serialize(binaryStream, SerializedProperties.FromStreamProperties(input.Properties));
     }
     input.ToStreamMessageObservable()
     .Subscribe(new BinaryStreamObserver <TKey, TPayload>(input.Properties, binaryStream));
 }
Exemplo n.º 7
0
        // TODO: This appears to be copied code from Binary egress - can we unify?
        public ShardedSerializerObserver(Stream destination, StreamProperties <TKey, TPayload> sourceProps, bool writePropertiesToStream = false)
        {
            this.destination = destination;
            if (writePropertiesToStream)
            {
                var propSer = StreamableSerializer.Create <SerializedProperties>();
                propSer.Serialize(destination, SerializedProperties.FromStreamProperties(sourceProps));
            }

            this.serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
        }
        private static void TestSerialization <T>(T enumerable)
            where T : IEnumerable <int>
        {
            var serializer = StreamableSerializer.Create <T>();

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, enumerable);
                stream.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                var copy = serializer.Deserialize(stream);

                Assert.IsTrue(enumerable.SequenceEqual(copy));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Write stream properties to specified .NET stream
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TPayload"></typeparam>
        /// <param name="streamable"></param>
        /// <param name="stream"></param>
        public static void WritePropertiesToStream <TKey, TPayload>(this IShardedStreamable <TKey, TPayload> streamable, Stream stream)
        {
            var properties        = StreamProperties <TKey, TPayload> .Default;
            var shardedStreamable = (ShardedStreamable <TKey, TPayload>)streamable;

            if (shardedStreamable != null)
            {
                if (shardedStreamable.Streamables.Length > 0)
                {
                    properties = shardedStreamable.Streamables[0].Properties;
                }
            }
            var propSer = StreamableSerializer.Create <SerializedProperties>();

            propSer.Serialize(stream, SerializedProperties.FromStreamProperties(properties));
        }
Exemplo n.º 10
0
        public BinaryIngressStreamablePassive(Stream binaryStream, StreamProperties <TKey, TPayload> inputProperties, bool readPropertiesFromStream, QueryContainer container, string identifier)
            : base((inputProperties ?? StreamProperties <TKey, TPayload> .Default).SetQueryContainer(container))
        {
            if (readPropertiesFromStream)
            {
                var propSer = StreamableSerializer.Create <SerializedProperties>();
                var props   = propSer.Deserialize(binaryStream);
                this.properties = props.ToStreamProperties <TKey, TPayload>();
            }

            this.stream                = binaryStream;
            this.serializer            = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
            this.container             = container;
            this.IngressSiteIdentifier = identifier ?? Guid.NewGuid().ToString();
            container?.RegisterIngressSite(identifier);
            this.restored = container == null;
        }
Exemplo n.º 11
0
 public BinaryStreamObserver(StreamProperties <TKey, TPayload> streamProperties, Stream stream)
 {
     this.serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
     this.stream     = stream;
 }