Fix code formatting

This commit is contained in:
Ronald Barendse
2021-09-14 23:56:49 +02:00
parent 26b26a940d
commit af0f263e3c

View File

@@ -122,31 +122,21 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IMediaType> ImportMediaTypes(IEnumerable<XElement> docTypeElements, int userId)
{
return ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService);
}
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService);
#endregion
#region Content
public IReadOnlyList<T> ImportContentBase<T, S>(
public IReadOnlyList<TContentBase> ImportContentBase<TContentBase, TContentTypeComposition>(
IEnumerable<CompiledPackageContentBase> docs,
IDictionary<string, S> importedDocumentTypes,
IDictionary<string, TContentTypeComposition> importedDocumentTypes,
int userId,
IContentTypeBaseService<S> typeService,
IContentServiceBase<T> service)
where T : class, IContentBase
where S : IContentTypeComposition
{
return docs.SelectMany(x => ImportContentBase(
x.XmlData.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty),
-1,
importedDocumentTypes,
userId,
typeService,
service)).ToList();
}
IContentTypeBaseService<TContentTypeComposition> typeService,
IContentServiceBase<TContentBase> service)
where TContentBase : class, IContentBase
where TContentTypeComposition : IContentTypeComposition
=> docs.SelectMany(x => ImportContentBase(x.XmlData.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty), -1, importedDocumentTypes, userId, typeService, service)).ToList();
/// <summary>
/// Imports and saves package xml as <see cref="IContent"/>
@@ -156,17 +146,16 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="importedDocumentTypes">A dictionary of already imported document types (basically used as a cache)</param>
/// <param name="userId">Optional Id of the user performing the import</param>
/// <returns>An enumerable list of generated content</returns>
public IEnumerable<T> ImportContentBase<T, S>(
public IEnumerable<TContentBase> ImportContentBase<TContentBase, TContentTypeComposition>(
IEnumerable<XElement> roots,
int parentId,
IDictionary<string, S> importedDocumentTypes,
IDictionary<string, TContentTypeComposition> importedDocumentTypes,
int userId,
IContentTypeBaseService<S> typeService,
IContentServiceBase<T> service)
where T : class, IContentBase
where S : IContentTypeComposition
IContentTypeBaseService<TContentTypeComposition> typeService,
IContentServiceBase<TContentBase> service)
where TContentBase : class, IContentBase
where TContentTypeComposition : IContentTypeComposition
{
var contents = ParseContentBaseRootXml(roots, parentId, importedDocumentTypes, typeService, service).ToList();
if (contents.Any())
{
@@ -213,74 +202,72 @@ namespace Umbraco.Cms.Infrastructure.Packaging
{
throw new InvalidOperationException("Could not find content type with alias " + contentTypeAlias);
}
importedContentTypes.Add(contentTypeAlias, contentType);
}
if (TryCreateContentFromXml(root, importedContentTypes[contentTypeAlias], default, parentId, service,
out TContentBase content))
if (TryCreateContentFromXml(root, importedContentTypes[contentTypeAlias], default, parentId, service, out TContentBase content))
{
contents.Add(content);
}
var children = root.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty)
.ToList();
var children = root.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty).ToList();
if (children.Count > 0)
{
contents.AddRange(CreateContentFromXml(children, content, importedContentTypes, typeService, service).WhereNotNull());
}
}
return contents;
}
private IEnumerable<T> CreateContentFromXml<T, S>(
private IEnumerable<TContentBase> CreateContentFromXml<TContentBase, TContentTypeComposition>(
IEnumerable<XElement> children,
T parent,
IDictionary<string, S> importedContentTypes,
IContentTypeBaseService<S> typeService,
IContentServiceBase<T> service)
where T : class, IContentBase
where S : IContentTypeComposition
TContentBase parent,
IDictionary<string, TContentTypeComposition> importedContentTypes,
IContentTypeBaseService<TContentTypeComposition> typeService,
IContentServiceBase<TContentBase> service)
where TContentBase : class, IContentBase
where TContentTypeComposition : IContentTypeComposition
{
var list = new List<T>();
var list = new List<TContentBase>();
foreach (var child in children)
{
string contentTypeAlias = child.Name.LocalName;
if (importedContentTypes.ContainsKey(contentTypeAlias) == false)
{
var contentType = FindContentTypeByAlias(contentTypeAlias, typeService);
importedContentTypes.Add(contentTypeAlias, contentType);
}
//Create and add the child to the list
// Create and add the child to the list
if (TryCreateContentFromXml(child, importedContentTypes[contentTypeAlias], parent, default, service, out var content))
{
list.Add(content);
}
//Recursive call
var child1 = child;
var grandChildren = (from grand in child1.Elements()
where (string)grand.Attribute("isDoc") == ""
select grand).ToList();
// Recursive call
var grandChildren = child.Elements().Where(x => (string)x.Attribute("isDoc") == string.Empty).ToList();
if (grandChildren.Any())
{
list.AddRange(CreateContentFromXml(grandChildren, content, importedContentTypes, typeService, service));
}
}
return list;
}
private bool TryCreateContentFromXml<T, S>(
private bool TryCreateContentFromXml<TContentBase, TContentTypeComposition>(
XElement element,
S contentType,
T parent,
TContentTypeComposition contentType,
TContentBase parent,
int parentId,
IContentServiceBase<T> service,
out T output)
where T : class, IContentBase
where S : IContentTypeComposition
IContentServiceBase<TContentBase> service,
out TContentBase output)
where TContentBase : class, IContentBase
where TContentTypeComposition : IContentTypeComposition
{
Guid key = element.RequiredAttributeValue<Guid>("key");
@@ -317,7 +304,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
}
}
T content = CreateContent(
TContentBase content = CreateContent(
nodeName,
parent,
parentId,
@@ -384,34 +371,34 @@ namespace Umbraco.Cms.Infrastructure.Packaging
return true;
}
private T CreateContent<T, S>(string name, T parent, int parentId, S contentType, Guid key, int level, int sortOrder, int? templateId)
where T : class, IContentBase
where S : IContentTypeComposition
private TContentBase CreateContent<TContentBase, TContentTypeComposition>(string name, TContentBase parent, int parentId, TContentTypeComposition contentType, Guid key, int level, int sortOrder, int? templateId)
where TContentBase : class, IContentBase
where TContentTypeComposition : IContentTypeComposition
{
switch (contentType)
{
case IContentType c:
if (parent is null)
{
return new Content(name, parentId, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as T;
return new Content(name, parentId, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as TContentBase;
}
else
{
return new Content(name, (IContent)parent, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as T;
return new Content(name, (IContent)parent, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as TContentBase;
}
case IMediaType m:
if (parent is null)
{
return new Core.Models.Media(name, parentId, m) { Key = key, Level = level, SortOrder = sortOrder, } as T;
return new Core.Models.Media(name, parentId, m) { Key = key, Level = level, SortOrder = sortOrder, } as TContentBase;
}
else
{
return new Core.Models.Media(name, (IMedia)parent, m) { Key = key, Level = level, SortOrder = sortOrder, } as T;
return new Core.Models.Media(name, (IMedia)parent, m) { Key = key, Level = level, SortOrder = sortOrder, } as TContentBase;
}
default:
throw new NotSupportedException($"Type {typeof(S)} is not supported");
throw new NotSupportedException($"Type {typeof(TContentTypeComposition)} is not supported");
}
}
@@ -420,9 +407,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
#region DocumentTypes
public IReadOnlyList<IContentType> ImportDocumentType(XElement docTypeElement, int userId)
{
return ImportDocumentTypes(new[] { docTypeElement }, userId);
}
=> ImportDocumentTypes(new[] { docTypeElement }, userId);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
@@ -431,9 +416,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IContentType> ImportDocumentTypes(IEnumerable<XElement> docTypeElements, int userId)
{
return ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService);
}
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
@@ -443,7 +426,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<T> ImportDocumentTypes<T>(IReadOnlyCollection<XElement> unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService<T> service)
where T : class, IContentTypeComposition
where T : class, IContentTypeComposition
{
var importedContentTypes = new Dictionary<string, T>();
@@ -768,8 +751,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
return contentType;
}
private void UpdateContentTypesAllowedTemplates(IContentType contentType,
XElement allowedTemplatesElement, XElement defaultTemplateElement)
private void UpdateContentTypesAllowedTemplates(IContentType contentType, XElement allowedTemplatesElement, XElement defaultTemplateElement)
{
if (allowedTemplatesElement != null && allowedTemplatesElement.Elements("Template").Any())
{
@@ -953,7 +935,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
}
private T UpdateContentTypesStructure<T>(T contentType, XElement structureElement, IReadOnlyDictionary<string, T> importedContentTypes, IContentTypeBaseService<T> service)
where T : IContentTypeComposition
where T : IContentTypeComposition
{
var allowedChildren = contentType.AllowedContentTypes.ToList();
int sortOrder = allowedChildren.Any() ? allowedChildren.Last().SortOrder : 0;
@@ -986,8 +968,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// </summary>
/// <param name="contentTypeAlias"></param>
/// <returns></returns>
private S FindContentTypeByAlias<S>(string contentTypeAlias, IContentTypeBaseService<S> typeService)
where S : IContentTypeComposition
private T FindContentTypeByAlias<T>(string contentTypeAlias, IContentTypeBaseService<T> typeService)
where T : IContentTypeComposition
{
var contentType = typeService.Get(contentTypeAlias);
@@ -1207,12 +1189,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
}
private static bool DictionaryValueIsNew(IEnumerable<IDictionaryTranslation> translations, XElement valueElement)
{
return translations.All(t =>
string.Compare(t.Language.IsoCode, valueElement.Attribute("LanguageCultureAlias").Value,
StringComparison.InvariantCultureIgnoreCase) != 0
);
}
=> translations.All(t => string.Compare(t.Language.IsoCode, valueElement.Attribute("LanguageCultureAlias").Value, StringComparison.InvariantCultureIgnoreCase) != 0);
private static void AddDictionaryTranslation(ICollection<IDictionaryTranslation> translations, XElement valueElement, IEnumerable<ILanguage> languages)
{
@@ -1231,7 +1208,6 @@ namespace Umbraco.Cms.Infrastructure.Packaging
#region Languages
/// <summary>
/// Imports and saves the 'Languages' part of a package xml as a list of <see cref="ILanguage"/>
/// </summary>
@@ -1289,7 +1265,6 @@ namespace Umbraco.Cms.Infrastructure.Packaging
foreach (XElement macroPartialViewXml in macroPartialViewsElements)
{
var path = macroPartialViewXml.AttributeValue<string>("path");
if (path == null)
{
throw new InvalidOperationException("No path attribute found");
@@ -1325,24 +1300,28 @@ namespace Umbraco.Cms.Infrastructure.Packaging
{
useInEditor = bool.Parse(useInEditorElement.Value);
}
var cacheDurationElement = macroElement.Element("refreshRate");
var cacheDuration = 0;
if (cacheDurationElement != null && string.IsNullOrEmpty((string)cacheDurationElement) == false)
{
cacheDuration = int.Parse(cacheDurationElement.Value);
}
var cacheByMemberElement = macroElement.Element("cacheByMember");
var cacheByMember = false;
if (cacheByMemberElement != null && string.IsNullOrEmpty((string)cacheByMemberElement) == false)
{
cacheByMember = bool.Parse(cacheByMemberElement.Value);
}
var cacheByPageElement = macroElement.Element("cacheByPage");
var cacheByPage = false;
if (cacheByPageElement != null && string.IsNullOrEmpty((string)cacheByPageElement) == false)
{
cacheByPage = bool.Parse(cacheByPageElement.Value);
}
var dontRenderElement = macroElement.Element("dontRender");
var dontRender = true;
if (dontRenderElement != null && string.IsNullOrEmpty((string)dontRenderElement) == false)
@@ -1386,6 +1365,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
sortOrder++;
}
}
return macro;
}
@@ -1398,7 +1378,6 @@ namespace Umbraco.Cms.Infrastructure.Packaging
foreach (XElement scriptXml in scriptElements)
{
var path = scriptXml.AttributeValue<string>("path");
if (path.IsNullOrWhiteSpace())
{
continue;
@@ -1462,7 +1441,6 @@ namespace Umbraco.Cms.Infrastructure.Packaging
foreach (XElement n in stylesheetElements)
{
var stylesheetPath = n.Element("FileName")?.Value;
if (stylesheetPath.IsNullOrWhiteSpace())
{
continue;
@@ -1503,9 +1481,11 @@ namespace Umbraco.Cms.Infrastructure.Packaging
sp = newProp;
}
}
sp.Alias = alias;
sp.Value = prop.Element("Value")?.Value;
}
_fileService.SaveStylesheet(s, userId);
result.Add(s);
}
@@ -1518,9 +1498,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
#region Templates
public IEnumerable<ITemplate> ImportTemplate(XElement templateElement, int userId)
{
return ImportTemplates(new[] { templateElement }, userId);
}
=> ImportTemplates(new[] { templateElement }, userId);
/// <summary>
/// Imports and saves package xml as <see cref="ITemplate"/>
@@ -1570,6 +1548,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
var existingTemplate = _fileService.GetTemplate(alias) as Template;
var template = existingTemplate ?? new Template(_shortStringHelper, templateName, alias);
template.Content = design;
if (masterElement != null && string.IsNullOrEmpty((string)masterElement) == false)
{
template.MasterTemplateAlias = masterElement.Value;
@@ -1577,6 +1556,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
if (masterTemplate != null)
template.MasterTemplateId = new Lazy<int>(() => masterTemplate.Id);
}
templates.Add(template);
}