2017-10-10 16:05:21 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2020-08-04 12:27:21 +10:00
|
|
|
|
using Umbraco.Core;
|
2020-05-20 13:35:55 +02:00
|
|
|
|
using Umbraco.Core.Logging;
|
2020-08-04 12:27:21 +10:00
|
|
|
|
using Umbraco.Web.Common.Attributes;
|
2020-05-20 13:35:55 +02:00
|
|
|
|
using Umbraco.Web.Editors;
|
2017-10-10 16:05:21 +01:00
|
|
|
|
|
2020-05-20 13:35:55 +02:00
|
|
|
|
namespace Umbraco.Web.BackOffice.Controllers
|
2017-10-10 16:05:21 +01:00
|
|
|
|
{
|
2020-08-04 12:27:21 +10:00
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
2017-10-10 16:05:21 +01:00
|
|
|
|
public class HelpController : UmbracoAuthorizedJsonController
|
2018-08-17 15:07:57 +02:00
|
|
|
|
{
|
2020-05-20 13:35:55 +02:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public HelpController(ILogger logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-25 16:15:37 +02:00
|
|
|
|
private static HttpClient _httpClient;
|
2018-07-27 16:41:57 +01:00
|
|
|
|
public async Task<List<HelpPage>> GetContextHelpForPage(string section, string tree, string baseUrl = "https://our.umbraco.com")
|
2017-10-10 16:05:21 +01:00
|
|
|
|
{
|
|
|
|
|
|
var url = string.Format(baseUrl + "/Umbraco/Documentation/Lessons/GetContextHelpDocs?sectionAlias={0}&treeAlias={1}", section, tree);
|
2018-09-25 16:15:37 +02:00
|
|
|
|
|
2019-12-19 09:05:47 +01:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (_httpClient == null)
|
|
|
|
|
|
_httpClient = new HttpClient();
|
|
|
|
|
|
|
|
|
|
|
|
//fetch dashboard json and parse to JObject
|
|
|
|
|
|
var json = await _httpClient.GetStringAsync(url);
|
|
|
|
|
|
var result = JsonConvert.DeserializeObject<List<HelpPage>>(json);
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (HttpRequestException rex)
|
|
|
|
|
|
{
|
2020-09-14 14:25:59 +02:00
|
|
|
|
_logger.LogInformation($"Check your network connection, exception: {rex.Message}");
|
2019-12-19 09:05:47 +01:00
|
|
|
|
}
|
2017-10-10 16:05:21 +01:00
|
|
|
|
|
2018-08-17 15:07:57 +02:00
|
|
|
|
return new List<HelpPage>();
|
2017-10-10 16:05:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DataContract(Name = "HelpPage")]
|
|
|
|
|
|
public class HelpPage
|
|
|
|
|
|
{
|
|
|
|
|
|
[DataMember(Name = "name")]
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember(Name = "description")]
|
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember(Name = "url")]
|
|
|
|
|
|
public string Url { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember(Name = "type")]
|
|
|
|
|
|
public string Type { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|