public static IEnumerable <string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
        {
#if (DEBUG && TEST_HOOK)
            FaultInjectionPoint fip = new FaultInjectionPoint(FaultInjectionPoint.FIP_ThrowExceptionOnDirectory);
            string fiValue;

            if (fip.TryGetValue(out fiValue) && !String.IsNullOrEmpty(fiValue))
            {
                if (!fiValue.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    fiValue = fiValue + Path.DirectorySeparatorChar.ToString();
                }

                if (path.EndsWith(fiValue, StringComparison.OrdinalIgnoreCase))
                {
                    throw new Exception("test exception thrown because of FIP_ThrowExceptionOnDirectory is enabled");
                }
            }
#endif
#if DOTNET5_4
            return(Directory.EnumerateFileSystemEntries(path, searchPattern, searchOption));
#else
            return(EnumerateFileSystemEntries(path, searchPattern, searchOption, FilesOrDirectory.All));
#endif
        }
Пример #2
0
        public static void HandleFaultInjection(string relativePath, SingleObjectTransfer transfer)
        {
            FaultInjectionPoint fip = new FaultInjectionPoint(FaultInjectionPoint.FIP_ThrowExceptionAfterEnumerated);
            string    fiValue;
            string    filePath   = relativePath;
            CloudBlob sourceBlob = transfer.Source.Instance as CloudBlob;

            if (sourceBlob != null && sourceBlob.IsSnapshot)
            {
                filePath = Utils.AppendSnapShotTimeToFileName(filePath, sourceBlob.SnapshotTime);
            }

            if (fip.TryGetValue(out fiValue) &&
                string.Equals(fiValue, filePath, StringComparison.OrdinalIgnoreCase))
            {
                throw new TransferException(TransferErrorCode.Unknown, "test exception thrown because of ThrowExceptionAfterEnumerated is enabled", null);
            }
        }
        private IEnumerable <SingleObjectTransfer> AllTransfers(CancellationToken cancellationToken)
        {
            if (null == this.Journal)
            {
                // return all existing transfers in subTransfers
                foreach (var transfer in this.subTransfers.GetEnumerator())
                {
                    Utils.CheckCancellation(cancellationToken);
                    transfer.Context = this.Context;

                    this.UpdateTransfer(transfer);
                    yield return(transfer as SingleObjectTransfer);
                }
            }
            else
            {
                foreach (var transfer in this.Journal.ListSubTransfers())
                {
                    Utils.CheckCancellation(cancellationToken);
                    transfer.Context = this.Context;

                    this.UpdateTransfer(transfer);

                    this.subTransfers.AddTransfer(transfer, false);
                    yield return(transfer);
                }
            }

            while (true)
            {
                Utils.CheckCancellation(cancellationToken);

                Tuple <SingleObjectTransfer, TransferEntry> pair;
                try
                {
                    pair = this.shouldTransferQueue.DequeueResult();
                }
                catch (InvalidOperationException)
                {
                    // Task queue is empty and CompleteAdding. No more transfer to dequeue.
                    break;
                }
                catch (AggregateException aggregateException)
                {
                    // Unwrap the AggregateException.
                    ExceptionDispatchInfo.Capture(aggregateException.Flatten().InnerExceptions[0]).Throw();

                    break;
                }


                SingleObjectTransfer transfer = pair.Item1;
                TransferEntry        entry    = pair.Item2;

                lock (this.lockEnumerateContinuationToken)
                {
                    if (null != transfer)
                    {
                        this.subTransfers.AddTransfer(transfer);
                    }
                    this.enumerateContinuationToken = new SerializableListContinuationToken(entry.ContinuationToken);
                }

                if (null != transfer)
                {
                    this.Journal?.AddSubtransfer(transfer);
                }

                this.Journal?.UpdateJournalItem(this);

                if (null == transfer)
                {
                    continue;
                }

                try
                {
                    this.CreateParentDirectory(transfer);
                }
                catch (Exception ex)
                {
                    transfer.OnTransferFailed(ex);

                    // Don't keep failed transfers in memory if they can be persisted to a journal.
                    if (null != this.Journal)
                    {
                        this.subTransfers.RemoveTransfer(transfer);
                    }
                    continue;
                }

#if DEBUG
                FaultInjectionPoint fip = new FaultInjectionPoint(FaultInjectionPoint.FIP_ThrowExceptionAfterEnumerated);
                string    fiValue;
                string    filePath   = entry.RelativePath;
                CloudBlob sourceBlob = transfer.Source.Instance as CloudBlob;
                if (sourceBlob != null && sourceBlob.IsSnapshot)
                {
                    filePath = Utils.AppendSnapShotTimeToFileName(filePath, sourceBlob.SnapshotTime);
                }

                if (fip.TryGetValue(out fiValue) &&
                    string.Equals(fiValue, filePath, StringComparison.OrdinalIgnoreCase))
                {
                    throw new TransferException(TransferErrorCode.Unknown, "test exception thrown because of ThrowExceptionAfterEnumerated is enabled", null);
                }
#endif

                yield return(transfer);
            }
        }