/// Execute action public override object Execute() { string fromExpanded = Context.TransformStr(From, Transform); string toExpanded = Context.TransformStr(To, Transform); var nf = new FileNameOnlyFilter(Syntax, Context.TransformStr(Filter, Transform)); var df = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add); object ret = null; Uri uri; if (Uri.TryCreate(fromExpanded, UriKind.Absolute, out uri)) { if (uri.IsFile) { fromExpanded = uri.LocalPath; uri = null; } } if (uri != null) { FileInfo to; toExpanded = Download.UrlToLocalFileName(fromExpanded, toExpanded); to = new FileInfo(toExpanded); VerboseMessage("Copying from URI {0} to {1}", fromExpanded, to); ret = downloadSingleFile(nf, uri, to); } else { DirectoryInfo di = new DirectoryInfo(fromExpanded); if (fromExpanded.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || fromExpanded.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal) || di.Exists) { VerboseMessage("Copying a directory {0} to {1}", di, toExpanded); ret = copy(di, di, new DirectoryInfo(toExpanded), nf, df); } else { FileInfo fr = new FileInfo(fromExpanded); FileInfo to; if (toExpanded.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || toExpanded.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal) || new DirectoryInfo(toExpanded).Exists) { to = new FileInfo(Path.Combine(new DirectoryInfo(toExpanded).FullName, fr.Name)); } else { to = new FileInfo(toExpanded); } VerboseMessage("Copying a single file {0} to {1}", fr, to); ret = copySingleFile(nf, fr, to); } } if (ReturnValue.IsBreak(ret)) { return(null); } ReturnValue.RethrowIfException(ret); return(ret); }
/// Execute action public override object Execute() { string fromExpanded = Context.TransformStr(From, Transform); string toExpanded = Context.TransformStr(To, Transform); var nf = new FileNameOnlyFilter(Syntax, Context.TransformStr(Filter, Transform)); var df = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add); object ret = null; Uri uri; if (Uri.TryCreate(fromExpanded, UriKind.Absolute, out uri)) if (uri.IsFile) { fromExpanded=uri.LocalPath; uri=null; } if (uri!=null) { FileInfo to; toExpanded= Download.UrlToLocalFileName(fromExpanded,toExpanded); to = new FileInfo(toExpanded); VerboseMessage("Copying from URI {0} to {1}", fromExpanded, to); ret=downloadSingleFile(nf,uri,to); } else { DirectoryInfo di = new DirectoryInfo(fromExpanded); if (fromExpanded.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || fromExpanded.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal) || di.Exists) { VerboseMessage("Copying a directory {0} to {1}", di, toExpanded); ret = copy(di, di, new DirectoryInfo(toExpanded), nf, df); } else { FileInfo fr = new FileInfo(fromExpanded); FileInfo to; if (toExpanded.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) || toExpanded.EndsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal) || new DirectoryInfo(toExpanded).Exists) { to = new FileInfo(Path.Combine(new DirectoryInfo(toExpanded).FullName, fr.Name)); } else { to = new FileInfo(toExpanded); } VerboseMessage("Copying a single file {0} to {1}", fr, to); ret = copySingleFile(nf, fr, to); } } if (ReturnValue.IsBreak(ret)) return null; ReturnValue.RethrowIfException(ret); return ret; }
/// Execute action public override object Execute() { string f = Context.TransformStr(From, Transform); DirectoryInfo src; IStringFilter nf, df; string trg = Context.TransformStr(To, Transform); if (File.Exists(f)) { src = new DirectoryInfo(new FileInfo(f).DirectoryName); nf = new SelfIgnoreFilenameOnlyFilter(trg, FilterSyntax.Pattern, Regex.Escape(Path.GetFileName(f))); df = new StringFilter(null); } else { src = new DirectoryInfo(f); nf = new SelfIgnoreFilenameOnlyFilter(trg, Syntax, Context.TransformStr(Filter, Transform)); df = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add); } if (!src.Exists) { throw new DirectoryNotFoundException(string.Format("Directory {0} does not exist", src)); } bool deleteTrg = false; Stream str = null; var outTo = Context.TransformStr(OutTo, Transform); try { if (outTo != null) { str = new MemoryStream(); } else { str = Context.CreateStream(trg); deleteTrg = true; } var ret = createZip(str, src.FullName, nf, df); if (trg != null && outTo != null) { deleteTrg = true; using (var ctx2 = Context.CreateStream(trg)) ((MemoryStream)str).WriteTo(ctx2); } if (outTo != null) { Context.OutTo(outTo, ((MemoryStream)str).ToArray()); } deleteTrg = false; if (ReturnValue.IsBreak(ret)) { return(null); } ReturnValue.RethrowIfException(ret); return(ret); } finally { if (str != null) { str.Dispose(); } if (deleteTrg) { File.Delete(trg); } } }
/// Execute action public override object Execute() { string f = Context.TransformStr(From, Transform); DirectoryInfo src; IStringFilter nf, df; string trg = Context.TransformStr(To, Transform); if (File.Exists(f)) { src = new DirectoryInfo(new FileInfo(f).DirectoryName); nf = new SelfIgnoreFilenameOnlyFilter(trg, FilterSyntax.Pattern, Regex.Escape(Path.GetFileName(f))); df = new StringFilter(null); } else { src = new DirectoryInfo(f); nf = new SelfIgnoreFilenameOnlyFilter(trg, Syntax, Context.TransformStr(Filter, Transform)); df = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add); } if (!src.Exists) throw new DirectoryNotFoundException(string.Format("Directory {0} does not exist", src)); bool deleteTrg = false; Stream str = null; var outTo = Context.TransformStr(OutTo, Transform); try { if (outTo != null) str = new MemoryStream(); else { str = Context.CreateStream(trg); deleteTrg = true; } var ret = createZip(str, src.FullName, nf, df); if (trg != null && outTo != null) { deleteTrg = true; using (var ctx2 = Context.CreateStream(trg)) ((MemoryStream)str).WriteTo(ctx2); } if (outTo != null) Context.OutTo(outTo, ((MemoryStream)str).ToArray()); deleteTrg = false; if (ReturnValue.IsBreak(ret)) return null; ReturnValue.RethrowIfException(ret); return ret; } finally { if (str != null) str.Dispose(); if (deleteTrg) File.Delete(trg); } }