Exemplo n.º 1
0
        private void EnumerateAndCopyFiles(
            SourceComputer computer, string location, string destination, string pattern, bool recurseIntoDirectories)
        {
            if (!location.EndsWith(Path.DirectorySeparatorChar + ""))
            {
                location += Path.DirectorySeparatorChar;
            }
            foreach (
                var file in
                EnumerateFiles(
                    location,
                    pattern,
                    recurseIntoDirectories
                            ? SearchOption.AllDirectories
                            : SearchOption.TopDirectoryOnly))
            {
                var path =
                    Path.Combine(destination, computer.Name, file.Substring(location.Length));
                var directoryInfo = new FileInfo(path).Directory;
                if (directoryInfo != null)
                {
                    Directory.CreateDirectory(directoryInfo.FullName);
                }
                else
                {
                    throw new DirectoryNotFoundException($"Couldn't find directory for path: {path}");
                }
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                CopyFile(
                    computer, file, path);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
Exemplo n.º 2
0
        private async Task CopyFile(
            SourceComputer SourceComputer, string file, string destination)
        {
            var progressPart = new Progress <FileProgress>(
                p => {
                lock (SourceComputer.FileSize) {
                    SourceComputer.FileSize[file] = p.Total;
                }
                lock (SourceComputer.FileProgress) {
                    SourceComputer.FileProgress[file] = p.Transfered;
                }
                SourceComputer.JobStatus = JobStatus.Copying;
                if (p.Transfered >= p.Total)
                {
                    SourceComputer.JobStatus = JobStatus.Success;
                }
                Dispatcher.InvokeAsync(RecomputeTotals);
            });

            try {
                await FileEx.CopyAsync(
                    file, destination, cancellationTokenSource.Token, progressPart);
            }
            catch (Win32Exception wex) {
                SourceComputer.JobStatus = JobStatus.Failed;
                SourceComputer.Exception = wex;
            }
            catch (OperationCanceledException) {
                if (SourceComputer.JobStatus == JobStatus.Copying ||
                    SourceComputer.JobStatus == JobStatus.Waiting)
                {
                    SourceComputer.JobStatus = JobStatus.Cancelled;
                }
                throw;
            }
        }
Exemplo n.º 3
0
 public virtual bool Visit(SourceComputer sourceComputer)
 {
     return(true);
 }