本文整理汇总了C#中Duplicati.Server.WebServer.BodyWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BodyWriter.Write方法的具体用法?C# BodyWriter.Write怎么用?C# BodyWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duplicati.Server.WebServer.BodyWriter
的用法示例。
在下文中一共展示了BodyWriter.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportBackup
private void ImportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
var output_template = "<html><body><script type=\"text/javascript\">var rp = null; try { rp = parent['CBM']; } catch (e) {}; rp = rp || alert; rp('MSG');</script></body></html>";
//output_template = "<html><body><script type=\"text/javascript\">alert('MSG');</script></body></html>";
try
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var cmdline = Library.Utility.Utility.ParseBool(input["cmdline"].Value, false);
output_template = output_template.Replace("CBM", input["callback"].Value);
if (cmdline)
{
response.ContentType = "text/html";
bw.Write(output_template.Replace("MSG", "Import from commandline not yet implemented"));
}
else
{
ImportExportStructure ipx;
var file = request.Form.GetFile("config");
if (file == null)
throw new Exception("No file uploaded");
var buf = new byte[3];
using(var fs = System.IO.File.OpenRead(file.Filename))
{
fs.Read(buf, 0, buf.Length);
fs.Position = 0;
if (buf[0] == 'A' && buf[1] == 'E' && buf[2] == 'S')
{
var passphrase = input["passphrase"].Value;
using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>()))
using(var m2 = m.Decrypt(fs))
using(var sr = new System.IO.StreamReader(m2))
ipx = Serializer.Deserialize<ImportExportStructure>(sr);
}
else
{
using(var sr = new System.IO.StreamReader(fs))
ipx = Serializer.Deserialize<ImportExportStructure>(sr);
}
}
ipx.Backup.ID = null;
((Database.Backup)ipx.Backup).DBPath = null;
if (ipx.Schedule != null)
ipx.Schedule.ID = -1;
lock(Program.DataConnection.m_lock)
{
var basename = ipx.Backup.Name;
var c = 0;
while (c++ < 100 && Program.DataConnection.Backups.Where(x => x.Name.Equals(ipx.Backup.Name, StringComparison.InvariantCultureIgnoreCase)).Any())
ipx.Backup.Name = basename + " (" + c.ToString() + ")";
if (Program.DataConnection.Backups.Where(x => x.Name.Equals(ipx.Backup.Name, StringComparison.InvariantCultureIgnoreCase)).Any())
{
bw.SetOK();
response.ContentType = "text/html";
bw.Write(output_template.Replace("MSG", "There already exists a backup with the name: " + basename.Replace("\'", "\\'")));
}
Program.DataConnection.AddOrUpdateBackupAndSchedule(ipx.Backup, ipx.Schedule);
}
response.ContentType = "text/html";
bw.Write(output_template.Replace("MSG", "OK"));
//bw.OutputOK(new { status = "OK", ID = ipx.Backup.ID });
}
}
catch (Exception ex)
{
Program.DataConnection.LogError("", "Failed to import backup", ex);
response.ContentType = "text/html";
bw.Write(output_template.Replace("MSG", ex.Message.Replace("\'", "\\'").Replace("\r", "\\r").Replace("\n", "\\n")));
}
}