public bool OnRemoveAfter <T>(IEntityRequestContext context, T entity) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(entity); AuditManager.LogRemove(context.Who, IdentityManager.GetClientMachine(context.Who), info.Module, entity._key, null, null, entity, context.TransactionUID); return(true); }
public bool OnModifyAfter <T>(IEntityRequestContext context, T before, T after) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(before); AuditManager.LogModify(context.Who, IdentityManager.GetClientMachine(context.Who), info.Module, before._key, null, null, before, after, context.TransactionUID); return(true); }
public T Get(IEntityRequestContext context, T entity) { using (var database = SqlQuery.GetConnection(_info.Module, EntityOperationType.Get, null, null, context)) { Debug.Assert(database != null); return(SqlQuery.Get <T>(_container, context, EntityInfoManager.GetInfo(entity), entity._key, database)); } }
public bool OnGetPagedBefore <T>(IEntityRequestContext context) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(typeof(T)); if (!AuthorizationHelper.CanView(context.Who, info)) { AuditManager.LogChange <T>(context.Who, info.Module, info.Entity, null, null, null, "ACC", null, null, context.TransactionUID); throw new UnauthorizedAccessException(); } return(true); }
public bool OnRemoveBefore <T>(IEntityRequestContext context, T entity) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(entity); if (!AuthorizationHelper.CanRemove(context.Who, info)) { AuditManager.LogAccess(context.Who, IdentityManager.GetClientMachine(context.Who), info.Module, entity._key, null, null, entity, context.TransactionUID); throw new UnauthorizedAccessException(); } return(true); }
public void Register <TImplementation, TFacade>(Lifestyle lifestyle = null) where TImplementation : class, IEntityIdentity where TFacade : class, IEntityBusinessFacade <TImplementation> { //_container.Register<TService, TImplementation>(Lifestyle.Transient); var producer = (lifestyle ?? _container.Options.DefaultLifestyle).CreateProducer <IEntityIdentity, TImplementation>(_container); var facadeProducer = (Lifestyle.Singleton).CreateProducer <IEntityBusinessFacade <TImplementation>, TFacade>(_container); _container.Register <IEntityBusinessFacade <TImplementation>, TFacade>(Lifestyle.Singleton); var info = EntityInfoManager.GetInfo <TImplementation>(); _facadeProducers[typeof(TImplementation).FullName] = facadeProducer; _producers[info.Name] = producer; }
public IQueryMetadata GetPaged(string module, string version, string entity, [FromQuery] ODataV3QueryOptions options) { var item = _factory.CreateNew(module, entity); var info = EntityInfoManager.GetInfo(item); var max = EntityInfoManager.GetMaxRows(info); var resultLimit = options.Top < max && options.Top > 0 ? options.Top : max; string orderBy = options.ProcessOrderByOptions(); var context = new EntityRequestContext { Who = User as ClaimsPrincipal }; var facade = _factory.CreateFacade(item); var result = facade.GetPaged(context, options.Skip, ref resultLimit, options.InlineCount, options.Filter, orderBy); return(new QueryMetadata <object>(result, resultLimit)); }
public bool OnModifyBefore <T>(IEntityRequestContext context, T before, T after) where T : class, IEntityIdentity { var retValue = true; var info = EntityInfoManager.GetInfo(before); var handlers = _producers[EntityEventType.ModifyBefore]; var allTypes = handlers.ContainsKey(ALL_CLASSES); var targetTypes = handlers.ContainsKey(info.Name); if (!allTypes && !targetTypes) { return(true); } if (allTypes) { foreach (var handler in handlers[ALL_CLASSES]) { if (!handler.OnModifyBefore(context, before, after)) { retValue = false; } } } if (targetTypes) { foreach (var handler in handlers[info.Name]) { if (!handler.OnModifyBefore(context, before, after)) { retValue = false; } } } return(retValue); }
public IEnumerable <T> OnGetPagedAfter <T>(IEntityRequestContext context, IEnumerable <T> list) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(typeof(T)); var handlers = _producers[EntityEventType.GetPagedAfter]; var allTypes = handlers.ContainsKey(ALL_CLASSES); var targetTypes = handlers.ContainsKey(info.Name); if (!allTypes && !targetTypes) { return(list); } if (targetTypes) { foreach (var handler in handlers[info.Name]) { list = handler.OnGetPagedAfter(context, list); if (list == null) { return(null); } } } if (allTypes) { foreach (var handler in handlers[ALL_CLASSES]) { list = handler.OnGetPagedAfter(context, list); if (list == null) { return(null); } } } return(list); }
protected SqlRepository(Container container) { _container = container; _info = EntityInfoManager.GetInfo(typeof(T)); }
private void ProcessRequests(List <JObject> list, Dictionary <string, string> identities, EntityRequestContext context, List <object> result, IEntityIdentity parent) { foreach (var obj in list) { string module = null; if (obj.Property("_schema") != null) { obj["_module"] = obj["_schema"].Value <string>(); } if (obj.Property("_module") != null) { module = obj["_module"].Value <string>(); } if (string.IsNullOrEmpty(module)) { throw new Exception($"Missing _module on posted object {obj}"); } if (obj.Property("_action") == null) { throw new Exception($"Missing _action on posted object {obj}"); } if (obj.Property("_entity") == null) { throw new Exception($"Missing _entity name on posted object {obj}"); } var action = obj["_action"].Value <string>(); if (action == "modify") { action = "save"; } if (action == "add") { action = "add"; } var entity = obj["_entity"].Value <string>(); var identity = string.Empty; if (obj.Property("_identity") != null) { identity = obj["_identity"].Value <string>(); obj.Remove("_identity"); } List <JObject> children = null; if (obj.Property("_children") != null) { children = obj["_children"].Value <List <JObject> >(); obj.Remove("_children"); } var item = _factory.CreateNew(module, entity); if (parent != null) { var info = EntityInfoManager.GetInfo(item); if (string.IsNullOrEmpty(info.RelatedKeyName)) { throw new Exception($"Missing RelatedKeyName is not configured not sure what property to set on child object {obj}"); } obj[info.RelatedKeyName] = parent._key; } var replace = (from prop in obj.Properties() where prop.Value.ToString().StartsWith("{{") select prop.Name).ToList(); foreach (var prop in replace) { var val = obj[prop].Value <string>().ToLower(); if (val.StartsWith("{{") && val.EndsWith("}}")) { val = val.Replace("{{", ""); val = val.Replace("}}", ""); if (identities.ContainsKey(val)) { obj[prop] = new JValue(identities[val]); } } } try { var facade = _factory.CreateFacade(item); switch (action.ToLowerInvariant()) { case "remove": JsonConvert.PopulateObject(obj.ToString(), item); facade.Remove(context, item); result.Add(item); break; case "save": JsonConvert.PopulateObject(obj.ToString(), item); facade.Save(context, item); if (!string.IsNullOrEmpty(identity)) { identities[identity.ToLower()] = item._key; } result.Add(item); break; } if (children != null) { ProcessRequests(children, identities, context, result, item); } } catch (Exception ex) { Logger.HandleException(LoggingBoundaries.ServiceBoundary, ex); context.Rollback(); throw; } } }
public static bool PopulateEntity <T>(T entity, IDataReader dataReader, bool stripLeadUnderscore) where T : class, IEntityIdentity { var info = EntityInfoManager.GetInfo(entity); return(PopulateEntity(entity, info, dataReader, stripLeadUnderscore)); }