本文整理汇总了C#中Duplicati.Server.WebServer.RESTMethods.RequestInfo类的典型用法代码示例。如果您正苦于以下问题:C# RequestInfo类的具体用法?C# RequestInfo怎么用?C# RequestInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestInfo类属于Duplicati.Server.WebServer.RESTMethods命名空间,在下文中一共展示了RequestInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GET
public void GET(string key, RequestInfo info)
{
// Start with a scratch object
var o = new Newtonsoft.Json.Linq.JObject();
// Add application wide settings
o.Add("ApplicationOptions", new Newtonsoft.Json.Linq.JArray(
from n in Program.DataConnection.Settings
select Newtonsoft.Json.Linq.JObject.FromObject(n)
));
try
{
// Add built-in defaults
Newtonsoft.Json.Linq.JObject n;
using(var s = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".newbackup.json")))
n = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(s.ReadToEnd());
MergeJsonObjects(o, n);
}
catch
{
}
try
{
// Add install defaults/overrides, if present
var path = System.IO.Path.Combine(Duplicati.Library.AutoUpdater.UpdaterManager.InstalledBaseDir, "newbackup.json");
if (System.IO.File.Exists(path))
{
Newtonsoft.Json.Linq.JObject n;
n = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(System.IO.File.ReadAllText(path));
MergeJsonObjects(o, n);
}
}
catch
{
}
info.OutputOK(new
{
success = true,
data = o
});
}
示例2: GET
public void GET(string key, RequestInfo info)
{
var adv_props = from n in Program.DataConnection.GetSettings(Database.Connection.APP_SETTINGS_ID)
select new KeyValuePair<string, string>(n.Name, n.Value);
info.OutputOK(adv_props.ToDictionary(x => x.Key, x => x.Value));
}
示例3: POST
public void POST(string key, RequestInfo info)
{
string url;
using(var sr = new System.IO.StreamReader(info.Request.Body, System.Text.Encoding.UTF8, true))
url = sr.ReadToEnd();
switch (key)
{
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;
}
}
示例4: 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;
}
}
示例5: 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);
}
示例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: 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();
}
}
示例8: CreateFolder
private void CreateFolder(string uri, RequestInfo info)
{
using(var b = Duplicati.Library.DynamicLoader.BackendLoader.GetBackend(uri, new Dictionary<string, string>()))
b.CreateFolder();
info.OutputOK();
}
示例9: 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
});
}
}
}
示例10: 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));
}
}
示例11: 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");
}
示例12: GET
public void GET(string key, RequestInfo info)
{
var prop = typeof(Database.ApplicationSettings).GetProperty(key);
if (prop == null)
info.OutputError(null, System.Net.HttpStatusCode.NotFound, "Not found");
else
info.OutputOK(prop.GetValue(Program.DataConnection.ApplicationSettings));
}
示例13: LocateDbUri
private void LocateDbUri(string uri, RequestInfo info)
{
var path = Library.Main.DatabaseLocator.GetDatabasePath(uri, null, false, false);
info.OutputOK(new {
Exists = !string.IsNullOrWhiteSpace(path),
Path = path
});
}
示例14: GET
public void GET(string key, RequestInfo info)
{
var path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "acknowledgements.txt");
info.OutputOK(new GetResponse() {
Status = "OK",
Acknowledgements = System.IO.File.ReadAllText(path)
});
}
示例15: GET
public void GET(string key, RequestInfo info)
{
var parts = (key ?? "").Split(new char[] { '/' });
var path = Duplicati.Library.Utility.Uri.UrlDecode((parts.Length == 2 ? parts.FirstOrDefault() : key ?? ""));
var command = parts.Length == 2 ? parts.Last() : null;
if (string.IsNullOrEmpty(path))
path = info.Request.QueryString["path"].Value;
Process(command, path, info);
}