Beispiel #1
0
            QueryEntity?IFromXmlContext.TryGetQuery(string queryKey)
            {
                var qn = QueryLogic.TryToQueryName(queryKey);

                if (qn == null)
                {
                    return(null);
                }

                return(QueryLogic.GetQueryEntity(qn));
            }
Beispiel #2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                QueryLogic.Start(sb, dqm);

                dqm.AllowQuery += new Func <object, bool, bool>(dqm_AllowQuery);

                cache = new AuthCache <RuleQueryEntity, QueryAllowedRule, QueryEntity, object, QueryAllowed>(sb,
                                                                                                             qn => QueryLogic.ToQueryName(qn.Key),
                                                                                                             QueryLogic.GetQueryEntity,
                                                                                                             merger: new QueryMerger(),
                                                                                                             invalidateWithTypes: true,
                                                                                                             coercer: QueryCoercer.Instance);

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Queries", "Query", QueryUtils.GetKey, b => b.ToString(),
                                                                      exportAll ? QueryLogic.QueryNames.Values.ToList(): null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(QueryEntity).Name;

                    replacements.AskForReplacements(
                        x.Element("Queries").Elements("Role").SelectMany(r => r.Elements("Query")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
                        QueryLogic.QueryNames.Keys.ToHashSet(),
                        replacementKey);

                    return(cache.ImportXml(x, "Queries", "Query", roles, s =>
                    {
                        var qn = QueryLogic.TryToQueryName(replacements.Apply(replacementKey, s));

                        if (qn == null)
                        {
                            return null;
                        }

                        return QueryLogic.GetQueryEntity(qn);
                    }, str =>
                    {
                        if (Enum.TryParse <QueryAllowed>(str, out var result))
                        {
                            return result;
                        }

                        var bResult = bool.Parse(str); //For backwards compatibilityS
                        return bResult ? QueryAllowed.Allow : QueryAllowed.None;
                    }));
                };
            }
        }
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 void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                QueryLogic.Start(sb);

                QueryLogic.Queries.AllowQuery += new Func <object, bool, bool>(dqm_AllowQuery);

                sb.Include <RuleQueryEntity>()
                .WithUniqueIndex(rt => new { rt.Resource, rt.Role });

                cache = new AuthCache <RuleQueryEntity, QueryAllowedRule, QueryEntity, object, QueryAllowed>(sb,
                                                                                                             toKey: qn => QueryLogic.ToQueryName(qn.Key),
                                                                                                             toEntity: QueryLogic.GetQueryEntity,
                                                                                                             isEquals: (q1, q2) => q1 == q2,
                                                                                                             merger: new QueryMerger(),
                                                                                                             invalidateWithTypes: true,
                                                                                                             coercer: QueryCoercer.Instance);

                sb.Schema.EntityEvents <RoleEntity>().PreUnsafeDelete += query =>
                {
                    Database.Query <RuleQueryEntity>().Where(r => query.Contains(r.Role.Entity)).UnsafeDelete();
                    return(null);
                };

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Queries", "Query", QueryUtils.GetKey, b => b.ToString(),
                                                                      exportAll ? QueryLogic.QueryNames.Values.ToList(): null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(QueryEntity).Name;

                    replacements.AskForReplacements(
                        x.Element("Queries") !.Elements("Role").SelectMany(r => r.Elements("Query")).Select(p => p.Attribute("Resource") !.Value).ToHashSet(),
                        QueryLogic.QueryNames.Keys.ToHashSet(),
                        replacementKey);

                    return(cache.ImportXml(x, "Queries", "Query", roles, s =>
                    {
                        var qn = QueryLogic.TryToQueryName(replacements.Apply(replacementKey, s));

                        if (qn == null)
                        {
                            return null;
                        }

                        return QueryLogic.GetQueryEntity(qn);
                    }, str =>
                    {
                        if (Enum.TryParse <QueryAllowed>(str, out var result))
                        {
                            return result;
                        }

                        var bResult = bool.Parse(str); //For backwards compatibilityS
                        return bResult ? QueryAllowed.Allow : QueryAllowed.None;
                    }));
                };

                sb.Schema.Table <QueryEntity>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync);
            }
        }