<commit_before>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;

using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Services;

using uSync8.ContentEdition.Mapping;
using uSync8.Core.Extensions;
using uSync8.Core.Serialization;

namespace uSync8.ContentEdition.Serializers
{
    public abstract class ContentSerializerBase<TObject> : SyncTreeSerializerBase<TObject>
        where TObject : IContentBase
    {
        protected UmbracoObjectTypes umbracoObjectType;
        protected SyncValueMapperCollection syncMappers;

        protected ILocalizationService localizationService;

        protected Dictionary<string, string> pathCache;

        public ContentSerializerBase(
            IEntityService entityService,
            ILocalizationService localizationService,
            ILogger logger,
            UmbracoObjectTypes umbracoObjectType,
            SyncValueMapperCollection syncMappers)
            : base(entityService, logger)
        {
            this.umbracoObjectType = umbracoObjectType;
            this.syncMappers = syncMappers;

            this.localizationService = localizationService;

            this.pathCache = new Dictionary<string, string>();
        }

        protected virtual XElement InitializeNode(TObject item, string typeName)
        {
            var node = new XElement(this.ItemType,
                new XAttribute("Key", item.Key),
                new XAttribute("Alias", item.Name),
                new XAttribute("Level", item.Level));

            return node;
        }

        protected virtual XElement SerializeInfo(TObject item)
        {
            var info = new XElement("Info");

            var parentKey = Guid.Empty;
            var parentName = "";
            if (item.ParentId != -1)
            {
                var parent = FindItem(item.ParentId);
                if (parent != null)
                {
                    parentKey = parent.Key;
                    parentName = parent.Name;
                }
            }

            info.Add(new XElement("Parent", new XAttribute("Key", parentKey), parentName));
            info.Add(new XElement("Path", GetItemPath(item)));
            info.Add(new XElement("Trashed", item.Trashed));
            info.Add(new XElement("ContentType", item.ContentType.Alias));
            info.Add(new XElement("CreateDate", item.CreateDate));

            info.Add(new XElement("Version", item.VersionId));

            var title = new XElement("NodeName", new XAttribute("Default", item.Name));
            foreach (var culture in item.AvailableCultures)
            {
                title.Add(new XElement("Name", item.GetCultureName(culture),
                    new XAttribute("Culture", culture)));
            }<commit_msg>rollback - dont' serialize version<commit_after>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;

using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Services;

using uSync8.ContentEdition.Mapping;
using uSync8.Core.Extensions;
using uSync8.Core.Serialization;

namespace uSync8.ContentEdition.Serializers
{
    public abstract class ContentSerializerBase<TObject> : SyncTreeSerializerBase<TObject>
        where TObject : IContentBase
    {
        protected UmbracoObjectTypes umbracoObjectType;
        protected SyncValueMapperCollection syncMappers;

        protected ILocalizationService localizationService;

        protected Dictionary<string, string> pathCache;

        public ContentSerializerBase(
            IEntityService entityService,
            ILocalizationService localizationService,
            ILogger logger,
            UmbracoObjectTypes umbracoObjectType,
            SyncValueMapperCollection syncMappers)
            : base(entityService, logger)
        {
            this.umbracoObjectType = umbracoObjectType;
            this.syncMappers = syncMappers;

            this.localizationService = localizationService;

            this.pathCache = new Dictionary<string, string>();
        }

        protected virtual XElement InitializeNode(TObject item, string typeName)
        {
            var node = new XElement(this.ItemType,
                new XAttribute("Key", item.Key),
                new XAttribute("Alias", item.Name),
                new XAttribute("Level", item.Level));

            return node;
        }

        protected virtual XElement SerializeInfo(TObject item)
        {
            var info = new XElement("Info");

            var parentKey = Guid.Empty;
            var parentName = "";
            if (item.ParentId != -1)
            {
                var parent = FindItem(item.ParentId);
                if (parent != null)
                {
                    parentKey = parent.Key;
                    parentName = parent.Name;
                }
            }

            info.Add(new XElement("Parent", new XAttribute("Key", parentKey), parentName));
            info.Add(new XElement("Path", GetItemPath(item)));
            info.Add(new XElement("Trashed", item.Trashed));
            info.Add(new XElement("ContentType", item.ContentType.Alias));
            info.Add(new XElement("CreateDate", item.CreateDate));

            var title = new XElement("NodeName", new XAttribute("Default", item.Name));
            foreach (var culture in item.AvailableCultures)
            {
                title.Add(new XElement("Name", item.GetCultureName(culture),
                    new XAttribute("Culture", culture)));
            }
{'fraction_non_alphanumeric': 0.08950026118753265, 'fraction_numerical': 0.0017412502176562773, 'mean_word_length': 2.230596175478065, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2012034', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1443, 'n_words': 322}