本文整理汇总了C#中Duplicati.Server.WebServer.BodyWriter.WriteJsonObject方法的典型用法代码示例。如果您正苦于以下问题:C# BodyWriter.WriteJsonObject方法的具体用法?C# BodyWriter.WriteJsonObject怎么用?C# BodyWriter.WriteJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duplicati.Server.WebServer.BodyWriter
的用法示例。
在下文中一共展示了BodyWriter.WriteJsonObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteBackup
private void DeleteBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var backup = Program.DataConnection.GetBackup(input["id"].Value);
if (backup == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
if (Program.WorkThread.Active)
{
try
{
//TODO: It's not safe to access the values like this,
//because the runner thread might interfere
var nt = Program.WorkThread.CurrentTask;
if (backup.Equals(nt == null ? null : nt.Backup))
{
bool force;
if (!bool.TryParse(input["force"].Value, out force))
force = false;
if (!force)
{
bw.WriteJsonObject(new { status = "failed", reason = "backup-in-progress" });
return;
}
bool hasPaused = Program.LiveControl.State == LiveControls.LiveControlState.Paused;
Program.LiveControl.Pause();
try
{
for (int i = 0; i < 10; i++)
if (Program.WorkThread.Active)
{
var t = Program.WorkThread.CurrentTask;
if (backup.Equals(t == null ? null : t.Backup))
System.Threading.Thread.Sleep(1000);
else
break;
}
else
break;
}
finally
{
}
if (Program.WorkThread.Active)
{
var t = Program.WorkThread.CurrentTask;
if (backup.Equals(t == null ? null : t.Backup))
{
if (hasPaused)
Program.LiveControl.Resume();
bw.WriteJsonObject(new { status = "failed", reason = "backup-unstoppable" });
return;
}
}
if (hasPaused)
Program.LiveControl.Resume();
}
}
catch (Exception ex)
{
bw.WriteJsonObject(new { status = "error", message = ex.Message });
return;
}
}
Program.DataConnection.DeleteBackup(backup);
//We have fiddled with the schedules
Program.Scheduler.Reschedule();
bw.OutputOK();
}
示例2: Process
public override bool Process (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
//We use the fake entry point /control.cgi to listen for requests
//This ensures that the rest of the webserver can just serve plain files
if (!request.Uri.AbsolutePath.Equals(CONTROL_HANDLER_URI, StringComparison.InvariantCultureIgnoreCase))
return false;
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
string action = input["action"].Value ?? "";
//Lookup the actual handler method
ProcessSub method;
SUPPORTED_METHODS.TryGetValue(action, out method);
if (method == null) {
response.Status = System.Net.HttpStatusCode.NotImplemented;
response.Reason = "Unsupported action: " + (action == null ? "<null>" : "");
response.Send();
} else {
//Default setup
response.Status = System.Net.HttpStatusCode.OK;
response.Reason = "OK";
#if DEBUG
response.ContentType = "text/plain";
#else
response.ContentType = "text/json";
#endif
using (BodyWriter bw = new BodyWriter(response, request))
{
try
{
method(request, response, session, bw);
}
catch (Exception ex)
{
Program.DataConnection.LogError("", string.Format("Request for {0} gave error", action), ex);
Console.WriteLine(ex.ToString());
try
{
if (!response.HeadersSent)
{
response.Status = System.Net.HttpStatusCode.InternalServerError;
response.Reason = "Error";
response.ContentType = "text/plain";
bw.WriteJsonObject(new
{
Message = ex.Message,
Type = ex.GetType().Name,
#if DEBUG
Stacktrace = ex.ToString()
#endif
});
bw.Flush();
}
}
catch (Exception flex)
{
Program.DataConnection.LogError("", "Reporting error gave error", flex);
}
}
}
}
return true;
}
示例3: ReportError
private void ReportError(HttpServer.IHttpResponse response, BodyWriter bw, string message)
{
response.Status = System.Net.HttpStatusCode.InternalServerError;
response.Reason = message;
bw.WriteJsonObject(new { Error = message });
}
示例4: GetChangelog
private void GetChangelog(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var fromUpdate = input["from-update"].Value;
if (!Library.Utility.Utility.ParseBool(fromUpdate, false))
{
var path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "changelog.txt");
bw.SetOK();
bw.WriteJsonObject(new {
Status = "OK",
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
Changelog = System.IO.File.ReadAllText(path)
});
}
else
{
var updateInfo = Program.DataConnection.ApplicationSettings.UpdatedVersion;
if (updateInfo == null)
{
ReportError(response, bw, "No update found");
}
else
{
bw.SetOK();
bw.WriteJsonObject(new {
Status = "OK",
Version = updateInfo.Version,
Changelog = updateInfo.ChangeInfo
});
}
}
}
示例5: GetAcknowledgements
private void GetAcknowledgements(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
var path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "acknowledgements.txt");
bw.SetOK();
bw.WriteJsonObject(new {
Status = "OK",
Acknowledgements = System.IO.File.ReadAllText(path)
});
}
示例6: LocateUriDb
private void LocateUriDb(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var uri = input["uri"].Value;
if (string.IsNullOrWhiteSpace(uri))
{
ReportError(response, bw, "Invalid request, missing uri");
}
else
{
var path = Library.Main.DatabaseLocator.GetDatabasePath(uri, null, false, false);
bw.SetOK();
bw.WriteJsonObject(new {Exists = !string.IsNullOrWhiteSpace(path)});
}
}