Beispiel #1
0
        public static QueryHelpService GetQueryHelpService(object queryName)
        {
            var entity = GetQueryHelp(queryName);

            var url = HelpUrls.QueryUrl(queryName);

            return(new QueryHelpService
            {
                QueryName = queryName,

                Info = GetHelpToolTipInfo(QueryUtils.GetNiceName(queryName), entity.Info, entity.UserDescription, url),

                Columns = entity.Columns.Where(a => a.Value.IsAllowed() == null).ToDictionary(kvp => kvp.Key, kvp =>
                                                                                              GetHelpToolTipInfo(kvp.Value.NiceName, kvp.Value.Info, kvp.Value.UserDescription, url)),
            });
        }
Beispiel #2
0
        public static SearchResult Search(this AppendixHelp entity, Regex regex)
        {
            {
                Match m = regex.Match(entity.Title.RemoveDiacritics());
                if (m.Success)
                {
                    return(new SearchResult(TypeSearchResult.Appendix, entity.Title, entity.Description.Etc(etcLength).DefaultText(entity.Title), null, m,
                                            HelpUrls.AppendixUrl(entity.UniqueName)));
                }
            }

            if (entity.Description.HasText())
            {
                Match m = regex.Match(entity.Description.RemoveDiacritics());
                if (m.Success)
                {
                    return(new SearchResult(TypeSearchResult.Appendix, entity.Title, entity.Description.Extract(m), null, m, HelpUrls.AppendixUrl(entity.UniqueName), isDescription: true));
                }
            }

            return(null);
        }
Beispiel #3
0
        public static WikiLink LinkParser(string content)
        {
            Match m = HelpLogic.HelpLinkRegex.Match(content);

            if (m.Success)
            {
                string letter = m.Groups["letter"].ToString();
                string link   = m.Groups["link"].ToString();
                string text   = m.Groups["text"].ToString();

                switch (letter)
                {
                case WikiFormat.EntityLink:
                    Type t = TypeLogic.TryGetType(link);
                    return(new WikiLink(
                               HelpUrls.EntityUrl(t),
                               text.HasText() ? text : t.NiceName()));

                case WikiFormat.Hyperlink:
                    return(new WikiLink(link, text));

                case WikiFormat.OperationLink:
                    OperationSymbol operation = SymbolLogic <OperationSymbol> .TryToSymbol(link);

                    List <Type> types = OperationLogic.FindTypes(operation).Where(TypeLogic.TypeToEntity.ContainsKey).ToList();
                    if (types.Count == 1)
                    {
                        return(new WikiLink(
                                   HelpUrls.OperationUrl(types[0], operation),
                                   text.HasText() ? text : operation.NiceToString()));
                    }
                    else
                    {
                        return(new MultiWikiLink(operation.NiceToString())
                        {
                            Links = types.Select(currentType =>
                                                 new WikiLink(
                                                     HelpUrls.OperationUrl(currentType, operation),
                                                     currentType.NiceName(), operation.NiceToString())).ToList()
                        });
                    }

                case WikiFormat.PropertyLink:
                    PropertyRoute route = PropertyRoute.Parse(TypeLogic.TryGetType(link.Before('.')), link.After('.'));

                    while (route.PropertyRouteType == PropertyRouteType.LiteEntity ||
                           route.PropertyRouteType == PropertyRouteType.Mixin ||
                           route.PropertyRouteType == PropertyRouteType.MListItems)
                    {
                        route = route.Parent;
                    }

                    return(new WikiLink(HelpUrls.PropertyUrl(route), route.PropertyInfo.NiceName()));

                case WikiFormat.QueryLink:
                    object o = QueryLogic.TryToQueryName(link);
                    if (o as Enum != null)
                    {
                        Enum query = (Enum)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }
                    else
                    {
                        Type query = (Type)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }

                case WikiFormat.NamespaceLink:
                    NamespaceHelp nameSpace = HelpLogic.GetNamespaceHelp(link);
                    return(new WikiLink(
                               HelpUrls.NamespaceUrl(link),
                               text.HasText() ? text : link,
                               nameSpace != null ? "" : "unavailable"));

                case WikiFormat.AppendixLink:
                    AppendixHelp appendix = HelpLogic.GetAppendixHelp(link);
                    return(new WikiLink(
                               HelpUrls.AppendixUrl(link),
                               text.HasText() ? text : link,
                               appendix != null ? "" : "unavailable"));
                }
            }
            return(null);
        }
Beispiel #4
0
        public static Dictionary <PropertyRoute, HelpToolTipInfo> GetPropertyRoutesService(List <PropertyRoute> routes)
        {
            return(routes.Where(p => p.IsAllowed() == null).GroupBy(a => a.RootType).SelectMany(r =>
            {
                var entity = GetEntityHelp(r.Key);

                return r.Select(pr =>
                {
                    var simp = pr.SimplifyToPropertyOrRoot();

                    if (simp.PropertyRouteType == PropertyRouteType.Root)
                    {
                        return KVP.Create(pr, GetHelpToolTipInfo(simp.RootType.NiceName(), entity.Info, entity.Description, HelpUrls.EntityUrl(pr.RootType)));
                    }
                    else
                    {
                        var prop = entity.Properties.GetOrThrow(simp);

                        return KVP.Create(pr, GetHelpToolTipInfo(prop.PropertyInfo.NiceName(), prop.Info, prop.UserDescription, HelpUrls.PropertyUrl(pr)));
                    }
                });
            }).ToDictionary());
        }
Beispiel #5
0
        public static EntityHelpService GetEntityHelpService(Type type)
        {
            var entity = GetEntityHelp(type);

            return(new EntityHelpService
            {
                Type = type,

                Info = GetHelpToolTipInfo(type.NiceName(), entity.Info, entity.Description, HelpUrls.EntityUrl(type)),

                Operations = entity.Operations.Where(o => o.Value.IsAllowed() == null).ToDictionary(kvp => kvp.Key,
                                                                                                    kvp => GetHelpToolTipInfo(kvp.Value.OperationSymbol.NiceToString(), kvp.Value.Info, kvp.Value.UserDescription, HelpUrls.OperationUrl(type, kvp.Value.OperationSymbol))),

                Properties = entity.Properties.Where(o => o.Value.IsAllowed() == null).ToDictionary(kvp => kvp.Key,
                                                                                                    kvp => GetHelpToolTipInfo(kvp.Value.PropertyInfo.NiceName(), kvp.Value.Info, kvp.Value.UserDescription, HelpUrls.PropertyUrl(kvp.Value.PropertyRoute))),
            });
        }
Beispiel #6
0
        public static IEnumerable <SearchResult> Search(this EntityHelp entity, Regex regex)
        {
            Type type = entity.Type;

            //Types
            Match m;

            m = regex.Match(type.NiceName().RemoveDiacritics());
            if (m.Success)
            {
                yield return(new SearchResult(TypeSearchResult.Type, type.NiceName(), entity.Description.DefaultText(entity.Info).Etc(etcLength), type, m, HelpUrls.EntityUrl(type)));

                yield break;
            }


            //Types description
            if (entity.Description.HasText())
            {
                // TODO: Some times the rendered Description does not contain the query term and it looks strange. Description should be
                // wiki-parsed and then make the search over this string
                if (m.Success)
                {
                    yield return(new SearchResult(TypeSearchResult.Type, type.NiceName(), entity.Description.Extract(m), type, m, HelpUrls.EntityUrl(type), isDescription: true));

                    yield break;
                }
            }


            //Properties (key)
            foreach (var p in  entity.Properties.Values)
            {
                if (p.PropertyInfo != null)
                {
                    m = regex.Match(p.PropertyInfo.NiceName().RemoveDiacritics());
                    if (m.Success)
                    {
                        yield return(new SearchResult(TypeSearchResult.Property, p.PropertyInfo.NiceName(), p.UserDescription.DefaultText(p.Info).Etc(etcLength), type, m,
                                                      HelpUrls.PropertyUrl(p.PropertyRoute)));

                        continue;
                    }
                }
                else if (p.UserDescription.HasText())
                {
                    m = regex.Match(p.UserDescription.RemoveDiacritics());
                    if (m.Success)
                    {
                        yield return(new SearchResult(TypeSearchResult.Property, p.PropertyInfo?.NiceName(), p.UserDescription.Extract(m), type, m,
                                                      HelpUrls.PropertyUrl(p.PropertyRoute), isDescription: true));
                    }
                }
            }

            //Queries (key)
            foreach (var p in entity.Queries.Values)
            {
                m = regex.Match(QueryUtils.GetNiceName(p.QueryName).RemoveDiacritics());
                if (m.Success)
                {
                    yield return(new SearchResult(TypeSearchResult.Query, QueryUtils.GetNiceName(p.QueryName), p.UserDescription.DefaultText(p.Info).Etc(etcLength), type, m,
                                                  HelpUrls.QueryUrl(p.QueryName, type)));
                }
                else if (p.UserDescription.HasText())
                {
                    m = regex.Match(p.UserDescription.ToString().RemoveDiacritics());
                    if (m.Success)
                    {
                        yield return(new SearchResult(TypeSearchResult.Query, QueryUtils.GetNiceName(p.QueryName), p.UserDescription.Extract(m), type, m,
                                                      HelpUrls.QueryUrl(p.QueryName, type), isDescription: true));
                    }
                }
            }

            //Operations (key)
            foreach (var op in entity.Operations.Values)
            {
                m = regex.Match(op.OperationSymbol.NiceToString().RemoveDiacritics());
                if (m.Success)
                {
                    yield return(new SearchResult(TypeSearchResult.Operation, op.OperationSymbol.NiceToString(), op.UserDescription.DefaultText(op.Info).Etc(etcLength), type, m,
                                                  HelpUrls.OperationUrl(type, op.OperationSymbol)));
                }
                else if (op.UserDescription.HasText())
                {
                    m = regex.Match(op.UserDescription.ToString().RemoveDiacritics());
                    if (m.Success)
                    {
                        yield return(new SearchResult(TypeSearchResult.Operation, op.OperationSymbol.NiceToString(), op.UserDescription.Extract(m), type, m,
                                                      HelpUrls.OperationUrl(type, op.OperationSymbol), isDescription: true));
                    }
                }
            }
        }
Beispiel #7
0
        public static SearchResult?Search(this NamespaceHelp entity, Regex regex)
        {
            {
                Match m = regex.Match(entity.Title.RemoveDiacritics());
                if (m.Success)
                {
                    return(new SearchResult(TypeSearchResult.Namespace, entity.Title, entity.Description.Try(d => d.Etc(etcLength)).DefaultText(entity.Title), null, m, HelpUrls.NamespaceUrl(entity.Namespace)));
                }
            }

            if (entity.Description.HasText())
            {
                Match m = regex.Match(entity.Description.RemoveDiacritics());
                if (m.Success)
                {
                    return(new SearchResult(TypeSearchResult.Namespace, entity.Title, entity.Description.Extract(m), null, m, HelpUrls.NamespaceUrl(entity.Namespace), isDescription: true));
                }
            }

            return(null);
        }