コード例 #1
0
        public Dictionary <PropertyRoute, Implementations> FindAllImplementations(Type root)
        {
            try
            {
                if (!Tables.ContainsKey(root))
                {
                    return(null);
                }

                var table = Table(root);

                return(PropertyRoute.GenerateRoutes(root)
                       .Select(r => r.Type.IsMList() ? r.Add("Item") : r)
                       .Where(r => r.Type.CleanType().IsIEntity())
                       .ToDictionary(r => r, r => FindImplementations(r)));
            }
            catch (Exception e)
            {
                e.Data["rootType"] = root.TypeName();
                throw;
            }
        }
コード例 #2
0
ファイル: HelpLogic.cs プロジェクト: crazyants/extensions
        static SqlPreCommand SynchronizeTypes(Replacements replacements, SyncData data)
        {
            var dic = Database.Query <EntityHelpEntity>().ToList();

            if (dic.IsEmpty())
            {
                return(null);
            }

            var typesByTableName = Schema.Current.Tables.ToDictionary(kvp => kvp.Value.Name.Name, kvp => kvp.Key);

            var replace = replacements.TryGetC(Replacements.KeyTables);

            var table = Schema.Current.Table <EntityHelpEntity>();

            using (replacements.WithReplacedDatabaseName())
                return(dic.Select(eh =>
                {
                    Type type = typesByTableName.TryGetC(replace.TryGetC(eh.Type.TableName) ?? eh.Type.TableName);

                    if (type == null)
                    {
                        return null; //PreDeleteSqlSync
                    }
                    var repProperties = replacements.TryGetC(PropertyRouteLogic.PropertiesFor.FormatWith(type.FullName));
                    var routes = PropertyRoute.GenerateRoutes(type).ToDictionary(pr => { var ps = pr.PropertyString(); return repProperties.TryGetC(ps) ?? ps; });
                    eh.Properties.RemoveAll(p => !routes.ContainsKey(p.Property.Path));
                    foreach (var prop in eh.Properties)
                    {
                        prop.Description = SynchronizeContent(prop.Description, replacements, data);
                    }

                    eh.Description = SynchronizeContent(eh.Description, replacements, data);

                    return table.UpdateSqlSync(eh);
                }).Combine(Spacing.Simple));
        }
コード例 #3
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                PropertyRouteLogic.Start(sb);

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

                cache = new AuthCache <RulePropertyEntity, PropertyAllowedRule, PropertyRouteEntity, PropertyRoute, PropertyAllowed>(sb,
                                                                                                                                     toKey: PropertyRouteEntity.ToPropertyRouteFunc,
                                                                                                                                     toEntity: PropertyRouteLogic.ToPropertyRouteEntity,
                                                                                                                                     isEquals: (p1, p2) => p1 == p2,
                                                                                                                                     merger: new PropertyMerger(),
                                                                                                                                     invalidateWithTypes: true,
                                                                                                                                     coercer: PropertyCoercer.Instance);

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

                PropertyRoute.SetIsAllowedCallback(pp => pp.GetAllowedFor(PropertyAllowed.Read));

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Properties", "Property", p => TypeLogic.GetCleanName(p.RootType) + "|" + p.PropertyString(), pa => pa.ToString(),
                                                                      exportAll ? TypeLogic.TypeToEntity.Keys.SelectMany(t => PropertyRoute.GenerateRoutes(t)).ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    Dictionary <Type, Dictionary <string, PropertyRoute> > routesDicCache = new Dictionary <Type, Dictionary <string, PropertyRoute> >();

                    var groups = x.Element("Properties").Elements("Role").SelectMany(r => r.Elements("Property")).Select(p => new PropertyPair(p.Attribute("Resource").Value))
                                 .AgGroupToDictionary(a => a.Type, gr => gr.Select(pp => pp.Property).ToHashSet());

                    foreach (var item in groups)
                    {
                        Type?type = TypeLogic.NameToType.TryGetC(replacements.Apply(TypeAuthCache.typeReplacementKey, item.Key));

                        if (type == null)
                        {
                            continue;
                        }

                        var dic = PropertyRoute.GenerateRoutes(type).ToDictionary(a => a.PropertyString());

                        replacements.AskForReplacements(
                            item.Value,
                            dic.Keys.ToHashSet(),
                            AuthPropertiesReplacementKey(type));

                        routesDicCache[type] = dic;
                    }

                    var routes = Database.Query <PropertyRouteEntity>().ToDictionary(a => a.ToPropertyRoute());

                    return(cache.ImportXml(x, "Properties", "Property", roles, s =>
                    {
                        var pp = new PropertyPair(s);

                        Type?type = TypeLogic.NameToType.TryGetC(replacements.Apply(TypeAuthCache.typeReplacementKey, pp.Type));
                        if (type == null)
                        {
                            return null;
                        }

                        PropertyRoute?route = routesDicCache[type].TryGetC(replacements.Apply(AuthPropertiesReplacementKey(type), pp.Property));
                        if (route == null)
                        {
                            return null;
                        }

                        var property = routes.GetOrCreate(route, () => new PropertyRouteEntity
                        {
                            RootType = TypeLogic.TypeToEntity[route.RootType],
                            Path = route.PropertyString()
                        }.Save());

                        return property;
                    }, EnumExtensions.ToEnum <PropertyAllowed>));
                };

                sb.Schema.Table <PropertyRouteEntity>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync);
            }
        }
コード例 #4
0
 public static AuthThumbnail?GetAllowedThumbnail(Lite <RoleEntity> role, Type entityType)
 {
     return(PropertyRoute.GenerateRoutes(entityType).Select(pr => cache.GetAllowed(role, pr)).Collapse());
 }
コード例 #5
0
ファイル: HelpLogic.cs プロジェクト: crazyants/extensions
        static string SynchronizeContent(string content, Replacements r, SyncData data)
        {
            if (content == null)
            {
                return(null);
            }

            return(WikiMarkup.WikiParserExtensions.TokenRegex.Replace(content, m =>
            {
                var m2 = HelpLinkRegex.Match(m.Groups["content"].Value);

                if (!m2.Success)
                {
                    return m.Value;
                }

                string letter = m2.Groups["letter"].Value;
                string link = m2.Groups["link"].Value;
                string text = m2.Groups["text"].Value;

                switch (letter)
                {
                case WikiFormat.EntityLink:
                    {
                        string type = r.SelectInteractive(link, TypeLogic.NameToType.Keys, "Type", data.StringDistance);

                        if (type == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, type, text);
                    }

                case WikiFormat.PropertyLink:
                    {
                        string type = r.SelectInteractive(link.Before("."), TypeLogic.NameToType.Keys, "Type", data.StringDistance);

                        if (type == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        var routes = PropertyRoute.GenerateRoutes(TypeLogic.GetType(type)).Select(a => a.PropertyString()).ToList();

                        string pr = r.SelectInteractive(link.After('.'), routes, "PropertyRoutes-" + type, data.StringDistance);

                        if (pr == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, type + "." + pr, text);
                    }

                case WikiFormat.QueryLink:
                    {
                        string query = r.SelectInteractive(link, QueryLogic.QueryNames.Keys, "Query", data.StringDistance);

                        if (query == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, query, text);
                    }

                case WikiFormat.OperationLink:
                    {
                        string operation = r.SelectInteractive(link, SymbolLogic <OperationSymbol> .AllUniqueKeys(), "Operation", data.StringDistance);

                        if (operation == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, operation, text);
                    }

                case WikiFormat.Hyperlink: return m.Value;

                case WikiFormat.NamespaceLink:
                    {
                        string @namespace = r.SelectInteractive(link, data.Namespaces, "Namespace", data.StringDistance);

                        if (@namespace == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, @namespace, text);
                    }

                case WikiFormat.AppendixLink:
                    {
                        string appendix = r.SelectInteractive(link, data.Appendices, "Appendices", data.StringDistance);

                        if (appendix == null)
                        {
                            return Link(letter + "-error", link, text);
                        }

                        return Link(letter, appendix, text);
                    }

                default:
                    break;
                }

                return m.Value;
            }));
        }
コード例 #6
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);
            }));
        }