Пример #1
0
        public IEnumerable <IExtractionResult <FormatObject> > Extract(FormatObject lastExtracted = default(FormatObject))
        {
            if (!(TempDownloadLocation.Exists))
            {
                TempDownloadLocation.Create();
            }

            Aggregator.Initialize();

            IEnumerable <FormatObject> firstFormats;

            if (lastExtracted.Equals(default(FormatObject)))
            {
                firstFormats = Source.GetPossibleFormatObjects(Source.FirstDateTimeOffset);
            }
            else
            {
                firstFormats = new [] { lastExtracted };
            }

            foreach (var format in firstFormats)
            {
                var aggregatorResult = Aggregator.DownloadFirst(format);

                foreach (var result in ProcessResult(aggregatorResult))
                {
                    yield return(result);
                }

                lastExtracted = aggregatorResult.CurrentPosition;
            }

            do
            {
                var aggregatorResult = Aggregator.DownloadNext(lastExtracted);

                foreach (var result in ProcessResult(aggregatorResult))
                {
                    yield return(result);
                }

                lastExtracted = aggregatorResult.CurrentPosition;
            }while (Source.GetUpperBoundExclusive(lastExtracted) < DateTimeOffset.Now);
        }
Пример #2
0
        public IEnumerable <IExtractionResult <FormatObject> > Extract(FormatObject lastExtracted)
        {
            var lastAttemptedFormat = lastExtracted;

            foreach (Pair pair in Source.GetDiscriminatingFilePairs())
            {
                if (!(TempDownloadLocation.Exists))
                {
                    TempDownloadLocation.Create();
                }

                DateTimeOffset?dateUpperBoundExclusive = null;
                bool           isDownloadSuccess       = true;

                while ((dateUpperBoundExclusive ?? DateTimeOffset.MinValue) < DateTimeOffset.Now)
                {
                    TryDownloadResult result = Downloader.TryDownload(lastAttemptedFormat);

                    var previous = dateUpperBoundExclusive;
                    if (previous == result.UpperBoundExclusive)
                    {
                        // downloader caught in a loop
                        break;
                    }

                    dateUpperBoundExclusive = result.UpperBoundExclusive;
                    isDownloadSuccess       = result.IsSuccess;
                    lastAttemptedFormat     = result.FormatObject;

                    if (result.IsSuccess)
                    {
                        yield return(new FileNameExtractionResult()
                        {
                            FileFullName = result.DestinationFile.FullName,
                            Pair = pair,
                            CurrentPosition = result.FormatObject,
                            IsSuccess = result.IsSuccess
                        });
                    }
                }
            }
        }