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 PropertyRouteHelpEntity { Property = fromProp.Property, Description = dic.GetOrThrow(fromProp.Description) }); } else if(!prop.Description.HasText()) { prop.Description = dic.GetOrThrow(fromProp.Description); } } entity.Execute(EntityHelpOperation.Save); }
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 PropertyRouteHelpEntity { 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; })); }