/// 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); } }