コード例 #1
0
 public override ActionBase CreateFromForm()
 {
     return(new CreateZipFileAction
     {
         OverriddenTargetDirectory = PathEx.GetDirectoryName(this.txtFileName.Text),
         FileName = AH.CoalesceStr(PathEx.GetFileName(this.txtFileName.Text), "archive.zip")
     });
 }
コード例 #2
0
        protected override string ProcessRemoteCommand(string name, string[] args)
        {
            var request = (HttpWebRequest)WebRequest.Create(this.Url);

            request.Method = this.HttpMethod;

            request.ContentType = AH.CoalesceStr(this.ContentType, "application/x-www-form-urlencoded");

            this.LogDebug("Request Content-Type: " + request.ContentType);

            if (this.LogRequestData)
            {
                var buffer = new StringBuilder();
                buffer.Append("Request content: ");

                if (!string.IsNullOrEmpty(this.PostData))
                {
                    buffer.Append(this.PostData);
                }
                else if (this.FormData != null && this.FormData.Count > 0)
                {
                    bool first = true;
                    foreach (var field in this.FormData)
                    {
                        if (!first)
                        {
                            buffer.Append('&');
                        }
                        else
                        {
                            first = false;
                        }

                        buffer.Append(Uri.EscapeDataString(field.Key));
                        buffer.Append('=');
                        buffer.Append(Uri.EscapeDataString(field.Value));
                    }
                }

                this.LogDebug(buffer.ToString());
            }

            if (!string.IsNullOrEmpty(this.PostData))
            {
                using (var requestStream = request.GetRequestStream())
                    using (var sw = new StreamWriter(requestStream, new UTF8Encoding(false)))
                    {
                        sw.Write(this.PostData);
                    }
            }
            else if (this.FormData != null && this.FormData.Count > 0)
            {
                using (var requestStream = request.GetRequestStream())
                    using (var sw = new StreamWriter(requestStream, new UTF8Encoding(false)))
                    {
                        bool first = true;

                        foreach (var field in this.FormData)
                        {
                            if (!first)
                            {
                                sw.Write('&');
                            }
                            else
                            {
                                first = false;
                            }

                            sw.Write(Uri.EscapeDataString(field.Key));
                            sw.Write('=');
                            sw.Write(Uri.EscapeDataString(field.Value));
                        }
                    }
            }

            this.PerformRequest(request);

            return(null);
        }