public string RouteAndRowId()
    {
        if (RowId.HasValue)
        {
            return(Route.PropertyString() + ";" + RowId);
        }

        return(Route.PropertyString());
    }
        static Action <T> GetUpdater <T>(PropertyRoute route)
            where T : Entity
        {
            string propertyPath = route.PropertyString();
            string rootType     = TypeLogic.GetCleanName(route.RootType);

            var mlistRoute = route.GetMListItemsRoute();

            if (mlistRoute == null)
            {
                var exp  = route.GetLambdaExpression <T, FilePathEmbedded?>(true);
                var func = exp.Compile();

                return((e) =>
                {
                    var fpe = func(e);
                    if (fpe != null)
                    {
                        fpe.EntityId = e.Id;
                        fpe.MListRowId = null;
                        fpe.PropertyRoute = route.PropertyString();
                        fpe.RootType = rootType;
                    }
                });
            }
            else
            {
                var mlistExpr = mlistRoute.Parent !.GetLambdaExpression <T, IMListPrivate>(true);
                var mlistFunc = mlistExpr.Compile();

                var fileExpr = route.GetLambdaExpression <ModifiableEntity, FilePathEmbedded>(true, mlistRoute);
                var fileFunc = fileExpr.Compile();

                return((e) =>
                {
                    var mlist = mlistFunc(e);
                    if (mlist != null)
                    {
                        var list = (IList)mlist;
                        for (int i = 0; i < list.Count; i++)
                        {
                            var mod = (ModifiableEntity)list[i] !;

                            var fpe = fileFunc(mod);
                            if (fpe != null)
                            {
                                fpe.EntityId = e.Id;
                                fpe.MListRowId = mlist.GetRowId(i);
                                fpe.PropertyRoute = route.PropertyString();
                                fpe.RootType = rootType;
                            }
                        }
                    }
                });
            }
        }
        static void AddBinding <T>(PropertyRoute route)
            where T : Entity
        {
            var entityEvents = Schema.Current.EntityEvents <T>();

            entityEvents.RegisterBinding <PrimaryKey>(route.Add(nameof(FilePathEmbedded.EntityId)),
                                                      () => true,
                                                      (t, rowId) => t.Id,
                                                      (t, rowId, retriever) => t.Id);

            entityEvents.RegisterBinding <PrimaryKey?>(route.Add(nameof(FilePathEmbedded.MListRowId)),
                                                       () => true,
                                                       (t, rowId) => rowId,
                                                       (t, rowId, retriever) => rowId);

            var routeType = TypeLogic.GetCleanName(route.RootType);

            entityEvents.RegisterBinding <string>(route.Add(nameof(FilePathEmbedded.RootType)),
                                                  () => true,
                                                  (t, rowId) => routeType,
                                                  (t, rowId, retriever) => routeType);

            var propertyRoute = route.PropertyString();

            entityEvents.RegisterBinding <string>(route.Add(nameof(FilePathEmbedded.PropertyRoute)),
                                                  () => true,
                                                  (t, rowId) => propertyRoute,
                                                  (t, rowId, retriever) => propertyRoute);
        }
Esempio n. 4
0
        protected virtual Dictionary <string, object> OptionsJSInternal()
        {
            var options = new Dictionary <string, object>
            {
                { "prefix", Prefix }
            };

            if (PartialViewName.HasText() && !Type.IsEmbeddedEntity())
            {
                options.Add("partialViewName", PartialViewName);
            }

            Type type = this.GetElementType();

            if (type.IsEmbeddedEntity())
            {
                if (Implementations != null)
                {
                    throw new ArgumentException("implementations should be null for EmbeddedEntities");
                }

                options.Add("types", new[] { type.ToJsTypeInfo(isSearch: false, prefix: Prefix) });

                PropertyRoute route = this.GetElementRoute();
                options.Add("rootType", Navigator.ResolveWebTypeName(route.RootType));
                options.Add("propertyRoute", route.PropertyString());
            }
            else
            {
                options.Add("types", Implementations.Value.ToJsTypeInfos(isSearch: false, prefix: Prefix));
            }

            if (this.ReadOnly)
            {
                options.Add("isReadOnly", this.ReadOnly);
            }

            if (Create)
            {
                options.Add("create", true);
            }
            if (Remove)
            {
                options.Add("remove", true);
            }
            if (Find)
            {
                options.Add("find", true);
            }
            if (View)
            {
                options.Add("view", true);
            }
            if (Navigate)
            {
                options.Add("navigate", this.Navigate);
            }

            return(options);
        }
Esempio n. 5
0
        public static PropertyRouteEntity ToPropertyRouteEntity(this PropertyRoute route)
        {
            TypeEntity type = TypeLogic.TypeToEntity.GetOrThrow(route.RootType);
            string     path = route.PropertyString();

            return(Database.Query <PropertyRouteEntity>().SingleOrDefaultEx(f => f.RootType == type && f.Path == path) ??
                   new PropertyRouteEntity
            {
                RootType = type,
                Path = path
            });
        }
Esempio n. 6
0
 public static string IdProperty(PropertyRoute route)
 {
     return("p-" + route.PropertyString().Replace('.', '_').Replace('/', '_').Replace('[', '_').Replace(']', '_'));
 }
Esempio n. 7
0
        public static LineLocator <S> LineLocator <T, S>(this ILineContainer <T> lineContainer, Expression <Func <T, S> > property) where T : IModifiableEntity
        {
            PropertyRoute route = lineContainer.Route ?? PropertyRoute.Root(typeof(T));

            var element = lineContainer.Element;

            foreach (var mi in Reflector.GetMemberList(property))
            {
                if (mi is MethodInfo && ((MethodInfo)mi).IsInstantiationOf(MixinDeclarations.miMixin))
                {
                    route = route.Add(((MethodInfo)mi).GetGenericArguments()[0]);
                }
                else
                {
                    var newRoute = route.Add(mi);

                    if (newRoute.Parent != route && route != lineContainer.Route)
                    {
                        element = element.FindElement(By.CssSelector("[data-property-path='" + route.PropertyString() + "']"));
                    }

                    route = newRoute;
                }
            }

            return(new LineLocator <S>(
                       elementLocator: element.WithLocator(By.CssSelector("[data-property-path='" + route.PropertyString() + "']")),
                       route: route
                       ));
        }
Esempio n. 8
0
 public static bool IsPropertyRoute(this PropertyRouteEntity prdn, PropertyRoute pr) =>
 As.Expression(() => prdn.RootType == pr.RootType.ToTypeEntity() && prdn.Path == pr.PropertyString());
Esempio n. 9
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                PropertyRouteLogic.Start(sb);

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

                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
                        {
                            Route = route,
                            RootType = TypeLogic.TypeToEntity[route.RootType],
                            Path = route.PropertyString()
                        }.Save());

                        return property;
                    }, EnumExtensions.ToEnum <PropertyAllowed>));
                };
            }
        }
Esempio n. 10
0
 static string Mapping_CanChange(PropertyRoute route)
 {
     switch (PropertyAuthLogic.GetPropertyAllowed(route))
     {
         case PropertyAllowed.Modify: return null;
         case PropertyAllowed.None:
         case PropertyAllowed.Read:
         default: return AuthMessage.NotAuthorizedToChangeProperty0on1.NiceToString().FormatWith(route.PropertyString(), route.RootType.NiceName());
     }
 }
Esempio n. 11
0
        static string PropertyLink(this PropertyRoute route)
        {
            string cleanName = TypeLogic.GetCleanName(route.RootType);

            return("[p:" + cleanName + "." + route.PropertyString().Replace("[", "[[").Replace("]", "]]") + "]");
        }
Esempio n. 12
0
    internal static string ConsiderMessage(PropertyRoute route, string targetTypes)
    {
        return($@"Consider writing something like this in your Starter class:
sb.Schema.Settings.FieldAttributes(({route.RootType.TypeName()} a) => a.{route.PropertyString().Replace("/", ".First().")}).Replace(new ImplementedByAttribute({targetTypes}))");
    }
Esempio n. 13
0
 public static string IdProperty(PropertyRoute route)
 {
     return "p-" + route.PropertyString().Replace('.', '_').Replace('/', '_').Replace('[', '_').Replace(']', '_');
 }
Esempio n. 14
0
        static string Mapping_CanChange(PropertyRoute route)
        {
            switch (PropertyAuthLogic.GetPropertyAllowed(route))
            {
            case PropertyAllowed.Modify: return(null);

            case PropertyAllowed.None:
            case PropertyAllowed.Read:
            default: return(AuthMessage.NotAuthorizedToChangeProperty0on1.NiceToString().FormatWith(route.PropertyString(), route.RootType.NiceName()));
            }
        }
 public override string ToString()
 {
     return(Route.PropertyString().Replace("/", "[" + RowId + "]."));
 }