Example #1
0
        // ------ Data Subscriber Methods ------

        // Creates and starts a data subscriber using the connection information supplied by the user in ConnectionUri.
        // Subscribers created through this method should also be released by the ReleaseDataSubscriber method.
        private DataSubscriber CreateDataSubscriber()
        {
            DataSubscriber subscriber = new DataSubscriber();
            int            index      = ConnectionUri.IndexOf(URI_SEPARATOR);
            string         server     = (index >= 0) ? ConnectionUri.Substring(0, index) : ConnectionUri;

            subscriber.StatusMessage         += DataSubscriber_StatusMessage;
            subscriber.ProcessException      += DataSubscriber_ProcessException;
            subscriber.ConnectionEstablished += DataSubscriber_ConnectionEstablished;
            subscriber.ConnectionTerminated  += DataSubscriber_ConnectionTerminated;
            subscriber.MetaDataReceived      += DataSubscriber_MetaDataReceived;
            subscriber.DataStartTime         += DataSubscriber_DataStartTime;
            subscriber.NewMeasurements       += DataSubscriber_NewMeasurements;

            subscriber.ConnectionString = string.Format("server={0}; interface={1}; localCertificate={2}; remoteCertificate={3}; validPolicyErrors={4}; validChainFlags={5}", server, IPv6Enabled ? "::0" : "0.0.0.0", FilePath.GetAbsolutePath("Local.cer"), FilePath.GetAbsolutePath("Remote.cer"), ~SslPolicyErrors.None, ~X509ChainStatusFlags.NoError);
            subscriber.SecurityMode     = EnableEncryption ? SecurityMode.TLS : SecurityMode.None;

            if (!EnableCompression)
            {
                subscriber.OperationalModes = DataSubscriber.DefaultOperationalModes & ~OperationalModes.CompressPayloadData;
            }

            subscriber.ReceiveInternalMetadata = true;
            subscriber.ReceiveExternalMetadata = true;

            subscriber.Initialize();
            subscriber.Start();

            return(subscriber);
        }
Example #2
0
        // ------ Data Subscriber Methods ------

        // Creates and starts a data subscriber using the connection information supplied by the user in ConnectionUri.
        // Subscribers created through this method should also be released by the ReleaseDataSubscriber method.
        private DataSubscriber CreateDataSubscriber()
        {
            DataSubscriber subscriber = new DataSubscriber();
            int            index      = ConnectionUri.IndexOf(URI_SEPARATOR, StringComparison.Ordinal);
            string         server     = (index >= 0) ? ConnectionUri.Substring(0, index) : ConnectionUri;

            subscriber.StatusMessage         += DataSubscriber_StatusMessage;
            subscriber.ProcessException      += DataSubscriber_ProcessException;
            subscriber.ConnectionEstablished += DataSubscriber_ConnectionEstablished;
            subscriber.ConnectionTerminated  += DataSubscriber_ConnectionTerminated;
            subscriber.MetaDataReceived      += DataSubscriber_MetaDataReceived;
            subscriber.DataStartTime         += DataSubscriber_DataStartTime;
            subscriber.NewMeasurements       += DataSubscriber_NewMeasurements;

            subscriber.ConnectionString = $"server={server}; interface={(IPv6Enabled ? "::0" : "0.0.0.0")};{(UseZeroMQChannel ? " useZeroMQChannel=true;" : "")} localCertificate={FilePath.GetAbsolutePath("Local.cer")}; remoteCertificate={FilePath.GetAbsolutePath("Remote.cer")}; validPolicyErrors={~SslPolicyErrors.None}; validChainFlags={~X509ChainStatusFlags.NoError}";
            subscriber.SecurityMode     = EnableEncryption ? SecurityMode.TLS : SecurityMode.None;

            subscriber.OperationalModes = DataSubscriber.DefaultOperationalModes;
            subscriber.CompressionModes = CompressionModes.GZip;

            if (EnableCompression)
            {
                subscriber.OperationalModes |= OperationalModes.CompressPayloadData;

                bool usingUDP = false;

                if (index >= 0)
                {
                    usingUDP = ConnectionUri.Substring(index + URI_SEPARATOR.Length).ParseKeyValuePairs('&').ContainsKey("udp");
                }

                if (!usingUDP)
                {
                    subscriber.CompressionModes |= CompressionModes.TSSC; // TSSC mode requires TCP connection
                }
            }

            subscriber.ReceiveInternalMetadata = true;
            subscriber.ReceiveExternalMetadata = true;

            subscriber.Initialize();
            subscriber.Start();

            return(subscriber);
        }
Example #3
0
        /// <summary>
        /// Opens the stream and starts playback.
        /// </summary>
        /// <param name="songName">The name of the song to be played.</param>
        public void Play(string songName)
        {
            if (m_dataSubscriber != null && m_metadata != null)
            {
                UnsynchronizedSubscriptionInfo info;

                StringBuilder filterExpression = new StringBuilder();
                DataTable     deviceTable      = m_metadata.Tables["DeviceDetail"];
                DataTable     measurementTable = m_metadata.Tables["MeasurementDetail"];

                Dictionary <string, string> uriSettings;
                string dataChannel = null;
                int    uriIndex    = ConnectionUri.IndexOf(URI_SEPARATOR);

                m_channelIndexes = new ConcurrentDictionary <Guid, int>();
                m_sampleRate     = DEFAULT_SAMPLE_RATE;
                m_numChannels    = DEFAULT_NUM_CHANNELS;

                // Get sample rate from metadata.
                if (deviceTable != null)
                {
                    string sampleRate = deviceTable.Rows.Cast <DataRow>()
                                        .Single(row => row["Acronym"].ToNonNullString() == songName)["FramesPerSecond"].ToNonNullString();

                    if (!string.IsNullOrEmpty(sampleRate))
                    {
                        m_sampleRate = int.Parse(sampleRate);
                    }
                }

                // Get measurements from metadata.
                if (measurementTable != null)
                {
                    IEnumerable <DataRow> measurementRows = measurementTable.Rows.Cast <DataRow>()
                                                            .Where(row => row["DeviceAcronym"].ToNonNullString() == songName)
                                                            .Where(row => row["SignalAcronym"].ToNonNullString() == "ALOG" || row["SignalAcronym"].ToNonNullString() == "VPHM")
                                                            .Where(row => row["Enabled"].ToNonNullString().ParseBoolean())
                                                            .OrderBy(row => row["ID"].ToNonNullString());

                    m_numChannels = 0;

                    foreach (DataRow row in measurementRows)
                    {
                        Guid measurementID = Guid.Parse(row["SignalID"].ToNonNullString());

                        if (m_numChannels > 0)
                        {
                            filterExpression.Append(';');
                        }

                        filterExpression.Append(measurementID);
                        m_channelIndexes[measurementID] = m_numChannels;
                        m_numChannels++;
                    }
                }

                // Create UDP data channel if specified.
                if (uriIndex >= 0)
                {
                    uriSettings = ConnectionUri.Substring(uriIndex + URI_SEPARATOR.Length).ParseKeyValuePairs('&');

                    if (uriSettings.ContainsKey("udp"))
                    {
                        dataChannel = string.Format("dataChannel={{port={0}; interface={1}}}", uriSettings["udp"], IPv6Enabled ? "::0" : "0.0.0.0");
                    }
                }

                m_buffer       = new ConcurrentQueue <IMeasurement>();
                m_dumpTimer    = CreateDumpTimer();
                m_statTimer    = CreateStatTimer();
                m_waveProvider = new BufferedWaveProvider(new WaveFormat(m_sampleRate < MINIMUM_SAMPLE_RATE ? MINIMUM_SAMPLE_RATE : m_sampleRate, m_numChannels));
                m_wavePlayer   = CreateWavePlayer(m_waveProvider);
                m_waveProvider.DiscardOnBufferOverflow = true;

                info = new UnsynchronizedSubscriptionInfo(false)
                {
                    FilterExpression = filterExpression.ToString(),
                    ExtraConnectionStringParameters = dataChannel
                };

                m_statTimer.Start();
                m_wavePlayer.Play();
                m_dataSubscriber.UnsynchronizedSubscribe(info);
                m_timeoutTimer.Start();
                OnStateChanged(PlaybackState.Buffering);
            }
        }