本文整理汇总了C#中HttpServer.HttpServer.SendBody方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.SendBody方法的具体用法?C# HttpServer.SendBody怎么用?C# HttpServer.SendBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer.HttpServer
的用法示例。
在下文中一共展示了HttpServer.SendBody方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportBackup
private void ExportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var bk = Program.DataConnection.GetBackup(input["id"].Value);
if (bk == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
var cmdline = Library.Utility.Utility.ParseBool(input["cmdline"].Value, false);
if (cmdline)
{
bw.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, bk)) });
}
else
{
var passphrase = input["passphrase"].Value;
var scheduleId = Program.DataConnection.GetScheduleIDsFromTags(new string[] { "ID=" + bk.ID });
var ipx = new ImportExportStructure() {
CreatedByVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
Backup = (Database.Backup)bk,
Schedule = (Database.Schedule)(scheduleId.Any() ? Program.DataConnection.GetSchedule(scheduleId.First()) : null),
DisplayNames = GetSourceNames(bk)
};
byte[] data;
using(var ms = new System.IO.MemoryStream())
using(var sw = new System.IO.StreamWriter(ms))
{
Serializer.SerializeJson(sw, ipx, true);
if (!string.IsNullOrWhiteSpace(passphrase))
{
ms.Position = 0;
using(var ms2 = new System.IO.MemoryStream())
using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>()))
{
m.Encrypt(ms, ms2);
data = ms2.ToArray();
}
}
else
data = ms.ToArray();
}
var filename = Library.Utility.Uri.UrlEncode(bk.Name) + "-duplicati-config.json";
if (!string.IsNullOrWhiteSpace(passphrase))
filename += ".aes";
response.ContentLength = data.Length;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
response.ContentType = "application/octet-stream";
bw.SetOK();
response.SendHeaders();
response.SendBody(data);
}
}
示例2: ExportBackup
private void ExportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var bk = Program.DataConnection.GetBackup(input["id"].Value);
if (bk == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
var cmdline = Library.Utility.Utility.ParseBool(input["cmdline"].Value, false);
if (cmdline)
{
bw.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, bk)) });
}
else
{
var passphrase = input["passphrase"].Value;
var ipx = Program.DataConnection.PrepareBackupForExport(bk);
byte[] data;
using(var ms = new System.IO.MemoryStream())
using(var sw = new System.IO.StreamWriter(ms))
{
Serializer.SerializeJson(sw, ipx, true);
if (!string.IsNullOrWhiteSpace(passphrase))
{
ms.Position = 0;
using(var ms2 = new System.IO.MemoryStream())
using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>()))
{
m.Encrypt(ms, ms2);
data = ms2.ToArray();
}
}
else
data = ms.ToArray();
}
var filename = Library.Utility.Uri.UrlEncode(bk.Name) + "-duplicati-config.json";
if (!string.IsNullOrWhiteSpace(passphrase))
filename += ".aes";
response.ContentLength = data.Length;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
response.ContentType = "application/octet-stream";
bw.SetOK();
response.SendHeaders();
response.SendBody(data);
}
}