static void AsignTranslatedQuery(QueryHelpEntity query, QueryHelpEntity fromQuery)
        {
            HashSet<string> toTranslate = new HashSet<string>();
            if (!query.Description.HasText() && fromQuery.Description.HasText())
                toTranslate.Add(fromQuery.Description);

            foreach (var fromProp in fromQuery.Columns)
            {
                var prop = query.Columns.SingleOrDefaultEx(p => p.ColumnName == fromProp.ColumnName);

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

            Dictionary<string, string> dic = Translate(toTranslate, fromQuery.Culture.Name, query.Culture.Name);

            if (!query.Description.HasText() && fromQuery.Description.HasText())
                query.Description = dic.GetOrThrow(fromQuery.Description);

            foreach (var fromProp in fromQuery.Columns)
            {
                var col = query.Columns.SingleOrDefaultEx(p => p.ColumnName == fromProp.ColumnName);

                if (col == null)
                {
                    query.Columns.Add(new QueryColumnHelpEntity
                    {
                        ColumnName = fromProp.ColumnName,
                        Description = dic.GetOrThrow(fromProp.Description)
                    });
                }
                else if (!col.Description.HasText())
                {
                    col.Description = dic.GetOrThrow(fromProp.Description);
                }
            }

            query.Execute(QueryHelpOperation.Save);
        }
Exemple #2
0
        public QueryHelp(object queryName, CultureInfo ci, QueryHelpEntity entity)
        {
            QueryName = queryName;
            Culture = ci;
            Info = HelpGenerator.GetQueryHelp(DynamicQueryManager.Current.GetQuery(queryName).Core.Value);
            Columns = DynamicQueryManager.Current.GetQuery(queryName).Core.Value.StaticColumns.ToDictionary(
                            cf => cf.Name,
                            cf => new QueryColumnHelp(cf, cf.DisplayName(), HelpGenerator.GetQueryColumnHelp(cf)));

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

                UserDescription = entity.Description;

                foreach (var tranColumn in entity.Columns)
                {
                    Columns.GetOrThrow(tranColumn.ColumnName).UserDescription = tranColumn.Description;
                }
            }

            Entity = new Lazy<QueryHelpEntity>(() => HelpLogic.GlobalContext(() =>
            {
                if (entity == null)
                    entity = new QueryHelpEntity
                    {
                        Culture = this.Culture.ToCultureInfoEntity(),
                        Query = QueryLogic.GetQueryEntity(this.QueryName),
                    };

                entity.Columns.AddRange(
                     DynamicQueryManager.Current.GetQuery(this.QueryName).Core.Value.StaticColumns.Select(a => a.Name)
                     .Except(entity.Columns.Select(a => a.ColumnName))
                     .Select(pr => new QueryColumnHelpEntity
                     {
                         ColumnName = pr,
                         Description = null,
                     }));

                return entity;
            }));
        }