本文整理汇总了C#中Duplicati.Server.WebServer.BodyWriter.OutputOK方法的典型用法代码示例。如果您正苦于以下问题:C# BodyWriter.OutputOK方法的具体用法?C# BodyWriter.OutputOK怎么用?C# BodyWriter.OutputOK使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duplicati.Server.WebServer.BodyWriter
的用法示例。
在下文中一共展示了BodyWriter.OutputOK方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBackup
private void AddBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
var str = request.Form["data"].Value;
if (string.IsNullOrWhiteSpace(str))
{
ReportError(response, bw, "Missing backup object");
return;
}
AddOrUpdateBackupData data = null;
try
{
data = Serializer.Deserialize<AddOrUpdateBackupData>(new StringReader(str));
if (data.Backup == null)
{
ReportError(response, bw, "Data object had no backup entry");
return;
}
data.Backup.ID = null;
if (Duplicati.Library.Utility.Utility.ParseBool(request.Form["temporary"].Value, false))
{
Program.DataConnection.RegisterTemporaryBackup(data.Backup);
bw.OutputOK(new { status = "OK", ID = data.Backup.ID });
}
else
{
if (Library.Utility.Utility.ParseBool(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())
{
ReportError(response, bw, "There already exists a backup with the name: " + data.Backup.Name);
return;
}
Program.DataConnection.AddOrUpdateBackupAndSchedule(data.Backup, data.Schedule);
}
bw.OutputOK(new { status = "OK", ID = data.Backup.ID });
}
}
catch (Exception ex)
{
if (data == null)
ReportError(response, bw, string.Format("Unable to parse backup or schedule object: {0}", ex.Message));
else
ReportError(response, bw, string.Format("Unable to save schedule or backup object: {0}", ex.Message));
}
}
示例2: ReadLogData
private void ReadLogData(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var backupid = input["id"].Value;
if (string.IsNullOrWhiteSpace(backupid))
{
List<Dictionary<string, object>> res = null;
Program.DataConnection.ExecuteWithCommand(x =>
{
res = DumpTable(x, "ErrorLog", "Timestamp", input["offset"].Value, input["pagesize"].Value);
});
bw.OutputOK(res);
}
else
{
var backup = Program.DataConnection.GetBackup(backupid);
if (backup == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
using(var con = (System.Data.IDbConnection)Activator.CreateInstance(Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType))
{
con.ConnectionString = "Data Source=" + backup.DBPath;
con.Open();
using(var cmd = con.CreateCommand())
{
if (Duplicati.Library.Utility.Utility.ParseBool(input["remotelog"].Value, false))
{
var dt = DumpTable(cmd, "RemoteOperation", "ID", input["offset"].Value, input["pagesize"].Value);
// Unwrap raw data to a string
foreach(var n in dt)
try { n["Data"] = System.Text.Encoding.UTF8.GetString((byte[])n["Data"]); }
catch { }
bw.OutputOK(dt);
}
else
{
var dt = DumpTable(cmd, "LogData", "ID", input["offset"].Value, input["pagesize"].Value);
bw.OutputOK(dt);
}
}
}
}
}
示例3: GetBackup
private void GetBackup(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");
else
{
var scheduleId = Program.DataConnection.GetScheduleIDsFromTags(new string[] { "ID=" + bk.ID });
var schedule = scheduleId.Any() ? Program.DataConnection.GetSchedule(scheduleId.First()) : null;
var sourcenames = GetSourceNames(bk);
//TODO: Filter out the password in both settings and the target url
bw.OutputOK(new
{
success = true,
data = new {
Schedule = schedule,
Backup = bk,
DisplayNames = sourcenames
}
});
}
}
示例4: SearchBackupFiles
private void SearchBackupFiles(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var filter = (input["filter"].Value ?? "").Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries);
var timestring = input["time"].Value;
var allversion = Duplicati.Library.Utility.Utility.ParseBool(input["all-versions"].Value, false);
if (string.IsNullOrWhiteSpace(timestring) && !allversion)
{
ReportError(response, bw, "Invalid or missing time");
return;
}
var bk = Program.DataConnection.GetBackup(input["id"].Value);
if (bk == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
var prefixonly = Duplicati.Library.Utility.Utility.ParseBool(input["prefix-only"].Value, false);
var foldercontents = Duplicati.Library.Utility.Utility.ParseBool(input["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(bk, filter, prefixonly, allversion, foldercontents, time), false) as Duplicati.Library.Interface.IListResults;
var result = new Dictionary<string, object>();
foreach(HttpServer.HttpInputItem n in input)
result[n.Name] = n.Value;
result["Filesets"] = r.Filesets;
result["Files"] = r.Files;
bw.OutputOK(result);
}
示例5: GetUISettingSchemes
private void GetUISettingSchemes(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bw.OutputOK(Program.DataConnection.GetUISettingsSchemes());
}
示例6: SetUISettings
private void SetUISettings(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var scheme = input["scheme"].Value;
var str = input["data"].Value;
if (string.IsNullOrWhiteSpace(scheme))
{
ReportError(response, bw, "No scheme supplied");
return;
}
if (string.IsNullOrWhiteSpace(str))
{
ReportError(response, bw, "No data supplied");
return;
}
IDictionary<string, string> data;
try
{
data = Serializer.Deserialize<Dictionary<string, string>>(new StringReader(str));
}
catch (Exception ex)
{
ReportError(response, bw, string.Format("Unable to parse settings object: {0}", ex.Message));
return;
}
if (data == null)
{
ReportError(response, bw, string.Format("Unable to parse settings object"));
return;
}
Program.DataConnection.SetUISettings(scheme, data);
bw.OutputOK();
}
示例7: ListSystemInfo
private void ListSystemInfo(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bw.OutputOK(new
{
APIVersion = 1,
PasswordPlaceholder = Duplicati.Server.WebServer.Server.PASSWORD_PLACEHOLDER,
ServerVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
ServerVersionName = Duplicati.License.VersionNumbers.Version,
ServerTime = DateTime.Now,
OSType = Library.Utility.Utility.IsClientLinux ? (Library.Utility.Utility.IsClientOSX ? "OSX" : "Linux") : "Windows",
DirectorySeparator = System.IO.Path.DirectorySeparatorChar,
PathSeparator = System.IO.Path.PathSeparator,
CaseSensitiveFilesystem = Duplicati.Library.Utility.Utility.IsFSCaseSensitive,
MonoVersion = Duplicati.Library.Utility.Utility.IsMono ? Duplicati.Library.Utility.Utility.MonoVersion.ToString() : null,
MachineName = System.Environment.MachineName,
NewLine = System.Environment.NewLine,
CLRVersion = System.Environment.Version.ToString(),
CLROSInfo = new
{
Platform = System.Environment.OSVersion.Platform.ToString(),
ServicePack = System.Environment.OSVersion.ServicePack,
Version = System.Environment.OSVersion.Version.ToString(),
VersionString = System.Environment.OSVersion.VersionString
},
Options = Serializable.ServerSettings.Options,
CompressionModules = Serializable.ServerSettings.CompressionModules,
EncryptionModules = Serializable.ServerSettings.EncryptionModules,
BackendModules = Serializable.ServerSettings.BackendModules,
GenericModules = Serializable.ServerSettings.GenericModules,
WebModules = Serializable.ServerSettings.WebModules,
ConnectionModules = Serializable.ServerSettings.ConnectionModules,
UsingAlternateUpdateURLs = Duplicati.Library.AutoUpdater.AutoUpdateSettings.UsesAlternateURLs,
LogLevels = Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))
});
}
示例8: 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();
}
示例9: ListSupportedActions
private void ListSupportedActions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bw.OutputOK(new { Version = 1, Methods = SUPPORTED_METHODS.Keys });
}
示例10: ValidatePath
private void ValidatePath(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
if (input["path"] == null || input["path"].Value == null)
{
ReportError(response, bw, "The path parameter was not set");
return;
}
try
{
string path = SpecialFolders.ExpandEnvironmentVariables(input["path"].Value);
if (System.IO.Path.IsPathRooted(path) && System.IO.Directory.Exists(path))
{
bw.OutputOK();
return;
}
}
catch
{
}
ReportError(response, bw, "File or folder not found");
return;
}
示例11: GetServerOptions
private void GetServerOptions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
var adv_props = from n in Program.DataConnection.GetSettings(Database.Connection.APP_SETTINGS_ID)
select new KeyValuePair<string, string>(n.Name, n.Value);
bw.OutputOK(adv_props.ToDictionary(x => x.Key, x => x.Value));
}
示例12: ListApplicationSettings
private void ListApplicationSettings(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bw.OutputOK(Program.DataConnection.ApplicationSettings);
}
示例13: DeleteLocalData
private void DeleteLocalData(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;
}
System.IO.File.Delete(bk.DBPath);
bw.OutputOK();
}
示例14: ListCoreOptions
private void ListCoreOptions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bw.OutputOK(new Duplicati.Library.Main.Options(new Dictionary<string, string>()).SupportedCommands);
}
示例15: GetCurrentState
private void GetCurrentState (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
bool isError;
long id = 0;
if (LongPollCheck(request, response, bw, Program.StatusEventNotifyer, ref id, out isError))
{
//Make sure we do not report a higher number than the eventnotifyer says
var st = new Serializable.ServerStatus();
st.LastEventID = id;
bw.OutputOK(st);
}
else if (!isError)
{
bw.OutputOK(new Serializable.ServerStatus());
}
}