コード例 #1
0
ファイル: Epoch.cs プロジェクト: polytronicgr/symphony-core
        /// <summary>
        /// Informs this Epoch that stimulus data was output by the Symphony.Core output pipeline.
        /// </summary>
        /// <param name="device">ExternalDevice that was the target of the output data</param>
        /// <param name="outputTime">Approximate time the data was written "to the wire"</param>
        /// <param name="duration">Duration of the output data segment</param>
        /// <param name="configuration">Pipeline node configuration(s) for nodes that processed the outgoing data</param>
        public virtual void DidOutputData(IExternalDevice device, DateTimeOffset outputTime, TimeSpan duration, IEnumerable <IPipelineNodeConfiguration> configuration)
        {
            //virtual so that we can mock it

            if (outputTime < StartTime)
            {
                throw new ArgumentException("Data output time must be after Epoch start time", "outputTime");
            }

            if (Stimuli.ContainsKey(device))
            {
                Stimuli[device].DidOutputData(duration, configuration);
            }
        }
コード例 #2
0
ファイル: Epoch.cs プロジェクト: polytronicgr/symphony-core
        /// <summary>
        /// Pulls output data from the given device of the given duration.
        /// <para>If the given device has an associated Stimulus in this.Stimuli,
        /// the data is pulled from that Stimulus. If there is no associated Stimulus,
        /// data is generated according to this.Background[dev].</para>
        /// </summary>
        /// <param name="dev">Output device requesting data</param>
        /// <param name="blockDuration">Requested duration of the IOutputData</param>
        /// <returns>IOutputData intsance with duration less than or equal to blockDuration</returns>
        public IOutputData PullOutputData(IExternalDevice dev, TimeSpan blockDuration)
        {
            if (Stimuli.ContainsKey(dev))
            {
                var blockIter = StimulusDataEnumerators.GetOrAdd(dev,
                                                                 (d) => Stimuli[d].DataBlocks(blockDuration).GetEnumerator()
                                                                 );

                IOutputData stimData = null;
                while (stimData == null || stimData.Duration < blockDuration)
                {
                    if (!blockIter.MoveNext())
                    {
                        break;
                    }

                    stimData =
                        stimData == null ? blockIter.Current : stimData.Concat(blockIter.Current);
                }

                if (stimData == null)
                {
                    return(BackgroundDataForDevice(dev, blockDuration));
                }

                if (stimData.Duration < blockDuration)
                {
                    var remainingDuration = blockDuration - stimData.Duration;
                    stimData = stimData.Concat(BackgroundDataForDevice(dev, remainingDuration));
                }

                return(stimData);
            }


            log.DebugFormat("Will send background for device {0} ({1})", dev.Name, blockDuration);
            return(BackgroundDataForDevice(dev, blockDuration));
        }