<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Signum.Entities.Authorization;
using Signum.Entities.Basics;
using Signum.Entities.Chart;
using Signum.Entities.Dashboard;

namespace Signum.Entities.UserAssets
{
    [Serializable]
    public class UserAssetPreviewModel : ModelEntity
    {
        public MList<UserAssetPreviewLineEmbedded> Lines { get; set; } = new MList<UserAssetPreviewLineEmbedded>();
    }

    [Serializable]
    public class UserAssetPreviewLineEmbedded : EmbeddedEntity
    {
        public TypeEntity Type { get; set; }

        public string Text { get; set; }

        public EntityAction Action { get; set; }

        public bool OverrideEntity { get; set; }

        public Guid Guid { get; set; }

        [HiddenProperty]
        public bool OverrideVisible
        {
            get { return Action == EntityAction.Different; }
        }
    }

    public enum EntityAction
    {
        Identical,
        Different,
        New,
    }

    public enum UserAssetMessage
    {
        ExportToXml,
        ImportUserAssets,
        ImportPreview,
        SelectTheXmlFileWithTheUserAssetsThatYouWantToImport,
        SelectTheEntitiesToOverride,
        SucessfullyImported,
    }

    [AutoInit]
    public static class UserAssetPermission
    {
        public static PermissionSymbol UserAssetsToXML;
    }

    public interface IToXmlContext
    {
        Guid Include(IUserAssetEntity content);
        Guid Include(Lite<IUserAssetEntity> content);

        string TypeToName(Lite<TypeEntity> type);

        string QueryToName(Lite<QueryEntity> query);
    }

    public interface IFromXmlContext
    {
        QueryEntity GetQuery(string queryKey);
        Lite<TypeEntity> GetType(string cleanName);

        ChartScriptEntity ChartScript(string chartScriptName);

        IUserAssetEntity GetEntity(Guid guid);

        IPartEntity GetPart(IPartEntity old, XElement element);

        DynamicQuery.QueryDescription GetQueryDescription(QueryEntity Query);
    }

    public interface IUserAssetEntity : IEntity
    {
        Guid Guid { get; set; }

        XElement ToXml(IToXmlContext ctx);

        void FromXml(XElement element, IFromXmlContext ctx);
    }

    public static class FromXmlExtensions
    {
        public static void Synchronize<T>(this MList<T> entities, List<XElement> xElements, Action<T, XElement> syncAction)
            where T : new()
        {
            for (int i = 0; i < xElements.Count; i++)
            {
                T entity;
                if (entities.Count == i)
                {
                    entity = new T();
                    entities.Add(entity);
                }<commit_msg>fix UserAssets Synchronize<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Signum.Entities.Authorization;
using Signum.Entities.Basics;
using Signum.Entities.Chart;
using Signum.Entities.Dashboard;

namespace Signum.Entities.UserAssets
{
    [Serializable]
    public class UserAssetPreviewModel : ModelEntity
    {
        public MList<UserAssetPreviewLineEmbedded> Lines { get; set; } = new MList<UserAssetPreviewLineEmbedded>();
    }

    [Serializable]
    public class UserAssetPreviewLineEmbedded : EmbeddedEntity
    {
        public TypeEntity Type { get; set; }

        public string Text { get; set; }

        public EntityAction Action { get; set; }

        public bool OverrideEntity { get; set; }

        public Guid Guid { get; set; }

        [HiddenProperty]
        public bool OverrideVisible
        {
            get { return Action == EntityAction.Different; }
        }
    }

    public enum EntityAction
    {
        Identical,
        Different,
        New,
    }

    public enum UserAssetMessage
    {
        ExportToXml,
        ImportUserAssets,
        ImportPreview,
        SelectTheXmlFileWithTheUserAssetsThatYouWantToImport,
        SelectTheEntitiesToOverride,
        SucessfullyImported,
    }

    [AutoInit]
    public static class UserAssetPermission
    {
        public static PermissionSymbol UserAssetsToXML;
    }

    public interface IToXmlContext
    {
        Guid Include(IUserAssetEntity content);
        Guid Include(Lite<IUserAssetEntity> content);

        string TypeToName(Lite<TypeEntity> type);

        string QueryToName(Lite<QueryEntity> query);
    }

    public interface IFromXmlContext
    {
        QueryEntity GetQuery(string queryKey);
        Lite<TypeEntity> GetType(string cleanName);

        ChartScriptEntity ChartScript(string chartScriptName);

        IUserAssetEntity GetEntity(Guid guid);

        IPartEntity GetPart(IPartEntity old, XElement element);

        DynamicQuery.QueryDescription GetQueryDescription(QueryEntity Query);
    }

    public interface IUserAssetEntity : IEntity
    {
        Guid Guid { get; set; }

        XElement ToXml(IToXmlContext ctx);

        void FromXml(XElement element, IFromXmlContext ctx);
    }

    public static class FromXmlExtensions
    {
        public static void Synchronize<T>(this MList<T> entities, List<XElement> xElements, Action<T, XElement> syncAction)
            where T : new()
        {

            if (xElements == null)
                xElements = new List<XElement>();


            for (int i = 0; i < xElements.Count; i++)
            {
                T entity;
                if (entities.Count == i)
                {
                    entity = new T();
                    entities.Add(entity);
                }
{'fraction_non_alphanumeric': 0.07375734901122394, 'fraction_numerical': 0.0003563156957063959, 'mean_word_length': 2.3297746144721234, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 24, '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': '2397059', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1495, 'n_words': 372}