コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSegment"/> class.
        /// Allow specifying an absolutely aligned (to the nearest minute) file segment.
        /// Implies `FileDateBehavior.Required`.
        /// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
        /// </summary>
        public FileSegment(
            FileInfo source,
            TimeAlignment alignment,
            IAudioUtility utility         = null,
            FileDateBehavior dateBehavior = FileDateBehavior.Try)
        {
            Contract.Requires(source != null);
            if (alignment != TimeAlignment.None)
            {
                Contract.Requires(
                    dateBehavior == FileDateBehavior.Required,
                    "If TimeAlignment is required, a date must be required in the filename");
            }

            this.dateBehavior = dateBehavior;
            this.Source       = source;
            this.Alignment    = alignment;

            var fileDate = this.ParseDate(null);

            var info = (utility ?? DefaultMasterAudioUtility).Info(source);

            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);

            this.SourceMetadata = new SourceMetadata(info.Duration.Value, info.SampleRate.Value, basename, fileDate);

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSegment"/> class.
        /// Use this constructor if you know all the information about a segment beforehand (except for the date it was created).
        /// </summary>
        public FileSegment(FileInfo source, int sampleRate, TimeSpan duration, FileDateBehavior dateBehavior)
        {
            // when we should know everything about the file, we don't want to try and parse the date again...
            // we either picked it up the first time or it is not available
            this.dateBehavior = dateBehavior;
            this.Source       = source;

            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);
            var fileDate = this.ParseDate(null);

            this.SourceMetadata = new SourceMetadata(duration, sampleRate, basename, fileDate);

            this.Alignment = TimeAlignment.None;

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }
コード例 #3
0
        public FileSegment(
            FileInfo source,
            DateTimeOffset startDate,
            IAudioUtility utility = null)
        {
            Contract.Requires(source != null);

            this.dateBehavior = FileDateBehavior.Required;
            this.Source       = source;
            this.Alignment    = TimeAlignment.None;

            var fileDate = this.ParseDate(startDate);

            var info     = (utility ?? DefaultMasterAudioUtility).Info(source);
            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);

            this.SourceMetadata = new SourceMetadata(info.Duration.Value, info.SampleRate.Value, basename, fileDate);

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }