Пример #1
0
        static void AssignTranslatedEntity(EntityHelpEntity entity, EntityHelpEntity fromEntity)
        {
            HashSet <string> toTranslate = new HashSet <string>();

            if (!entity.Description.HasText() && fromEntity.Description.HasText())
            {
                toTranslate.Add(fromEntity.Description);
            }

            foreach (var fromProp in fromEntity.Properties)
            {
                var prop = entity.Properties.SingleOrDefaultEx(p => p.Property.Is(fromProp.Property));

                if (prop == null || !prop.Description.HasText())
                {
                    toTranslate.Add(fromProp.Description);
                }
            }

            Dictionary <string, string> dic = Translate(toTranslate, fromEntity.Culture.Name, entity.Culture.Name);

            if (!entity.Description.HasText() && fromEntity.Description.HasText())
            {
                entity.Description = dic.GetOrThrow(fromEntity.Description);
            }

            foreach (var fromProp in fromEntity.Properties)
            {
                var prop = entity.Properties.SingleOrDefaultEx(p => p.Property.Is(fromProp.Property));

                if (prop == null)
                {
                    entity.Properties.Add(new PropertyRouteHelpEmbedded
                    {
                        Property    = fromProp.Property,
                        Description = dic.GetOrThrow(fromProp.Description)
                    });
                }
                else if (!prop.Description.HasText())
                {
                    prop.Description = dic.GetOrThrow(fromProp.Description);
                }
            }

            entity.Execute(EntityHelpOperation.Save);
        }
Пример #2
0
        public static void AssignTranslatedFullEntity(this EntityHelpEntity entity, CultureInfoEntity fromCulture)
        {
            var fromEntity = Database.Query <EntityHelpEntity>().SingleOrDefaultEx(e => e.Type == entity.Type && e.Culture == fromCulture);

            if (fromEntity != null)
            {
                AssignTranslatedEntity(entity, fromEntity);
            }

            var queries = HelpLogic.TypeToQuery.Value.TryGetC(entity.Type.ToType()).EmptyIfNull().Select(QueryLogic.GetQueryEntity).ToList();

            foreach (var q in queries)
            {
                var fromQuery = Database.Query <QueryHelpEntity>().SingleOrDefaultEx(e => e.Query == q && e.Culture == fromCulture);

                if (fromQuery != null)
                {
                    var query = Database.Query <QueryHelpEntity>().SingleOrDefaultEx(e => e.Query == q && e.Culture == entity.Culture) ??
                                new QueryHelpEntity {
                        Culture = entity.Culture, Query = q
                    };

                    AsignTranslatedQuery(query, fromQuery);
                }
            }

            var operations = OperationLogic.GetAllOperationInfos(entity.Type.ToType()).Select(o => o.OperationSymbol).ToList();

            foreach (var oper in operations)
            {
                var fromOper = Database.Query <OperationHelpEntity>().SingleOrDefaultEx(e => e.Operation == oper && e.Culture == fromCulture);

                if (fromOper != null)
                {
                    var operation = Database.Query <OperationHelpEntity>().SingleOrDefaultEx(e => e.Operation == oper && e.Culture == entity.Culture) ??
                                    new OperationHelpEntity {
                        Culture = entity.Culture, Operation = oper
                    };

                    AsignTranslatedOperation(operation, fromOper);
                }
            }
        }
Пример #3
0
 public static XDocument ToXDocument(EntityHelpEntity entity)
 {
     return(new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(_Entity,
                             new XAttribute(_FullName, entity.Type.FullClassName),
                             new XAttribute(_Culture, entity.Culture.Name),
                             entity.Description.HasText() ? new XElement(_Description, entity.Description) : null,
                             entity.Properties.Any() ? new XElement(_Properties,
                                                                    entity.Properties.Select(p => new XElement(_Property,
                                                                                                               new XAttribute(_Name, p.Property.Path),
                                                                                                               p.Description))
                                                                    ) : null,
                             entity.Operations.Any() ? new XElement(_Operations,
                                                                    entity.Operations.Select(o => new XElement(_Operation,
                                                                                                               new XAttribute(_Key, o.Operation.Key),
                                                                                                               o.Description))
                                                                    ) : null
                             )
                ));
 }
Пример #4
0
        public EntityHelp(Type type, CultureInfo culture, EntityHelpEntity entity)
        {
            Type    = type;
            Culture = culture;
            Info    = HelpGenerator.GetEntityHelp(type);

            Properties = PropertyRoute.GenerateRoutes(type)
                         .ToDictionary(
                pp => pp,
                pp => new PropertyHelp(pp, HelpGenerator.GetPropertyHelp(pp)));


            var allOperations = HelpLogic.CachedOperationsHelp();

            Operations = OperationLogic.GetAllOperationInfos(type).Select(oi => allOperations.GetOrThrow(oi.OperationSymbol)).ToDictionary(a => a.OperationSymbol);

            var allQueries = HelpLogic.CachedQueriesHelp();

            Queries = HelpLogic.TypeToQuery.Value.TryGetC(this.Type).EmptyIfNull().Select(a => allQueries.GetOrThrow(a)).ToDictionary(qh => qh.QueryName);

            if (entity != null)
            {
                HasEntity = true;

                Description = entity.Description;

                foreach (var tranProp in entity.Properties)
                {
                    Properties.GetOrThrow(tranProp.Property.ToPropertyRoute()).UserDescription = tranProp.Description;
                }

                foreach (var transOper in entity.Operations)
                {
                    Operations.GetOrThrow(transOper.Operation).UserDescription = transOper.Description;
                }
            }

            Entity = new Lazy <EntityHelpEntity>(() => HelpLogic.GlobalContext(() =>
            {
                if (entity == null)
                {
                    entity = new EntityHelpEntity
                    {
                        Culture = this.Culture.ToCultureInfoEntity(),
                        Type    = this.Type.ToTypeEntity(),
                    }
                }
                ;

                entity.Properties.AddRange(
                    PropertyRouteLogic.RetrieveOrGenerateProperties(this.Type.ToTypeEntity())
                    .Except(entity.Properties.Select(a => a.Property))
                    .Select(pr => new PropertyRouteHelpEmbedded
                {
                    Property    = pr,
                    Description = null,
                }));

                entity.Operations.AddRange(this.Operations.Values.Select(o => o.Entity.Value).ToList());

                entity.Queries.AddRange(this.Queries.Values.Select(a => a.Entity.Value).ToList());

                return(entity);
            }));
        }