Example #1
0
        private static PathAndTrackNumber GetNextAvailableFile(IOptionsService optionsService, string folder, DateTime dt)
        {
            PathAndTrackNumber result = null;
            var path = Directory.Exists(folder) ? null : GenerateCandidateFilePath(folder, dt, 1);

            if (path != null)
            {
                result = new PathAndTrackNumber {
                    FilePath = path, TrackNumber = 1
                };
            }
            else
            {
                int maxFileCount = optionsService.Options.MaxRecordingsInOneFolder;

                for (int increment = 1; increment <= maxFileCount && result == null; ++increment)
                {
                    string candidateFile = GenerateCandidateFilePath(folder, dt, increment);
                    if (!File.Exists(candidateFile))
                    {
                        result = new PathAndTrackNumber {
                            FilePath = candidateFile, TrackNumber = increment
                        };
                    }
                }
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets the full path of the next recording file (non-existent)
        /// </summary>
        /// <param name="optionsService">Options service</param>
        /// <param name="dt">Recording date</param>
        /// <param name="commandLineIdentifier">identifier passed on commandline to differentiate settings and folders</param>
        /// <returns>Candidate path</returns>
        public RecordingCandidate GetRecordingFileCandidate(
            IOptionsService optionsService,
            DateTime dt,
            string commandLineIdentifier)
        {
            var destFolder = FileUtils.GetDestinationFolder(dt, commandLineIdentifier, optionsService.Options.DestinationFolder);
            PathAndTrackNumber finalPathAndTrack = GetNextAvailableFile(optionsService, destFolder, dt);

            var result = new RecordingCandidate
            {
                RecordingDate = dt,
                TrackNumber   = finalPathAndTrack.TrackNumber,
                TempPath      = GetTempRecordingFile(),
                FinalPath     = finalPathAndTrack.FilePath
            };

            Log.Logger.Information("New candidate = {@Candidate}", result);
            return(result);
        }