protected override string ChildPropertyValidation(ModifiableEntity sender, PropertyInfo pi) { if (sender is PanelPartEntity) { PanelPartEntity part = (PanelPartEntity)sender; if (pi.Name == nameof(part.StartColumn)) { if (part.StartColumn + part.Columns > 12) return DashboardMessage.Part0IsTooLarge.NiceToString(part); var other = Parts.TakeWhile(p => p != part) .FirstOrDefault(a => a.Row == part.Row && a.ColumnInterval().Overlaps(part.ColumnInterval())); if (other != null) return DashboardMessage.Part0OverlapsWith1.NiceToString(part, other); } if (entityType != null && pi.Name == nameof(part.Content) && part.Content != null) { var idents = GraphExplorer.FromRoot((Entity)part.Content).OfType<Entity>(); string errorsUserQuery = idents.OfType<IHasEntitytype>() .Where(uc => uc.EntityType != null && !uc.EntityType.Is(EntityType)) .ToString(uc => DashboardMessage._0Is1InstedOf2In3.NiceToString(NicePropertyName(() => EntityType), uc.EntityType, entityType, uc), "\r\n"); return errorsUserQuery.DefaultText(null); } } return base.ChildPropertyValidation(sender, pi); }
static bool manager_IsReadOnly(Type type, ModifiableEntity entity) { Entity ident = entity as Entity; if (ident == null || ident.IsNew) return GetAllowed(type).MaxUI() < TypeAllowedBasic.Modify; else return !ident.IsAllowedFor(TypeAllowedBasic.Modify); }
static bool manager_IsViewable(Type type, ModifiableEntity entity) { Entity ident = entity as Entity; if (ident == null || ident.IsNew) return GetAllowed(type).MaxUI() >= TypeAllowedBasic.Read; return ident.IsAllowedFor(TypeAllowedBasic.Read); }
protected override string ChildPropertyValidation(ModifiableEntity sender, PropertyInfo pi) { OrderDetailsEntity details = sender as OrderDetailsEntity; if (details != null && !IsLegacy && pi.Name == nameof(details.Discount)) { if ((details.Discount * 100.0m) % 5.0m != 0) return OrderMessage.DiscountShouldBeMultpleOf5.NiceToString(); } return base.ChildPropertyValidation(sender, pi); }
private bool ValidateModifiableEntity(ValidationContext validationContext, ModifiableEntity mod) { bool isValid = true; PropertyScope propertyScope = new PropertyScope(); validationContext.KeyBuilders.Push(propertyScope); var entity = mod as Entity; using (entity == null ? null : entity.Mixins.OfType<CorruptMixin>().Any(c => c.Corrupt) ? Corruption.AllowScope() : Corruption.DenyScope()) { foreach (var kvp in PropertyConverter.GetPropertyConverters(mod.GetType())) { if (kvp.Value.AvoidValidate) continue; propertyScope.PropertyName = kvp.Key; if (SignumValidate(validationContext, kvp.Value.GetValue(mod)) ?? true) { isValid = false; } string error = kvp.Value.PropertyValidator.PropertyCheck(mod); if (error != null) { string key = CalculateKey(validationContext); if (validationContext.ModelState.IsValidField(key)) { isValid = false; validationContext.ModelState.AddModelError(key, error); } } } } if (entity != null && entity.Mixins.Any()) { propertyScope.PropertyName = "mixins"; PropertyScope mixinScope = new PropertyScope(); validationContext.KeyBuilders.Push(mixinScope); foreach (var mixin in entity.Mixins) { mixinScope.PropertyName = mixin.GetType().Name; if (!ValidateModifiableEntity(validationContext, mixin)) isValid = false; } validationContext.KeyBuilders.Pop(); } validationContext.KeyBuilders.Pop(); return isValid; }
string GetTitle(ModifiableEntity mod) { if (mod == null) return ""; string niceName = mod.GetType().NiceName(); IdentifiableEntity ident = mod as IdentifiableEntity; if (ident == null) return niceName; if (ident.IsNew) { return LiteMessage.New.NiceToString().ForGenderAndNumber(ident.GetType().GetGender()) + " " + niceName; } return niceName + " " + ident.Id; }
public static string DynamicValidation(ModifiableEntity mod, PropertyInfo pi) { if (!initialized) return null; var candidates = DynamicValidations.Value.TryGetC(pi); if (candidates == null) return null; foreach (var pair in candidates) { if (pair.PropertyRoute.MatchesProperty(mod, pi) == true) { var val = pair.Validation; if (val.IsGlobalyEnabled || (ExplicitelyEnabled != null && ExplicitelyEnabled.Contains(val.ToLite()))) { using (HeavyProfiler.LogNoStackTrace("DynamicValidation", () => val.Name)) { try { string result = val.Eval.Algorithm.EvaluateUntyped(mod, pi); if (result != null) return result; } catch (Exception e) { e.Data["DynamicValidation"] = val.Name; throw e; } } } } } return null; }
protected override string ChildPropertyValidation(ModifiableEntity sender, System.Reflection.PropertyInfo pi) { var column = sender as ChartScriptColumnEntity; if (column != null && pi.Name == nameof(column.IsGroupKey)) { if (column.IsGroupKey) { if (!ChartUtils.Flag(ChartColumnType.Groupable, column.ColumnType)) return "{0} can not be true for {1}".FormatWith(pi.NiceName(), column.ColumnType.NiceToString()); } } var param = sender as ChartScriptParameterEntity; if (param != null && pi.Name == nameof(param.ColumnIndex)) { if (param.ColumnIndex == null && param.ShouldHaveColumnIndex()) return ValidationMessage._0IsNecessary.NiceToString(pi.NiceName()); if (param.ColumnIndex.HasValue && !(0 <= param.ColumnIndex && param.ColumnIndex < this.Columns.Count)) return ValidationMessage._0HasToBeBetween1And2.NiceToString(pi.NiceName(), 0, this.Columns.Count); } return base.ChildPropertyValidation(sender, pi); }
protected MixinEntity(ModifiableEntity mainEntity, MixinEntity?next) { this.mainEntity = mainEntity; this.next = next; }
public static void SetSetters(ModifiableEntity entity, List <PropertySetter> setters, PropertyRoute route) { var options = SignumServer.JsonSerializerOptions; foreach (var setter in setters) { var pr = route.Add(setter.Property); SignumServer.WebEntityJsonConverterFactory.AssertCanWrite(pr, entity); if (pr.Type.IsMList()) { var elementPr = pr.Add("Item"); var mlist = pr.GetLambdaExpression <ModifiableEntity, IMListPrivate>(false).Compile()(entity); switch (setter.Operation) { case PropertyOperation.AddElement: { var value = ConvertObject(setter.Value, elementPr, options); ((IList)mlist).Add(value); } break; case PropertyOperation.AddNewElement: { var item = (ModifiableEntity)Activator.CreateInstance(elementPr.Type) !; SetSetters(item, setter.Setters !, elementPr); ((IList)mlist).Add(item); } break; case PropertyOperation.ChangeElements: { var predicate = GetPredicate(setter.Predicate !, elementPr, options); var toChange = ((IEnumerable <object>)mlist).Where(predicate.Compile()).ToList(); foreach (var item in toChange) { SetSetters((ModifiableEntity)item, setter.Setters !, elementPr); } } break; case PropertyOperation.RemoveElementsWhere: { var predicate = GetPredicate(setter.Predicate !, elementPr, options); var toRemove = ((IEnumerable <object>)mlist).Where(predicate.Compile()).ToList(); foreach (var item in toRemove) { ((IList)mlist).Remove(item); } } break; case PropertyOperation.RemoveElement: { var value = ConvertObject(setter.Value, elementPr, options); ((IList)mlist).Remove(value); } break; default: break; } } else if (setter.Operation == PropertyOperation.CreateNewEntity) { var subPr = pr.Type.IsEmbeddedEntity() ? pr : PropertyRoute.Root(TypeLogic.GetType(setter.EntityType !)); var item = (ModifiableEntity)Activator.CreateInstance(subPr.Type) !; SetSetters(item, setter.Setters !, subPr); SetProperty(entity, pr, route, item); } else if (setter.Operation == PropertyOperation.ModifyEntity) { var item = GetProperty(entity, pr, route); if (!(item is ModifiableEntity mod)) { throw new InvalidOperationException($"Unable to change entity in {pr}: {item}"); } SetSetters(mod, setter.Setters !, pr); SetProperty(entity, pr, route, mod); } else if (setter.Operation == PropertyOperation.Set) { var value = ConvertObject(setter.Value, pr, options); SetProperty(entity, pr, route, value); } else { throw new UnexpectedValueException(setter.Operation); } } }
public void ValidateEntity(ModifiableEntity entity) { return; }
public static bool IsNavigable(ModifiableEntity entity, string partialViewName, bool isSearch = false) { return(Manager.OnIsNavigable(entity.GetType(), entity, partialViewName, isSearch)); }
public static bool IsReadOnly(ModifiableEntity entity) { return(Manager.OnIsReadOnly(entity.GetType(), entity)); }
public static TypeContext UntypedNew(ModifiableEntity entity, string prefix, PropertyRoute route) { return((TypeContext)Activator.CreateInstance(typeof(TypeContext <>).MakeGenericType(entity.GetType()), entity, (TypeContext)null, prefix, route)); }
public void ParseData(ModifiableEntity context, QueryDescription description, SubTokensOptions options) { if (token != null) token.ParseData(context, description, options & ~SubTokensOptions.CanAnyAll); }
public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer) { using (HeavyProfiler.LogNoStackTrace("WriteJson", () => value !.GetType().Name)) { PropertyRoute pr = GetCurrentPropertyRoute(value !); ModifiableEntity mod = (ModifiableEntity)value !; writer.WriteStartObject(); var entity = mod as Entity; if (entity != null) { writer.WritePropertyName("Type"); writer.WriteValue(TypeLogic.TryGetCleanName(mod.GetType())); writer.WritePropertyName("id"); writer.WriteValue(entity.IdOrNull == null ? null : entity.Id.Object); if (entity.IsNew) { writer.WritePropertyName("isNew"); writer.WriteValue(true); } if (Schema.Current.Table(entity.GetType()).Ticks != null) { writer.WritePropertyName("ticks"); writer.WriteValue(entity.Ticks.ToString()); } } else { writer.WritePropertyName("Type"); writer.WriteValue(mod.GetType().Name); } if (!(mod is MixinEntity)) { writer.WritePropertyName("toStr"); writer.WriteValue(mod.ToString()); } writer.WritePropertyName("modified"); writer.WriteValue(mod.Modified == ModifiedState.Modified || mod.Modified == ModifiedState.SelfModified); foreach (var kvp in PropertyConverter.GetPropertyConverters(value !.GetType())) { WriteJsonProperty(writer, serializer, mod, kvp.Key, kvp.Value, pr); } if (entity != null && entity.Mixins.Any()) { writer.WritePropertyName("mixins"); writer.WriteStartObject(); foreach (var m in entity.Mixins) { var prm = pr.Add(m.GetType()); using (JsonSerializerExtensions.SetCurrentPropertyRoute(prm)) { writer.WritePropertyName(m.GetType().Name); serializer.Serialize(writer, m); } } writer.WriteEndObject(); } writer.WriteEndObject(); } }
public virtual object View(object entityOrLite, ViewOptions options) { if (entityOrLite == null) { throw new ArgumentNullException("entity"); } ModifiableEntity entity = entityOrLite as ModifiableEntity; Type liteType = null; if (entity == null) { liteType = Lite.Extract(entityOrLite.GetType()); entity = Server.Retrieve((Lite <Entity>)entityOrLite); } EntitySettings es = AssertViewableEntitySettings(entity); if (!es.OnIsViewable()) { throw new Exception("{0} is not viewable".FormatWith(entity)); } Control ctrl = options.View ?? es.CreateView(entity, options.PropertyRoute); ctrl = es.OnOverrideView(entity, ctrl); NormalWindow win = CreateNormalWindow(); SetNormalWindowEntity(win, (ModifiableEntity)entity, options, es, ctrl); if (options.AllowErrors != AllowErrors.Ask) { win.AllowErrors = options.AllowErrors; } bool?ok = win.ShowDialog(); if (ok != true) { return(null); } object result = win.DataContext; if (liteType != null) { Entity ident = (Entity)result; bool saveProtected = ((ViewOptions)options).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(ident.GetType()); if (GraphExplorer.HasChanges(ident)) { if (saveProtected) { throw new InvalidOperationException("The lite '{0}' of type '{1}' is SaveProtected but has changes. Consider setting SaveProtected = false in ViewOptions".FormatWith(entityOrLite, liteType.TypeName())); } return(ident.ToLiteFat()); } return(ident.ToLite()); } return(result); }
void TaskSetLabelNormalWindow(NormalWindow nw, ModifiableEntity entity) { ShortcutHelper.SetLabelShortcuts(nw); }
void TaskSetIconNormalWindow(NormalWindow nw, ModifiableEntity entity) { var icon = GetEntityIcon(entity.GetType(), true); nw.Icon = icon; }
public static bool IsViewable(ModifiableEntity entity) { return(Manager.OnIsViewable(entity.GetType(), entity)); }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext { JsonReader = reader, JsonSerializer = serializer, Entity = entity, ParentPropertyRoute = parentRoute, PropertyConverter = pc, }); } else { object oldValue = pc.GetValue(entity); var pi = pc.PropertyValidator.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType, oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) //JSON.Net already complaining return; pc.SetValue?.Invoke(entity, newValue); } } } } }
public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route) { if (pc.CustomWriteJsonProperty != null) { pc.CustomWriteJsonProperty(new WriteJsonPropertyContext { JsonWriter = writer, JsonSerializer = serializer, LowerCaseName = lowerCaseName, Entity = mod, ParentPropertyRoute = route, PropertyConverter = pc }); } else { var pr = route.Add(pc.PropertyValidator.PropertyInfo); string error = CanReadPropertyRoute?.Invoke(pr); if (error != null) return; using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { writer.WritePropertyName(lowerCaseName); serializer.Serialize(writer, pc.GetValue(mod)); } } }
static bool manager_IsReadOnly(Type type, ModifiableEntity entity) { if (!typeof(Entity).IsAssignableFrom(type)) return false; var ident = (Entity)entity; if (ident == null || ident.IsNew) return TypeAuthLogic.GetAllowed(type).MaxUI() < TypeAllowedBasic.Modify; return !ident.IsAllowedFor(TypeAllowedBasic.Modify, inUserInterface: true); }
public ReadJsonPropertyContext(JsonReader jsonReader, JsonSerializer jsonSerializer, PropertyConverter propertyConverter, ModifiableEntity entity, PropertyRoute parentPropertyRoute) { JsonReader = jsonReader; JsonSerializer = jsonSerializer; PropertyConverter = propertyConverter; Entity = entity; ParentPropertyRoute = parentPropertyRoute; }
protected DiffLogMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { this.RebindEvents(); }
private ViewResultBase EncapsulateView(ControllerBase controller, ModifiableEntity entity, string prefix, VisualConstructStyle preferredStyle, string partialViewName, bool? readOnly, bool showOperations, bool? saveProtected) { Entity ident = entity as Entity; if (ident == null) throw new InvalidOperationException("Visual Constructor doesn't work with EmbeddedEntities"); switch (preferredStyle) { case VisualConstructStyle.PopupView: return controller.PopupView(ident, new PopupViewOptions(prefix) { PartialViewName = partialViewName, ReadOnly = readOnly, SaveProtected = saveProtected, ShowOperations = showOperations }); case VisualConstructStyle.PopupNavigate: return controller.PopupNavigate(ident, new PopupNavigateOptions(prefix) { PartialViewName = partialViewName, ReadOnly = readOnly, ShowOperations = showOperations }); case VisualConstructStyle.PartialView: return controller.PartialView(ident, prefix, partialViewName); case VisualConstructStyle.View: return controller.NormalPage(ident, new NavigateOptions { PartialViewName = partialViewName }); default: throw new InvalidOperationException(); } }
public static void Save(Entity[] entities) { if (entities == null || entities.Any(e => e == null)) { throw new ArgumentNullException("entity"); } using (var log = HeavyProfiler.LogNoStackTrace("PreSaving")) { Schema schema = Schema.Current; DirectedGraph <Modifiable> modifiables = GraphExplorer.PreSaving(() => GraphExplorer.FromRoots(entities), (Modifiable m, ref bool graphModified) => { ModifiableEntity me = m as ModifiableEntity; if (me != null) { me.SetTemporalErrors(null); } m.PreSaving(ref graphModified); Entity ident = m as Entity; if (ident != null) { schema.OnPreSaving(ident, ref graphModified); } }); HashSet <Entity> wasNew = modifiables.OfType <Entity>().Where(a => a.IsNew).ToHashSet(); HashSet <Entity> wasSelfModified = modifiables.OfType <Entity>().Where(a => a.Modified == ModifiedState.SelfModified).ToHashSet(); log.Switch("Integrity"); var error = GraphExplorer.FullIntegrityCheck(modifiables); if (error != null) { throw new IntegrityCheckException(error); } log.Switch("Graph"); GraphExplorer.PropagateModifications(modifiables.Inverse()); //colapsa modifiables (collections and embeddeds) keeping indentifiables only DirectedGraph <Entity> identifiables = GraphExplorer.ColapseIdentifiables(modifiables); foreach (var node in identifiables) { schema.OnSaving(node); } //Remove all the edges that doesn't mean a dependency identifiables.RemoveEdges(identifiables.Edges.Where(e => !e.To.IsNew).ToList()); //Remove all the nodes that are not modified List <Entity> notModified = identifiables.Where(node => !node.IsGraphModified).ToList(); notModified.ForEach(node => identifiables.RemoveFullNode(node, None)); log.Switch("SaveGroups"); SaveGraph(schema, identifiables); foreach (var node in identifiables) { schema.OnSaved(node, new SavedEventArgs { IsRoot = entities.Contains(node), WasNew = wasNew.Contains(node), WasSelfModified = wasSelfModified.Contains(node), }); } EntityCache.Add(identifiables); EntityCache.Add(notModified); GraphExplorer.CleanModifications(modifiables); } }
public static MappingContext UntypedApplyChanges(this ModifiableEntity entity, ControllerBase controller, string prefix = null, PropertyRoute route = null, SortedList <string, string> inputs = null) { return(miApplyChanges.GetInvoker(entity.GetType()).Invoke(entity, controller, prefix, route, inputs)); }
OrderDetailMixin(ModifiableEntity mainEntity, MixinEntity?next) : base(mainEntity, next) { }
public static bool IsViewable(ModifiableEntity entity, string partialViewName) { return(Manager.OnIsViewable(entity.GetType(), entity, partialViewName)); }
static Schema() { PropertyRoute.SetFindImplementationsCallback(pr => Schema.Current.FindImplementations(pr)); ModifiableEntity.SetIsRetrievingFunc(() => EntityCache.HasRetriever); }
public static string OnPartialViewName(ModifiableEntity entity) { return(EntitySettings(entity.GetType()).OnPartialViewName(entity)); }
internal void OnPreEntityLoaded(ModifiableEntity entity) { this.RaiseEvent(new PreEntityLoadedEventArgs(PreEntityLoadedEvent) { Entity = entity }); }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SendEmailTaskEntity>() .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.Name, e.EmailTemplate, e.UniqueTarget, }); Validator.PropertyValidator((SendEmailTaskEntity er) => er.UniqueTarget).StaticPropertyValidation += (er, pi) => { if (er.UniqueTarget != null && er.TargetsFromUserQuery != null) { return(ValidationMessage._0And1CanNotBeSetAtTheSameTime.NiceToString(pi.NiceName(), ReflectionTools.GetPropertyInfo(() => er.TargetsFromUserQuery).NiceName())); } Implementations?implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query)); if (implementations != null && er.UniqueTarget == null && er.TargetsFromUserQuery == null) { return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); } if (er.UniqueTarget != null) { if (!implementations.Value.Types.Contains(er.UniqueTarget.EntityType)) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; Validator.PropertyValidator((SendEmailTaskEntity er) => er.TargetsFromUserQuery).StaticPropertyValidation += (SendEmailTaskEntity er, PropertyInfo pi) => { Implementations?implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query)); if (implementations != null && er.TargetsFromUserQuery == null && er.UniqueTarget == null) { return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); } if (er.TargetsFromUserQuery != null) { var uqImplementations = GetImplementations(er.TargetsFromUserQuery.InDB(a => a.Query)); if (!implementations.Value.Types.Intersect(uqImplementations.Value.Types).Any()) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; new Graph <SendEmailTaskEntity> .Execute(SendEmailTaskOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { } } .Register(); SchedulerLogic.ExecuteTask.Register((SendEmailTaskEntity er, ScheduledTaskContext ctx) => { if (er.UniqueTarget != null) { ModifiableEntity entity = er.UniqueTarget?.Retrieve(); if (er.ModelConverter != null) { entity = er.ModelConverter.Convert(entity); } Lite <EmailMessageEntity> last = null; foreach (var email in er.EmailTemplate.CreateEmailMessage(entity)) { email.SendMailAsync(); last = email.ToLite(); } return(last); } else { var qr = er.TargetsFromUserQuery.Retrieve().ToQueryRequest(); qr.Columns.Clear(); var result = DynamicQueryManager.Current.ExecuteQuery(qr); var entities = result.Rows.Select(a => a.Entity).ToList(); if (entities.IsEmpty()) { return(null); } return(EmailPackageLogic.SendMultipleEmailsAsync(er.EmailTemplate, entities, er.ModelConverter).Execute(ProcessOperation.Execute).ToLite()); } }); } }
DisabledMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { }
public void ParseData(ModifiableEntity context, QueryDescription description, SubTokensOptions options) { token?.ParseData(context, description, options); }
public override object?ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { using (HeavyProfiler.LogNoStackTrace("ReadJson", () => objectType.Name)) { if (reader.TokenType == JsonToken.Null) { return(null); } using (EntityCache ec = new EntityCache()) { reader.Assert(JsonToken.StartObject); ModifiableEntity mod = GetEntity(reader, objectType, existingValue, out bool markedAsModified); var pr = GetCurrentPropertyRoute(mod); var dic = PropertyConverter.GetPropertyConverters(mod.GetType()); using (JsonSerializerExtensions.SetAllowDirectMListChanges(markedAsModified)) while (reader.TokenType == JsonToken.PropertyName) { if ((string)reader.Value == "mixins") { var entity = (Entity)mod; reader.Read(); reader.Assert(JsonToken.StartObject); reader.Read(); while (reader.TokenType == JsonToken.PropertyName) { var mixin = entity[(string)reader.Value]; reader.Read(); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr.Add(mixin.GetType()))) serializer.DeserializeValue(reader, mixin.GetType(), mixin); reader.Read(); } reader.Assert(JsonToken.EndObject); reader.Read(); } else { PropertyConverter pc = dic.GetOrThrow((string)reader.Value); reader.Read(); ReadJsonProperty(reader, serializer, mod, pc, pr, markedAsModified); reader.Read(); } } reader.Assert(JsonToken.EndObject); AfterDeserilization.Invoke(mod); return(mod); } } }
static bool manager_IsViewable(Type type, ModifiableEntity entity) { if (!typeof(Entity).IsAssignableFrom(type)) return true; var ident = (Entity)entity; if (ident == null || ident.IsNew) return TypeAuthLogic.GetAllowed(type).MaxUI() >= TypeAllowedBasic.Read; return ident.IsAllowedFor(TypeAllowedBasic.Read, inUserInterface: true); }
DisconnectedCreatedMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { }
public static void PostConstructors_AddFilterProperties(ConstructorContext ctx, ModifiableEntity entity) { HttpContextBase httpContext = ctx.Controller.ControllerContext.HttpContext; if (!httpContext.Request.Params.AllKeys.Contains("webQueryName")) { return; } if (!(entity is Entity)) { return; } object queryName = Finder.ResolveQueryName(httpContext.Request.Params["webQueryName"]); if (entity.GetType() != queryName as Type) { return; } QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(queryName); var filters = FindOptionsModelBinder.ExtractFilterOptions(httpContext, queryDescription) .Where(fo => fo.Operation == FilterOperation.EqualTo); var pairs = from pi in ctx.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance) join fo in filters on pi.Name equals fo.Token.Key //where CanConvert(fo.Value, pi.PropertyType) && fo.Value != null where fo.Value != null select new { pi, fo }; foreach (var p in pairs) { p.pi.SetValue(entity, Common.Convert(p.fo.Value, p.pi.PropertyType), null); } return; }
DisconnectedSubsetMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { }
static async void Manager_TaskNormalWindow(NormalWindow normal, ModifiableEntity entity) { ButtonBar bar = normal.Child<ButtonBar>(); var wrapPanel = (WrapPanel)bar.Content; bar.Content = null; HelpButton helpButton = new HelpButton { MainControl = normal, Margin = new Thickness(4), IsEnabled = false, }.Set(DockPanel.DockProperty, Dock.Right); bar.Content = new DockPanel { Children = { helpButton, wrapPanel } }; helpButton.IsActive = await Server.ReturnAsync((IHelpServer s) => s.HasEntityHelpService(entity.GetType())); helpButton.Checked += async (sender, args) => { var entityHelp = await Server.ReturnAsync((IHelpServer s) => s.GetEntityHelpService(entity.GetType())); SetHelpInfo(normal.Child<EntityTitle>(), entityHelp.Info); var properties = (from control in normal.Children<Control>(p => p.IsSet(Common.PropertyRouteProperty), HelpButton.WhereFlags) let propertyRoute = Common.GetPropertyRoute(control).SimplifyToPropertyOrRoot() where propertyRoute.PropertyRouteType != PropertyRouteType.Root select new { control, propertyRoute }).ToList(); var external = properties.Extract(t => t.propertyRoute.RootType != entity.GetType()); foreach (var t in properties) { SetHelpInfo(t.control, entityHelp.Properties.GetOrThrow(t.propertyRoute)); } var buttonBar = normal.Child<ButtonBar>(); var operations = (from control in buttonBar.Children<ToolBarButton>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { control, operation = ((OperationInfo)control.Tag).OperationSymbol }).ToList(); foreach (var t in operations) { SetHelpInfo(t.control, entityHelp.Operations.GetOrThrow(t.operation)); } var menuInfos = (from c in buttonBar.Children<ToolBarButton>(p => p.ContextMenu != null, HelpButton.WhereFlags) from mi in c.ContextMenu.Children<MenuItem>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { mi, operation = ((OperationInfo)mi.Tag).OperationSymbol }).ToList(); foreach (var t in menuInfos) { SetHelpInfo(t.mi, entityHelp.Operations.GetOrThrow(t.operation)); //ConstructFrom OperationInfo } if (external.Any()) { var externalRoutes = external.Select(a => a.propertyRoute).Distinct().ToList(); var dictionary = await Server.ReturnAsync((IHelpServer s) => s.GetPropertyRoutesService(externalRoutes)); foreach (var t in external) { SetHelpInfo(t.control, dictionary.GetOrThrow(t.propertyRoute)); } } }; helpButton.IsEnabled = true; }
IsolationMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { }
public void ValidateEntity(ModifiableEntity entity) { return; }
public static PartialViewResult PopupView(this ControllerBase controller, ModifiableEntity entity, PopupViewOptions options = null) { var prefix = options?.Prefix ?? controller.Prefix(); return(Manager.PopupControl(controller, TypeContextUtilities.UntypedNew(entity, prefix, options?.PropertyRoute), options ?? new PopupViewOptions(prefix))); }
protected EmailReceptionMixin(ModifiableEntity mainEntity, MixinEntity next) : base(mainEntity, next) { }
public virtual ToolBarButton[] ButtonBar_GetButtonBarElement(EntityButtonContext ctx, ModifiableEntity entity) { Entity ident = entity as Entity; if (ident == null) { return(null); } Type type = ident.GetType(); var operations = (from oi in OperationInfos(type) where oi.IsEntityOperation && (oi.AllowsNew.Value || !ident.IsNew) let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os) where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations select eoc).ToList(); if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true)) { Dictionary <OperationSymbol, string> canExecutes = OperationLogic.ServiceCanExecute(ident); foreach (var eoc in operations) { var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol); if (ce != null && ce.HasText()) { eoc.CanExecute = ce; } } } List <ToolBarButton> buttons = new List <ToolBarButton>(); Dictionary <EntityOperationGroup, ToolBarDropDown> groups = new Dictionary <EntityOperationGroup, ToolBarDropDown>(); foreach (var eoc in operations.Where(c => c.OperationSettings == null || !c.OperationSettings.HideOnCanExecute || c.CanExecute == null)) { EntityOperationGroup group = GetDefaultGroup(eoc); if (group != null) { var cm = groups.GetOrCreate(group, () => { var id = group == EntityOperationGroup.Create ? "tmConstructors" : ""; var tbm = new ToolBarDropDown(ctx.Prefix, id) { Title = group.Description(), Text = group.Description(), CssClass = group.CssClass, Items = new List <IMenuItem>(), Order = group.Order, }; buttons.Add(tbm); return(tbm); }); cm.Items.Add(CreateToolBarButton(eoc, group).ToMenuItem()); } else { buttons.Add(CreateToolBarButton(eoc, null)); } } foreach (var item in buttons.OfType <ToolBarDropDown>()) { item.Items = item.Items.OrderBy(a => ((MenuItem)a).Order).ToList(); } return(buttons.OrderBy(a => a.Order).ToArray()); }