当前位置: 首页>>代码示例>>C#>>正文


C# BodyWriter.WriteJsonObject方法代码示例

本文整理汇总了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();
        }
开发者ID:Berimor66,项目名称:duplicati,代码行数:80,代码来源:DeleteBackup.cs

示例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;
        }
开发者ID:HITSUN2015,项目名称:duplicati,代码行数:68,代码来源:ControlHandler.cs

示例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 });
        }
开发者ID:HITSUN2015,项目名称:duplicati,代码行数:7,代码来源:ControlHandler.cs

示例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
                    });
                }
            }
        }
开发者ID:admz,项目名称:duplicati,代码行数:33,代码来源:ControlHandler.cs

示例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)
         });            
 }
开发者ID:admz,项目名称:duplicati,代码行数:9,代码来源:ControlHandler.cs

示例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)});
            }
        }
开发者ID:admz,项目名称:duplicati,代码行数:17,代码来源:ControlHandler.cs


注:本文中的Duplicati.Server.WebServer.BodyWriter.WriteJsonObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。