本文整理汇总了C#中Duplicati.Server.WebServer.RESTMethods.RequestInfo.ReportClientError方法的典型用法代码示例。如果您正苦于以下问题:C# RequestInfo.ReportClientError方法的具体用法?C# RequestInfo.ReportClientError怎么用?C# RequestInfo.ReportClientError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duplicati.Server.WebServer.RESTMethods.RequestInfo
的用法示例。
在下文中一共展示了RequestInfo.ReportClientError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PATCH
public void PATCH(string key, RequestInfo info)
{
string str = info.Request.Form["data"].Value;
if (string.IsNullOrWhiteSpace(str))
str = new StreamReader(info.Request.Body, System.Text.Encoding.UTF8).ReadToEnd();
if (string.IsNullOrWhiteSpace(str))
{
info.ReportClientError("Missing data object");
return;
}
Dictionary<string, string> data = null;
try
{
data = Serializer.Deserialize<Dictionary<string, string>>(new StringReader(str));
if (data == null)
{
info.ReportClientError("Data object had no entry");
return;
}
Program.DataConnection.ApplicationSettings.UpdateSettings(data, false);
info.OutputOK();
}
catch (Exception ex)
{
if (data == null)
info.ReportClientError(string.Format("Unable to parse data object: {0}", ex.Message));
else
info.ReportClientError(string.Format("Unable to save settings: {0}", ex.Message));
}
}
示例2: GET
public void GET(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' }, 2);
if (parts.Length <= 1)
{
info.ReportClientError("No url or operation supplied");
return;
}
var url = Library.Utility.Uri.UrlDecode(parts.First());
var operation = parts.Last().ToLowerInvariant();
switch (operation)
{
case "dbpath":
LocateDbUri(url, info);
return;
case "list":
ListFolder(url, info);
return;
case "create":
CreateFolder(url, info);
return;
case "test":
TestConnection(url, info);
return;
default:
info.ReportClientError("No such method");
return;
}
}
示例3: GET
public void GET(string key, RequestInfo info)
{
long id;
long.TryParse(key, out id);
var tf = Program.DataConnection.GetTempFiles().Where(x => x.ID == id).FirstOrDefault();
if (tf == null)
{
info.ReportClientError("Invalid or missing bugreport id");
return;
}
if (!System.IO.File.Exists(tf.Path))
{
info.ReportClientError("File is missing");
return;
}
var filename = "bugreport.zip";
using(var fs = System.IO.File.OpenRead(tf.Path))
{
info.Response.ContentLength = fs.Length;
info.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
info.Response.ContentType = "application/octet-stream";
info.BodyWriter.SetOK();
info.Response.SendHeaders();
fs.CopyTo(info.Response.Body);
info.Response.Send();
}
}
示例4: POST
public void POST(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' }, 2);
long taskid;
if (parts.Length == 2 && long.TryParse(parts.First(), out taskid))
{
var task = Program.WorkThread.CurrentTask;
var tasks = Program.WorkThread.CurrentTasks;
if (task != null)
tasks.Insert(0, task);
task = tasks.Where(x => x.TaskID == taskid).FirstOrDefault();
if (task == null)
{
info.ReportClientError("No such task", System.Net.HttpStatusCode.NotFound);
return;
}
switch (parts.Last().ToLowerInvariant())
{
case "abort":
task.Abort();
info.OutputOK();
return;
case "stop":
task.Stop();
info.OutputOK();
return;
}
}
info.ReportClientError("Invalid or missing task id");
}
示例5: GET
public void GET(string key, RequestInfo info)
{
var fromUpdate = info.Request.QueryString["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");
info.OutputOK(new GetResponse() {
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)
{
info.ReportClientError("No update found");
}
else
{
info.OutputOK(new GetResponse() {
Status = "OK",
Version = updateInfo.Version,
Changelog = updateInfo.ChangeInfo
});
}
}
}
示例6: POST
public void POST(string key, RequestInfo info)
{
if ("import".Equals(key, StringComparison.InvariantCultureIgnoreCase))
{
ImportBackup(info);
return;
}
AddOrUpdateBackupData data = null;
try
{
data = Serializer.Deserialize<AddOrUpdateBackupData>(new StringReader(info.Request.Form["data"].Value));
if (data.Backup == null)
{
info.ReportClientError("Data object had no backup entry");
return;
}
data.Backup.ID = null;
if (Duplicati.Library.Utility.Utility.ParseBool(info.Request.Form["temporary"].Value, false))
{
using(var tf = new Duplicati.Library.Utility.TempFile())
data.Backup.DBPath = tf;
Program.DataConnection.RegisterTemporaryBackup(data.Backup);
info.OutputOK(new { status = "OK", ID = data.Backup.ID });
}
else
{
if (Library.Utility.Utility.ParseBool(info.Request.Form["existing_db"].Value, false))
{
data.Backup.DBPath = Library.Main.DatabaseLocator.GetDatabasePath(data.Backup.TargetURL, null, false, false);
if (string.IsNullOrWhiteSpace(data.Backup.DBPath))
throw new Exception("Unable to find remote db path?");
}
lock(Program.DataConnection.m_lock)
{
if (Program.DataConnection.Backups.Where(x => x.Name.Equals(data.Backup.Name, StringComparison.InvariantCultureIgnoreCase)).Any())
{
info.ReportClientError("There already exists a backup with the name: " + data.Backup.Name);
return;
}
Program.DataConnection.AddOrUpdateBackupAndSchedule(data.Backup, data.Schedule);
}
info.OutputOK(new { status = "OK", ID = data.Backup.ID });
}
}
catch (Exception ex)
{
if (data == null)
info.ReportClientError(string.Format("Unable to parse backup or schedule object: {0}", ex.Message));
else
info.ReportClientError(string.Format("Unable to save schedule or backup object: {0}", ex.Message));
}
}
示例7: SearchFiles
private void SearchFiles(IBackup backup, string filterstring, RequestInfo info)
{
var filter = Library.Utility.Uri.UrlDecode(filterstring ?? "").Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries);
var timestring = info.Request.QueryString["time"].Value;
var allversion = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["all-versions"].Value, false);
if (string.IsNullOrWhiteSpace(timestring) && !allversion)
{
info.ReportClientError("Invalid or missing time");
return;
}
var prefixonly = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["prefix-only"].Value, false);
var foldercontents = Duplicati.Library.Utility.Utility.ParseBool(info.Request.QueryString["folder-contents"].Value, false);
var time = new DateTime();
if (!allversion)
time = Duplicati.Library.Utility.Timeparser.ParseTimeInterval(timestring, DateTime.Now);
var r = Runner.Run(Runner.CreateListTask(backup, filter, prefixonly, allversion, foldercontents, time), false) as Duplicati.Library.Interface.IListResults;
var result = new Dictionary<string, object>();
foreach(HttpServer.HttpInputItem n in info.Request.QueryString)
result[n.Name] = n.Value;
result["Filesets"] = r.Filesets;
result["Files"] = r.Files;
info.OutputOK(result);
}
示例8: GET
public void GET(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' }, 2);
long taskid;
if (parts.Length == 2 && long.TryParse(parts.First(), out taskid))
{
var task = Program.WorkThread.CurrentTask;
var tasks = Program.WorkThread.CurrentTasks;
if (task != null && task.TaskID == taskid)
{
info.OutputOK(new { Status = "Running" });
return;
}
task = tasks.Where(x => x.TaskID == taskid).FirstOrDefault();
if (tasks.Where(x => x.TaskID == taskid).FirstOrDefault() == null)
{
KeyValuePair<long, Exception>[] matches;
lock(Program.MainLock)
matches = Program.TaskResultCache.Where(x => x.Key == taskid).ToArray();
if (matches.Length == 0)
info.ReportClientError("No such task found", System.Net.HttpStatusCode.NotFound);
else
info.OutputOK(new {
Status = matches[0].Value == null ? "Completed" : "Failed",
ErrorMessage = matches[0].Value == null ? null : matches[0].Value.Message,
Exception = matches[0].Value == null ? null : matches[0].Value.ToString()
});
}
else
{
info.OutputOK(new { Status = "Waiting" });
}
}
else
{
info.ReportClientError("Invalid request");
}
}
示例9: POST
public void POST(string key, RequestInfo info)
{
var input = info.Request.Form;
switch ((key ?? "").ToLowerInvariant())
{
case "pause":
if (input.Contains("duration") && !string.IsNullOrWhiteSpace(input["duration"].Value))
{
TimeSpan ts;
try
{
ts = Library.Utility.Timeparser.ParseTimeSpan(input["duration"].Value);
}
catch (Exception ex)
{
info.ReportClientError(ex.Message);
return;
}
if (ts.TotalMilliseconds > 0)
Program.LiveControl.Pause(ts);
else
Program.LiveControl.Pause();
}
else
{
Program.LiveControl.Pause();
}
info.OutputOK();
return;
case "resume":
Program.LiveControl.Resume();
info.OutputOK();
return;
default:
info.ReportClientError("No such action", System.Net.HttpStatusCode.NotFound);
return;
}
}
示例10: POST
public void POST(string key, RequestInfo info)
{
var input = info.Request.Form;
switch ((key ?? "").ToLowerInvariant())
{
case "suppressdonationmessages":
Library.Main.Utility.SuppressDonationMessages = true;
info.OutputOK();
return;
case "showdonationmessages":
Library.Main.Utility.SuppressDonationMessages = false;
info.OutputOK();
return;
default:
info.ReportClientError("No such action", System.Net.HttpStatusCode.NotFound);
return;
}
}
示例11:
info.ReportClientError("Invalid ID");
return;
}
var el = Program.DataConnection.GetNotifications().Where(x => x.ID == id).FirstOrDefault();
示例12: PUT
public void PUT(string key, RequestInfo info)
{
string str = info.Request.Form["data"].Value;
if (string.IsNullOrWhiteSpace(str))
{
info.ReportClientError("Missing backup object");
return;
}
Backups.AddOrUpdateBackupData data = null;
try
{
data = Serializer.Deserialize<Backups.AddOrUpdateBackupData>(new StringReader(str));
if (data.Backup == null)
{
info.ReportClientError("Data object had no backup entry");
return;
}
if (!string.IsNullOrEmpty(key))
data.Backup.ID = key;
if (string.IsNullOrEmpty(data.Backup.ID))
{
info.ReportClientError("Invalid or missing backup id");
return;
}
if (data.Backup.IsTemporary)
{
var backup = Program.DataConnection.GetBackup(data.Backup.ID);
if (backup.IsTemporary)
throw new InvalidDataException("External is temporary but internal is not?");
Program.DataConnection.UpdateTemporaryBackup(backup);
info.OutputOK();
}
else
{
lock(Program.DataConnection.m_lock)
{
var backup = Program.DataConnection.GetBackup(data.Backup.ID);
if (backup == null)
{
info.ReportClientError("Invalid or missing backup id");
return;
}
if (Program.DataConnection.Backups.Where(x => x.Name.Equals(data.Backup.Name, StringComparison.InvariantCultureIgnoreCase) && x.ID != data.Backup.ID).Any())
{
info.ReportClientError("There already exists a backup with the name: " + data.Backup.Name);
return;
}
//TODO: Merge in real passwords where the placeholder is found
Program.DataConnection.AddOrUpdateBackupAndSchedule(data.Backup, data.Schedule);
}
info.OutputOK();
}
}
catch (Exception ex)
{
if (data == null)
info.ReportClientError(string.Format("Unable to parse backup or schedule object: {0}", ex.Message));
else
info.ReportClientError(string.Format("Unable to save backup or schedule: {0}", ex.Message));
}
}
示例13: DELETE
public void DELETE(string key, RequestInfo info)
{
var backup = Program.DataConnection.GetBackup(key);
if (backup == null)
{
info.ReportClientError("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(info.Request.QueryString["force"].Value, out force))
force = false;
if (!force)
{
info.OutputError(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();
info.OutputError(new { status = "failed", reason = "backup-unstoppable" });
return;
}
}
if (hasPaused)
Program.LiveControl.Resume();
}
}
catch (Exception ex)
{
info.OutputError(new { status = "error", message = ex.Message });
return;
}
}
//var dbpath = backup.DBPath;
Program.DataConnection.DeleteBackup(backup);
// TODO: Before we activate this,
// we need some strategy to figure out
// if the db is shared with something else
// like the commandline or another backup
/*try
{
if (System.IO.File.Exists(dbpath))
System.IO.File.Delete(dbpath);
}
catch (Exception ex)
{
Program.DataConnection.LogError(null, string.Format("Failed to delete database: {0}", dbpath), ex);
}*/
//We have fiddled with the schedules
Program.Scheduler.Reschedule();
info.OutputOK();
}
示例14: GET
public void GET(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' }, 2);
var bk = Program.DataConnection.GetBackup(parts.First());
if (bk == null)
info.ReportClientError("Invalid or missing backup id");
else
{
if (parts.Length > 1)
{
var operation = parts.Last().Split(new char[] {'/'}).First().ToLowerInvariant();
switch (operation)
{
case "files":
SearchFiles(bk, parts.Last().Split(new char[] { '/' }, 2).LastOrDefault(), info);
return;
case "log":
FetchLogData(bk, info);
return;
case "remotelog":
FetchRemoteLogData(bk, info);
return;
case "filesets":
ListFileSets(bk, info);
return;
case "export":
Export(bk, info);
return;
case "isactive":
IsActive(bk, info);
return;
default:
info.ReportClientError(string.Format("Invalid component: {0}", operation));
return;
}
}
var scheduleId = Program.DataConnection.GetScheduleIDsFromTags(new string[] { "ID=" + bk.ID });
var schedule = scheduleId.Any() ? Program.DataConnection.GetSchedule(scheduleId.First()) : null;
var sourcenames = SpecialFolders.GetSourceNames(bk);
//TODO: Filter out the password in both settings and the target url
info.OutputOK(new GetResponse()
{
success = true,
data = new GetResponse.GetResponseData() {
Schedule = schedule,
Backup = bk,
DisplayNames = sourcenames
}
});
}
}
示例15: POST
public void POST(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' }, 2);
var bk = Program.DataConnection.GetBackup(parts.First());
if (bk == null)
info.ReportClientError("Invalid or missing backup id");
else
{
if (parts.Length > 1)
{
var operation = parts.Last().Split(new char[] { '/' }).First().ToLowerInvariant();
switch (operation)
{
case "deletedb":
System.IO.File.Delete(bk.DBPath);
info.OutputOK();
return;
case "restore":
RestoreFiles(bk, info);
return;
case "createreport":
CreateReport(bk, info);
return;
case "repair":
Repair(bk, info);
return;
case "repairupdate":
RepairUpdate(bk, info);
return;
case "verify":
Verify(bk, info);
return;
case "start":
case "run":
RunBackup(bk, info);
return;
case "copytotemp":
var ipx = Serializer.Deserialize<Database.Backup>(new StringReader(Newtonsoft.Json.JsonConvert.SerializeObject(bk)));
using(var tf = new Duplicati.Library.Utility.TempFile())
ipx.DBPath = tf;
ipx.ID = null;
info.OutputOK(new { status = "OK", ID = Program.DataConnection.RegisterTemporaryBackup(ipx) });
return;
}
}
info.ReportClientError("Invalid request");
}
}