Netcore: Migration of Model classes from Umbraco.Infrastructure to Core (#9404)

* Migrating more model, mapping and tree classes

* Migrating files from Mapping dir without Newtonsoft dependency

* Migrating files from PublishedContent and Editors dirs without Newtonsoft dependency + some more of the same kind

* Migrating DataType class without the usage of Newtonsoft.Json and making the corresponding changes to all classes affected

* Combining 3 ContentExtensions files into 1

* Refactoring from migrating ContentExtensions

* Migrating more classes

* Migrating ContentRepositoryExtensions - combining it with existing file in Umbraco.Core

* removing Newtonsoft json dependency & migrating file. Adding partial migration of ConfigurationEditor, so PropertyTagsExtensions can be migrated

* Migrating ContentTagsExtensions, and refactoring from changes in PropertyTagsExtensions

* Changes that should be reverted once ConfigurationEditor class is fully migrated

* VS couldn't find Composing, so build was failing. Removing the using solves the problem

* Handling a single case for deserializing a subset of an input

* Small changes and added tests to JsonNetSerializer

Signed-off-by: Bjarke Berg <mail@bergmania.dk>

* Migrated ConfigurationEditor

Signed-off-by: Bjarke Berg <mail@bergmania.dk>

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Elitsa Marinovska
2020-11-17 20:27:10 +01:00
committed by GitHub
parent d498c1a2cd
commit dd5f400cf3
116 changed files with 1098 additions and 897 deletions

View File

@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
/// <inheritdoc />
/// <summary>
/// The dictionary model mapper.
/// </summary>
public class DictionaryMapDefinition : IMapDefinition
{
private readonly ILocalizationService _localizationService;
public DictionaryMapDefinition(ILocalizationService localizationService)
{
_localizationService = localizationService;
}
public void DefineMaps(UmbracoMapper mapper)
{
mapper.Define<IDictionaryItem, EntityBasic>((source, context) => new EntityBasic(), Map);
mapper.Define<IDictionaryItem, DictionaryDisplay>((source, context) => new DictionaryDisplay(), Map);
mapper.Define<IDictionaryItem, DictionaryOverviewDisplay>((source, context) => new DictionaryOverviewDisplay(), Map);
}
// Umbraco.Code.MapAll -ParentId -Path -Trashed -Udi -Icon
private static void Map(IDictionaryItem source, EntityBasic target, MapperContext context)
{
target.Alias = source.ItemKey;
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.ItemKey;
}
// Umbraco.Code.MapAll -Icon -Trashed -Alias
private void Map(IDictionaryItem source, DictionaryDisplay target, MapperContext context)
{
target.Id = source.Id;
target.Key = source.Key;
target.Name = source.ItemKey;
target.ParentId = source.ParentId ?? Guid.Empty;
target.Udi = Udi.Create(Constants.UdiEntityType.DictionaryItem, source.Key);
// build up the path to make it possible to set active item in tree
// TODO: check if there is a better way
if (source.ParentId.HasValue)
{
var ids = new List<int> { -1 };
var parentIds = new List<int>();
GetParentId(source.ParentId.Value, _localizationService, parentIds);
parentIds.Reverse();
ids.AddRange(parentIds);
ids.Add(source.Id);
target.Path = string.Join(",", ids);
}
else
{
target.Path = "-1," + source.Id;
}
// add all languages and the translations
foreach (var lang in _localizationService.GetAllLanguages())
{
var langId = lang.Id;
var translation = source.Translations.FirstOrDefault(x => x.LanguageId == langId);
target.Translations.Add(new DictionaryTranslationDisplay
{
IsoCode = lang.IsoCode,
DisplayName = lang.CultureInfo.DisplayName,
Translation = (translation != null) ? translation.Value : string.Empty,
LanguageId = lang.Id
});
}
}
// Umbraco.Code.MapAll -Level -Translations
private void Map(IDictionaryItem source, DictionaryOverviewDisplay target, MapperContext context)
{
target.Id = source.Id;
target.Name = source.ItemKey;
// add all languages and the translations
foreach (var lang in _localizationService.GetAllLanguages())
{
var langId = lang.Id;
var translation = source.Translations.FirstOrDefault(x => x.LanguageId == langId);
target.Translations.Add(
new DictionaryOverviewTranslationDisplay
{
DisplayName = lang.CultureInfo.DisplayName,
HasTranslation = translation != null && string.IsNullOrEmpty(translation.Value) == false
});
}
}
private static void GetParentId(Guid parentId, ILocalizationService localizationService, List<int> ids)
{
var dictionary = localizationService.GetDictionaryItemById(parentId);
if (dictionary == null)
return;
ids.Add(dictionary.Id);
if (dictionary.ParentId.HasValue)
GetParentId(dictionary.ParentId.Value, localizationService, ids);
}
}
}