示例#1
0
        /// <inheritdoc/>
        public Guid RegisterStreamValueSubscriber <TTarget>(
            IStreamAdapter streamAdapter,
            RelativeTimeInterval epsilonTimeInterval,
            Action <bool, TTarget, DateTime, DateTime> callback)
        {
            var publisher = default(StreamValuePublisher <TSource, TTarget>);

            lock (this.publishers)
            {
                // Check if we have a publisher for this epsilon interval
                if (!this.publishers.ContainsKey(epsilonTimeInterval))
                {
                    this.publishers.Add(epsilonTimeInterval, new List <IStreamValuePublisher <TSource> >());
                }

                // Get the list of publishers for the specified epsilon interval
                var epsilonTimeIntervalPublishers = this.publishers[epsilonTimeInterval];

                // Check if we already have a publisher that uses the specified stream adapter
                publisher = epsilonTimeIntervalPublishers.FirstOrDefault(p => p.StreamAdapter.Equals(streamAdapter)) as StreamValuePublisher <TSource, TTarget>;
                if (publisher == null)
                {
                    // If not found, create a new publisher
                    publisher = new StreamValuePublisher <TSource, TTarget>(streamAdapter);
                    epsilonTimeIntervalPublishers.Add(publisher);
                }
            }

            // Register the subscriber with this publisher
            return(publisher.RegisterSubscriber(callback));
        }
        /// <summary>
        /// Deserializes the Sphinx server response data on the provided stream and reconstitutes the graph of objects.
        /// </summary>
        /// <param name="stream">The stream that contains the data to deserialize.</param>
        /// <exception cref="ServerErrorException"/>
        /// <exception cref="SphinxException"/>
        /// <exception cref="IOException"/>
        internal protected override void Deserialize(IStreamAdapter stream)
        {
            IBinaryReader reader = Connection.FormatterFactory.CreateReader(stream);

            // read general command response header values
            Result.Status = (CommandStatus)reader.ReadInt16();
            short serverCommandVersion = reader.ReadInt16();

            // read response body length
            int length = reader.ReadInt32();

            if (length <= 0 || length > MaxCommandBodyLength)
            {
                throw new SphinxException(String.Format(Messages.Exception_InvalidServerResponseLength, length));
            }

            // read server response body
            byte[] buffer = new byte[length];
            stream.ReadBytes(buffer, length);
            MemoryStream  bodyStream = new MemoryStream(buffer);
            IBinaryReader bodyReader = Connection.FormatterFactory.CreateReader(new StreamAdapter(bodyStream));

            // check response status
            ValidateResponse(bodyReader, serverCommandVersion);

            // parse command result
            DeserializeResponse(bodyReader);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamCache{T}"/> class.
        /// </summary>
        /// <param name="streamName">the name of the stream to read.</param>
        /// <param name="streamAdapter">the stream adapter to convert data from the stream into the type required by clients of this stream reader.</param>
        public StreamCache(string streamName, IStreamAdapter streamAdapter /*, object[] streamAdapterParameters*/)
        {
            if (string.IsNullOrWhiteSpace(streamName))
            {
                throw new ArgumentNullException(nameof(streamName));
            }

            this.StreamName    = streamName;
            this.StreamAdapter = streamAdapter;

            this.pool = PoolManager.Instance.GetPool <T>();

            this.readRequestsInternal = new List <ReadRequest>();
            this.readRequests         = new ReadOnlyCollection <ReadRequest>(this.readRequestsInternal);

            this.bufferLock  = new object();
            this.dataBuffer  = new List <Message <T> >(1000);
            this.indexBuffer = new List <StreamCacheEntry>(1000);

            var itemComparer = Comparer <Message <T> > .Create((m1, m2) => m1.OriginatingTime.CompareTo(m2.OriginatingTime));

            var indexComarer = Comparer <StreamCacheEntry> .Create((i1, i2) => i1.OriginatingTime.CompareTo(i2.OriginatingTime));

            this.data  = new ObservableKeyedCache <DateTime, Message <T> >(null, itemComparer, m => m.OriginatingTime);
            this.index = new ObservableKeyedCache <DateTime, StreamCacheEntry>(null, indexComarer, ie => ie.OriginatingTime);

            this.instantIndexView = null;

            this.instantStreamReaders = new List <EpsilonInstantStreamReader <T> >();

            if (this.needsDisposing)
            {
                this.data.CollectionChanged += this.OnCollectionChanged;
            }
        }
        protected Stream GetStream(IStreamAdapter adapter)
        {
            PrivateObject          po       = new PrivateObject(adapter);
            StreamAdapter_Accessor accessor = new StreamAdapter_Accessor(po);

            return(accessor.Stream);
        }
示例#5
0
        public void SetUp()
        {
            _mocks = new MockRepository();

             _streamAdapter = _mocks.DynamicMock<IStreamAdapter>();
             _serializeAdapter = _mocks.DynamicMock<ISerializeAdapter>();
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstantDataTarget"/> class.
 /// </summary>
 /// <param name="streamName">The name of the stream from which to receive updates when new data is available.</param>
 /// <param name="streamAdapter">The stream adapter to convert the raw stream data to the type required by the callback target.</param>
 /// <param name="cursorEpsilon">The cursor epsilon to use when searching for data.</param>
 /// <param name="callback">The method to call when new data is available.</param>
 public InstantDataTarget(string streamName, IStreamAdapter streamAdapter, RelativeTimeInterval cursorEpsilon, Action <object, IndexEntry> callback)
 {
     this.RegistrationToken = Guid.NewGuid();
     this.StreamName        = streamName;
     this.StreamAdapter     = streamAdapter;
     this.CursorEpsilon     = cursorEpsilon;
     this.Callback          = callback;
 }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamBinding"/> class.
        /// </summary>
        /// <param name="source">An existing stream binding to clone.</param>
        /// <param name="summarizerType">The type of the stream summarizer, null if there is none.</param>
        /// <param name="summarizerArgs">The arguments used when constructing the stream summarizer, null if ther is none.</param>
        public StreamBinding(StreamBinding source, Type summarizerType, object[] summarizerArgs)
            : this(source.StreamName, source.PartitionName, source.StoreName, source.StorePath, source.SimpleReaderType, source.StreamAdapterType, summarizerType, summarizerArgs)
        {
            this.streamAdapter = source.streamAdapter;

            // Do not copy this over since the type or args may have changed
            this.summarizer = null;
        }
		public IBinaryWriter CreateWriter(IStreamAdapter stream)
        {
            switch (_formatType)
            {
                case BinaryFormatType.BigEndian:
                    return new BigEndianBinaryWriter(stream, _encoding);
            }
            throw new NotSupportedException(String.Format(Messages.Exception_BinaryFormatNotSupported, Enum.GetName(typeof(BinaryFormatType), _formatType)));
        }
 public IBinaryWriter CreateWriter(IStreamAdapter stream)
 {
     switch (_formatType)
     {
     case BinaryFormatType.BigEndian:
         return(new BigEndianBinaryWriter(stream, _encoding));
     }
     throw new NotSupportedException(String.Format(Messages.Exception_BinaryFormatNotSupported, Enum.GetName(typeof(BinaryFormatType), _formatType)));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AdaptingInstantDataProvider{TSource, TDestination}"/> class.
        /// </summary>
        /// <param name="streamAdapter">The stream adapter that will convert the incoming data to the data that the targets require.</param>
        public AdaptingInstantDataProvider(IStreamAdapter streamAdapter)
        {
            if (streamAdapter == null)
            {
                throw new ArgumentNullException(nameof(streamAdapter));
            }

            this.streamAdapter = streamAdapter as StreamAdapter <TSource, TDestination>;
            this.targets       = new Dictionary <Guid, InstantDataTarget>();
        }
示例#11
0
        private IStreamReader GetExistingStreamReader(string streamName, IStreamAdapter streamAdapter)
        {
            IStreamReader streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                throw new ArgumentException("No stream reader exists for the stream.");
            }

            return(streamReader);
        }
示例#12
0
        private IStreamReader GetOrCreateStreamReader <T>(string streamName, IStreamAdapter streamAdapter)
        {
            var streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                streamReader = new StreamReader <T>(streamName, streamAdapter);
                this.streamReaders.Add(streamReader);
            }

            return(streamReader);
        }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and a specific character encoding.
        /// </summary>
        /// <param name="input">Input stream</param>
        /// <param name="encoding">The character encoding object used to decode strings from stream</param>
		protected BinaryReaderBase(IStreamAdapter input, Encoding encoding)
        {
            ArgumentAssert.IsNotNull(input, "input");
            ArgumentAssert.IsNotNull(encoding, "encoding");
            if (!input.CanRead)
            {
                throw new IOException(Messages.Exception_CantReadFromStream);
            }

            _inputStream = input;
            _encoding = encoding;
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and a specific character encoding.
        /// </summary>
        /// <param name="input">Input stream</param>
        /// <param name="encoding">The character encoding object used to decode strings from stream</param>
        protected BinaryReaderBase(IStreamAdapter input, Encoding encoding)
        {
            ArgumentAssert.IsNotNull(input, "input");
            ArgumentAssert.IsNotNull(encoding, "encoding");
            if (!input.CanRead)
            {
                throw new IOException(Messages.Exception_CantReadFromStream);
            }

            _inputStream = input;
            _encoding    = encoding;
        }
示例#15
0
		protected BinaryWriterBase(IStreamAdapter output, Encoding encoding)
        {
            ArgumentAssert.IsNotNull(output, "output");
            ArgumentAssert.IsNotNull(encoding, "encoding");
            if (!output.CanWrite)
            {
                throw new IOException(Messages.Exception_CantWriteToStream);
            }

            _outputStream = output;
            _encoding = encoding;
        }
        protected BinaryWriterBase(IStreamAdapter output, Encoding encoding)
        {
            ArgumentAssert.IsNotNull(output, "output");
            ArgumentAssert.IsNotNull(encoding, "encoding");
            if (!output.CanWrite)
            {
                throw new IOException(Messages.Exception_CantWriteToStream);
            }

            _outputStream = output;
            _encoding     = encoding;
        }
示例#17
0
        private IStreamReader GetStreamReader <T>(string streamName, IStreamAdapter streamAdapter, bool createIfNecessary)
        {
            var streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                if (createIfNecessary)
                {
                    streamReader = new StreamReader <T>(streamName, streamAdapter);
                    this.streamReaders.Add(streamReader);
                }
                else
                {
                    throw new ArgumentException("No stream reader exists for the stream binding.");
                }
            }

            return(streamReader);
        }
示例#18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamSource"/> class.
        /// </summary>
        /// <param name="partitionViewModel">The partition that is the stream's data source.</param>
        /// <param name="streamReaderType">The type of stream reader that should be used to read data from the store.</param>
        /// <param name="streamName">The name of the stream.</param>
        /// <param name="streamMetadata">The metadata for the stream.</param>
        /// <param name="streamAdapter">The stream adapter to use when reading stream data.</param>
        /// <param name="summarizer">The summarizer to use when reading the stream.</param>
        public StreamSource(
            PartitionViewModel partitionViewModel,
            Type streamReaderType,
            string streamName,
            IStreamMetadata streamMetadata,
            IStreamAdapter streamAdapter,
            ISummarizer summarizer)
        {
            this.StoreName        = partitionViewModel.StoreName;
            this.StorePath        = partitionViewModel.StorePath;
            this.StreamReaderType = streamReaderType;
            this.StreamName       = streamName;
            this.StreamMetadata   = streamMetadata;
            this.StreamAdapter    = streamAdapter;
            this.Summarizer       = summarizer;
            this.IsLive           = partitionViewModel.IsLivePartition;

            partitionViewModel.PropertyChanged += this.PartitionPropertyChanged;
        }
示例#19
0
        /// <summary>
        /// Creates a stream member adapter based on a specified visualizer metadata.  Any existing stream
        /// adapter in the given visualizer metadata will be preserved within the stream member adapter.
        /// </summary>
        /// <param name="visualizerMetadata">The visualizer metadata.</param>
        /// <param name="sourceDataType">The type of the stream's source data.</param>
        /// <returns>A new visualizer metadata containing a stream member adapter.</returns>
        internal static VisualizerMetadata CreateStreamMemberAdapter(VisualizerMetadata visualizerMetadata, Type sourceDataType)
        {
            // Clone the metadata
            var metadataClone = visualizerMetadata.DeepClone();

            // If the visualizer metadata already contains a stream adapter, create a stream member adapter that
            // encapsulates it, otherwise create a stream member adapter that adapts directly from the message
            // type to the member type.
            if (visualizerMetadata.StreamAdapterType != null)
            {
                IStreamAdapter existingStreamAdapter = (IStreamAdapter)Activator.CreateInstance(visualizerMetadata.StreamAdapterType);
                metadataClone.StreamAdapterType = typeof(StreamMemberAdapter <, , ,>).MakeGenericType(sourceDataType, existingStreamAdapter.SourceType, visualizerMetadata.StreamAdapterType, existingStreamAdapter.DestinationType);
            }
            else
            {
                metadataClone.StreamAdapterType = typeof(StreamMemberAdapter <,>).MakeGenericType(sourceDataType, metadataClone.DataType);
            }

            return(metadataClone);
        }
        /// <summary>
        /// Serializes an command and graph of internal objects to the provided stream.
        /// </summary>
        /// <param name="stream">The stream where the command puts the serialized data.</param>
        /// <exception cref="IOException"/>
        internal protected override void Serialize(IStreamAdapter stream)
        {
            IBinaryWriter writer = Connection.FormatterFactory.CreateWriter(stream);

            // send command id and version information
            CommandInfo.Serialize(writer);

            // serialize request body to temp. buffer to get command body length
            MemoryStream  buffer       = new MemoryStream();
            IBinaryWriter bufferWriter = Connection.FormatterFactory.CreateWriter(new StreamAdapter(buffer));

            SerializeRequest(bufferWriter);
            // send body length first
            int length = (int)buffer.Length;

            writer.Write(length);
            // send buffer content
            buffer.Position = 0;
            stream.WriteBytes(buffer.ToArray(), length);
        }
示例#21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamSource"/> class.
        /// </summary>
        /// <param name="partitionViewModel">The partition that is the stream's data source.</param>
        /// <param name="streamReaderType">The type of stream reader that should be used to read data from the store.</param>
        /// <param name="streamName">The name of the stream.</param>
        /// <param name="streamMetadata">The metadata for the stream.</param>
        /// <param name="streamAdapter">The stream adapter to use when reading stream data.</param>
        /// <param name="summarizer">The summarizer to use when reading the stream.</param>
        /// <param name="allocator">The allocator to use when reading data.</param>
        /// <param name="deallocator">The deallocator to use when reading data.</param>
        public StreamSource(
            PartitionViewModel partitionViewModel,
            Type streamReaderType,
            string streamName,
            IStreamMetadata streamMetadata,
            IStreamAdapter streamAdapter,
            ISummarizer summarizer,
            Func <dynamic> allocator,
            Action <dynamic> deallocator)
        {
            this.StoreName        = partitionViewModel.StoreName;
            this.StorePath        = partitionViewModel.StorePath;
            this.StreamReaderType = streamReaderType;
            this.StreamName       = streamName;
            this.StreamMetadata   = streamMetadata;
            this.StreamAdapter    = streamAdapter;
            this.Summarizer       = summarizer;
            this.IsLive           = partitionViewModel.IsLivePartition;
            this.Allocator        = allocator;
            this.Deallocator      = deallocator;

            partitionViewModel.PropertyChanged += this.OnPartitionViewModelPropertyChanged;
        }
示例#22
0
 	protected internal override void Serialize(IStreamAdapter stream)
     {
         IBinaryWriter writer = Connection.FormatterFactory.CreateWriter(stream);
         CommandInfo.Serialize(writer);
     }
示例#23
0
		protected internal override void Deserialize(IStreamAdapter stream)
        {
            // do nothing
        }
 public XmlWriterMock(IStreamAdapter output) : base(output, _defaultEncoding)
 {
 }
		public XmlWriterMock(IStreamAdapter output, Encoding encoding): base(output, encoding)
        {
        }
 public XmlWriterMock(IStreamAdapter output, Encoding encoding) : base(output, encoding)
 {
 }
		public XmlReaderMock(IStreamAdapter input, Encoding encoding): base(input, encoding)
        {
        } 
示例#28
0
        protected internal override void Serialize(IStreamAdapter stream)
        {
            IBinaryWriter writer = Connection.FormatterFactory.CreateWriter(stream);

            CommandInfo.Serialize(writer);
        }
 public IBinaryReader CreateReader(IStreamAdapter stream)
 {
     return(new XmlReaderMock(stream));
 }
示例#30
0
 protected internal override void Deserialize(IStreamAdapter stream)
 {
     // do nothing
 }
		public BigEndianBinaryWriter(IStreamAdapter output): base(output)
		{
		}
示例#32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and a specific character encoding.
 /// </summary>
 /// <param name="input">Input stream</param>
 /// <param name="encoding">The character encoding object used to decode strings from stream</param>
 public BigEndianBinaryReader(IStreamAdapter input, Encoding encoding) : base(input, encoding)
 {
 }
示例#33
0
        private const int MAX_LENGTH = 8 * 1024 * 1024;         // 8MB (hardcoded in sphinxd)
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="BigEndianBinaryReader"/> class based on the supplied stream and using default encoding <see cref="UTF8Encoding"/>.
        /// </summary>
        /// <param name="input">Input stream</param>
        public BigEndianBinaryReader(IStreamAdapter input) : base(input)
        {
        }
		public XmlWriterMock(IStreamAdapter output): base(output, _defaultEncoding)
        {
        }
示例#35
0
 public object Deserialize(IStreamAdapter streamAdapter)
 {
     return _serializer.Deserialize(streamAdapter.Stream);
 }
 public IBinaryReader CreateReader(IStreamAdapter stream)
 {
     return new XmlReaderMock(stream);
 }
示例#37
0
 public void Serialize(IStreamAdapter streamAdapter, object argument)
 {
     _serializer.Serialize(streamAdapter.Stream, argument);
 }
		protected Stream GetStream(IStreamAdapter adapter)
		{
			PrivateObject po = new PrivateObject(adapter);
			StreamAdapter_Accessor accessor = new StreamAdapter_Accessor(po);
			return accessor.Stream;
		}         
示例#39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and using default encoding <see cref="UTF8Encoding"/>.
 /// </summary>
 /// <param name="input">Input stream</param>
 protected BinaryReaderBase(IStreamAdapter input) : this(input, _defaultEncoding)
 {
 }
		private const int MAX_LENGTH = 8 * 1024 * 1024; // 8MB (hardcoded in sphinxd)
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="BigEndianBinaryReader"/> class based on the supplied stream and using default encoding <see cref="UTF8Encoding"/>.
		/// </summary>
		/// <param name="input">Input stream</param>
		public BigEndianBinaryReader(IStreamAdapter input): base(input)
		{
		}
		public XmlReaderMock(IStreamAdapter input): base(input, _defaultEncoding)
        {
        }
 public IBinaryWriter CreateWriter(IStreamAdapter stream)
 {
     return(new XmlWriterMock(stream));
 }
示例#43
0
		protected BinaryWriterBase(IStreamAdapter output): this(output, _defaultEncoding)
        {
        }
示例#44
0
 public IBinaryWriter CreateWriter(IStreamAdapter stream)
 {
     return(new ArrayListWriterMock(_list));
 }
示例#45
0
        /// <summary>
        /// Deserializes the Sphinx server response data on the provided stream and reconstitutes the graph of objects.
        /// </summary>
        /// <param name="stream">The stream that contains the data to deserialize.</param>
		internal protected abstract void Deserialize(IStreamAdapter stream);
示例#46
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamBinding"/> class.
 /// </summary>
 /// <param name="source">An existing stream binding to clone.</param>
 /// <param name="storeName">The store name.</param>
 /// <param name="storePath">The store path.</param>
 public StreamBinding(StreamBinding source, string storeName, string storePath)
     : this(source.StreamName, source.PartitionName, storeName, storePath, source.SimpleReaderType, source.StreamAdapterType, source.SummarizerType, source.SummarizerArgs)
 {
     this.streamAdapter = source.streamAdapter;
     this.summarizer    = source.summarizer;
 }
		public BigEndianBinaryWriter(IStreamAdapter output, Encoding encoding): base(output, encoding)
		{
		}
示例#48
0
 public void Serialize(IStreamAdapter streamAdapter, object messageDTO)
 {
     _serializer.Serialize(streamAdapter.Stream, messageDTO);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamValuePublisher{TSource, TDestination}"/> class.
 /// </summary>
 /// <param name="streamAdapter">The stream adapter that will convert the incoming data to the data that the targets require.</param>
 public StreamValuePublisher(IStreamAdapter streamAdapter)
 {
     this.targets       = new Dictionary <Guid, Action <bool, TDestination, DateTime, DateTime> >();
     this.StreamAdapter = (streamAdapter ?? new PassthroughAdapter <TDestination>()) as StreamAdapter <TSource, TDestination>;
 }
        public IBinaryReader CreateReader(IStreamAdapter stream)
        {
			return new ArrayListReaderMock(_list);
        }
		public IBinaryWriter CreateWriter(IStreamAdapter stream)
        {
            return new XmlWriterMock(stream);
        }
		public IBinaryWriter CreateWriter(IStreamAdapter stream)
        {
			return new ArrayListWriterMock(_list);
        }
示例#53
0
 public BinaryMessageSerializer(IStreamAdapter streamAdapter, ISerializeAdapter serializeAdapter)
 {
     _stream = streamAdapter;
      _serializer = serializeAdapter;
 }
示例#54
0
 public IBinaryReader CreateReader(IStreamAdapter stream)
 {
     return(new ArrayListReaderMock(_list));
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and a specific character encoding.
		/// </summary>
		/// <param name="input">Input stream</param>
		/// <param name="encoding">The character encoding object used to decode strings from stream</param>
		public BigEndianBinaryReader(IStreamAdapter input, Encoding encoding): base(input, encoding)
		{
		}
示例#56
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryReaderBase"/> class based on the supplied stream and using default encoding <see cref="UTF8Encoding"/>.
        /// </summary>
        /// <param name="input">Input stream</param>
		protected BinaryReaderBase(IStreamAdapter input): this(input, _defaultEncoding)
        {
        }