Files
Umbraco-CMS/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs

73 lines
2.6 KiB
C#
Raw Normal View History

2017-07-20 11:21:28 +02:00
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Cache;
2018-01-24 11:44:44 +01:00
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Core.Configuration.Grid
{
2017-09-15 18:22:19 +02:00
internal class GridEditorsConfig : IGridEditorsConfig
{
private readonly ILogger _logger;
2019-01-17 11:01:23 +01:00
private readonly IAppPolicedCache _runtimeCache;
private readonly DirectoryInfo _configFolder;
private readonly bool _isDebug;
2019-01-17 11:01:23 +01:00
public GridEditorsConfig(ILogger logger, IAppPolicedCache runtimeCache, DirectoryInfo configFolder, bool isDebug)
{
_logger = logger;
_runtimeCache = runtimeCache;
_configFolder = configFolder;
_isDebug = isDebug;
}
public IEnumerable<IGridEditorConfig> Editors
{
get
{
2019-01-07 10:43:28 +01:00
List<GridEditor> GetResult()
{
2018-01-19 19:08:12 +01:00
// fixme - should use the common one somehow! + ignoring _appPlugins here!
2018-01-24 11:44:44 +01:00
var parser = new ManifestParser(_runtimeCache, Current.ManifestValidators, _logger);
var editors = new List<GridEditor>();
var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js");
if (File.Exists(gridConfig))
{
var sourceString = File.ReadAllText(gridConfig);
try
{
editors.AddRange(parser.ParseGridEditors(sourceString));
}
catch (Exception ex)
{
_logger.Error<GridEditorsConfig>(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString);
}
}
2018-01-19 19:08:12 +01:00
// add manifest editors, skip duplicates
foreach (var gridEditor in parser.Manifest.GridEditors)
{
2019-01-07 10:43:28 +01:00
if (editors.Contains(gridEditor) == false) editors.Add(gridEditor);
}
2018-01-19 19:08:12 +01:00
return editors;
2019-01-07 10:43:28 +01:00
}
//cache the result if debugging is disabled
var result = _isDebug
2019-01-07 10:43:28 +01:00
? GetResult()
: _runtimeCache.GetCacheItem<List<GridEditor>>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10));
return result;
}
2017-07-20 11:21:28 +02:00
}
}
2017-07-20 11:21:28 +02:00
}