protected override bool Process(IInteraction parameters) { var dataSource = Closest <IIncomingBodiedInteraction> .From(parameters); FileInfo file = GetFileInfo(parameters); if (!file.FullName.StartsWith(this.ValidRootPath)) { return(FailForException(parameters, new Exception("File not in root path"))); } if (file.Exists && !MayOverwrite) { return(FailForException(parameters, new Exception("File already exists"))); } try { using (FileStream fileStream = file.OpenWrite()) { Task copyTask = dataSource.IncomingBody.CopyToAsync(fileStream); this.Meanwhile.TryProcess(parameters); copyTask.Wait(); } return((Successful == null) || Successful.TryProcess(parameters)); } catch (Exception ex) { return(FailForException(parameters, ex)); } }
protected override bool Process(IInteraction parameters) { IHttpInteraction httpInteraction = Closest <IHttpInteraction> .From(parameters); string contentType; if (this.ContentType.Length > 0) { contentType = this.ContentType; } else { contentType = Fallback <string> .From(parameters, "contenttype"); }; httpInteraction.SetContentType(contentType); if (this.SendLength) { long length = Fallback <long> .From(parameters, "contentlength"); httpInteraction.SetContentLength(length); } httpInteraction.PurgeBuffer(); return(WithBranch.TryProcess(parameters)); }
protected override bool Process(IInteraction parameters) { var dataSink = Closest <IOutgoingBodiedInteraction> .From(parameters); FileInfo file = GetFileInfo(parameters); if (!file.FullName.StartsWith(this.ValidRootPath)) { return(FailForException(parameters, new Exception("File not in root path"))); } IInteraction fileParameters = new SimpleInteraction( parameters, "contentlength", file.Length); if (!this.Header.TryProcess(fileParameters)) { return(FailForException(fileParameters, new Exception("Header failed"))); } try { using (FileStream fileStream = file.OpenRead()) { Task copyTask = fileStream.CopyToAsync(dataSink.OutgoingBody); Meanwhile.TryProcess(fileParameters); copyTask.Wait(); } return((Successful == null) || Successful.TryProcess(fileParameters)); } catch (Exception ex) { return(FailForException(fileParameters, ex)); } }
protected override bool Process(IInteraction parameters) { var signal = Closest <ShellSignalInteraction> .From(parameters); if (signal.IsKill) { shellProcess.Dispose(); } else { shellProcess = SystemProcess.Start(signal.ProcessInfo); shellProcess.BeginOutputReadLine(); shellProcess.OutputDataReceived += ShellProcess_OutputDataReceived; } return(true); }