The DTO object containing the full response for PRTG.
示例#1
0
        /// <summary>
        /// Serialize the DTO as JSON
        /// </summary>
        /// <param name="reply"></param>
        /// <returns></returns>
        public string Serialize(Reply reply)
        {
            string resultsJson = string.Join(",", reply.Prtg.Result.Select(p => ConvertToJson(p)).ToArray());

            string completeResult = "{\"prtg\":{\"result\":[" + resultsJson + "]";

            if (!string.IsNullOrWhiteSpace(reply.Prtg.Text))
            {
                completeResult = completeResult + $", \"text\":\"{reply.Prtg.Text}\"";
            }
            completeResult = completeResult + "}}";

            return completeResult;
        }
示例#2
0
 /// <summary>
 /// Queries the sensor to get the results, and then uses the serializer to convert it to a string.
 /// </summary>
 /// <param name="sensor"></param>
 /// <returns></returns>
 private Response QuerySensor(ISensor sensor)
 {
     try
     {
         var reply = new Reply(sensor.Description, sensor.Results().ToList());
         return Response.AsText(_serializer.Serialize(reply), _serializer.ContentType);
     }
     catch (Exception err)
     {
         Console.WriteLine("ERROR WITH REQUEST!");
         Console.WriteLine(err.ToString());
         return 500;
     }
 }
示例#3
0
        /// <summary>
        /// Serialize the reply as xml
        /// </summary>
        /// <param name="reply"></param>
        /// <returns></returns>
        public string Serialize(Reply reply)
        {
            //return Response.AsJson(new Reply(sensor.Description, resultsList));
            string resultsJson = string.Join(Environment.NewLine, reply.Prtg.Result.Select(this.ConvertToXml).ToArray());

            StringBuilder result = new StringBuilder();
            result.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
            result.AppendLine("<prtg>");
            result.AppendLine(resultsJson);

            if (!string.IsNullOrWhiteSpace(reply.Prtg.Text))
            {
                result.AppendLine($"<text>{reply.Prtg.Text}</text>");
            }
            result.AppendLine("</prtg>");

            return result.ToString();
        }