/// <summary>
        ///     Read telemetry samples from the stream for the given list of dataformat parameters and handle the data by the
        ///     TelemetryDataHandler delegate
        /// </summary>
        /// <param name="parameterIdentifiers">List of dataformat parameter identifiers</param>
        /// <param name="handler">Use this for the streamed data handling, updating etc.</param>
        /// <returns>Pipeline representing the network resource streaming messages to the inputs.</returns>
        public IStreamPipeline ReadTSamples(List <string> parameterIdentifiers, TelemetrySamplesHandler handler)
        {
            var pipeline = StreamPipelineBuilder.Into(streamId => Read(streamId, handler));

            if (!pipeline.WaitUntilConnected(connectionTimeoutInSeconds, CancellationToken.None))
            {
                throw new Exception("Couldn't connect");
            }

            return(pipeline);
        }
        private IStreamInput Read(string streamId, TelemetrySamplesHandler handler)
        {
            var input = new SessionTelemetryDataInput(streamId, DataFormatClient);

            input.SamplesInput.AutoBindFeeds((s, e) => // Take the input and bind feed to an event handler
            {
                handler(e.Data);
            });

            input.StreamFinished += (sender, e) => Trace.WriteLine("Finished"); // Handle the steam finished event

            return(input);
        }
        /// <summary>
        ///     Read telemetry samples from the stream for the given dataformat parameter and handle the data by the
        ///     TelemetryDataHandler delegate
        ///     and link to another output, using the <paramref name="writer" /> and the <paramref name="outputFeedNames" />
        /// </summary>
        /// <param name="parameterIdentifier">The dataformat parameter identifier</param>
        /// <param name="handler">Use this for the streamed data handling, updating etc.</param>
        /// <param name="writer">Writer object used for writing the streamed input to another output.</param>
        /// <param name="outputFeedNames">
        ///     List of output feed names where the streamed input will be linked to, using the
        ///     <paramref name="writer" />
        /// </param>
        /// <returns>Pipeline representing the network resource streaming messages to the inputs.</returns>
        public IStreamPipeline ReadAndLinkTSamples(string parameterIdentifier, TelemetrySamplesHandler handler,
                                                   Writer writer, List <string> outputFeedNames)
        {
            var pipeline = StreamPipelineBuilder.Into(streamId =>
                                                      ReadAndLinkOutput(streamId, parameterIdentifier, writer, outputFeedNames, handler));

            if (!pipeline.WaitUntilConnected(connectionTimeoutInSeconds, CancellationToken.None))
            {
                throw new Exception("Couldn't connect");
            }

            return(pipeline);
        }
        private IStreamInput ReadAndLinkOutput(
            string streamId,
            string parameterIdentifier,
            Writer writer,
            string outputFeedName,
            TelemetrySamplesHandler handler)
        {
            var input = new SessionTelemetryDataInput(streamId, DataFormatClient);

            Debug.WriteLine($"Linking stream {streamId}");
            // automatically propagate session metadata and lifecycle
            input.LinkToOutput(writer.SessionOutput, identifier => identifier + "_" + writer.TopicName);

            // react to data
            input.SamplesInput.GetFeed(outputFeedName).DataReceived += (s, e) => { handler(e.Data); };

            input.StreamFinished += HandleStreamFinished;
            return(input);
        }