public virtual T Get(IEntityRequestContext context, IEntityIdentity entity) { using (Logger.CreateTrace(LoggingBoundaries.ServiceBoundary, typeof(EntityBusinessFacade <T>), "Get")) { try { if (!context.IgnoreHandlers.HasFlag(EntityEventType.GetBefore) && !_handlers.OnGetBefore(context, entity)) { return(null); } var item = _repository.Get(context, entity as T); if (!context.IgnoreHandlers.HasFlag(EntityEventType.GetAfter) && !_handlers.OnGetAfter(context, item)) { return(null); } return(item); } catch (Exception ex) { if (Logger.HandleException(LoggingBoundaries.ServiceBoundary, ex)) { throw; } } } return(null); }
/// <summary> /// The constructor is used for restoring the instance of <see cref="AbstractEntityIdentity{TKey}"/> /// from provided <see cref="IEntityIdentity"/>. It is used during restoring aggregates from persistence /// storage. /// </summary> protected AbstractEntityIdentity(IEntityIdentity identity) { Require.NotNull(identity, nameof(identity)); Require.True(identity.Tag.Equals(Tag, StringComparison.Ordinal), nameof(identity), "Invalid identity.Tag value"); Id = ParseIdValue(identity.Value); }
private List <EntityEvent> GetPendingEntityEvents() { return(this.ChangeTracker .Entries <IEntity>() .Where(x => x.Entity.GetType().IsTypeOf(typeof(IEntityIdentity <>)) && x.Entity.GetType().GetCustomAttributes <PublishAttribute>().Any() && x.State is EntityState.Added or EntityState.Deleted) .Select(x => { var type = x.Entity.GetType(); var state = x.State.ToString(); var name = type.Name.Replace("Proxy", string.Empty); return x.Entity switch { IEntityIdentity <int> @int => new EntityEvent(@int.Id, name, state), IEntityIdentity <long> @long => new EntityEvent(@long.Id, name, state), IEntityIdentity <string> @string => new EntityEvent(@string.Id, name, state), IEntityIdentity <Guid> guid => new EntityEvent(guid.Id, name, state), IEntityIdentity <dynamic> dynamic => new EntityEvent(dynamic.Id, name, state), _ => null }; }) .Where(x => x != null) .ToList()); }
public async Task DeleteOrder(IEntityIdentity identity) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } await DataAccess.Delete(identity); }
public virtual void Save(IEntityRequestContext context, IEntityIdentity entity) { using (Logger.CreateTrace(LoggingBoundaries.ServiceBoundary, typeof(EntityBusinessFacade <T>), "Save")) { var first = context.Operations.Count == 0; try { var before = _repository.Get(context, entity as T); if (before == null) { if (!context.IgnoreHandlers.HasFlag(EntityEventType.AddBefore) && !_handlers.OnAddBefore(context, entity)) { throw new Exception("OnAddBefore handler rejected"); } _repository.Add(context, entity as T); if (!context.IgnoreHandlers.HasFlag(EntityEventType.AddAfter) && !_handlers.OnAddAfter(context, entity)) { throw new Exception("OnAddAfter handler rejected"); } } else { if (!context.IgnoreHandlers.HasFlag(EntityEventType.ModifyBefore) && !_handlers.OnModifyBefore(context, before, entity)) { throw new Exception("OnModifyBefore handler rejected"); } _repository.Modify(context, before, entity as T); if (!context.IgnoreHandlers.HasFlag(EntityEventType.ModifyAfter) && !_handlers.OnModifyAfter(context, before, entity)) { throw new Exception("OnModifyAfter handler rejected"); } } } catch (Exception ex) { context.Rollback(); if (Logger.HandleException(LoggingBoundaries.ServiceBoundary, ex)) { throw; } } finally { if (first) { context.Commit(); } } } }
private void OnTriggerEnter(Collider other) { IEntityIdentity identity = other.GetComponent <IEntityIdentity>(); if (!PlayerCollection.ContainsId(identity.EntityId)) { throw new InvalidOperationException($"Unknown Entity: {identity.EntityId} entered trigger."); } OnPlayerEnter(PlayerCollection[identity.EntityId]); }
public async Task Delete(IEntityIdentity id) { var result = await Context.Clients.FirstOrDefaultAsync(client => client.Id == id.Id); if (result != null) { Context.Clients.Remove(result); await Context.SaveChangesAsync(); } }
public async Task <Client> Get(IEntityIdentity id) { if (id.Id.HasValue) { return(Mapper.Map <Client>(await Context.Clients.FirstOrDefaultAsync(client => client.Id == id.Id))); } else { throw new ArgumentNullException(); } }
public UserProjection Get(IEntityIdentity <Guid> id) { var user = _context.Users.FindById(id.Identity); if (user == null) { return(UserProjection.Empty()); } return(user); }
public async Task <Order> Get(IEntityIdentity identity) { if (identity.Id.HasValue) { return(Mapper.Map <Order>(await Context.Orders.FirstOrDefaultAsync(order => order.Id == identity.Id))); } else { throw new ArgumentNullException(); } }
public async Task Delete(IEntityIdentity identity) { var result = await Context.Orders.FirstOrDefaultAsync(order => order.Id == identity.Id); if (result != null) { Context.Orders.Remove(result); await Context.SaveChangesAsync(); } }
private void OnTriggerExit(Collider other) { IEntityIdentity identity = other.GetComponent <IEntityIdentity>(); if (!PlayerCollection.ContainsId(identity.EntityId)) { return; } OnPlayerExit(PlayerCollection[identity.EntityId]); }
private bool isLocalPlayer(GameObject obj) { //We need to know who is entering IEntityIdentity identity = obj.GetComponent <IEntityIdentity>(); //If it's not the local player's id we should not do anything if (identity == null || SlotModel.SlotSelected != identity.EntityId) { return(false); } return(true); }
public User Get(IEntityIdentity <EntityId> id) { var user = DbContext.Users.AsNoTracking() .OrderByDescending(ob => ob.Id) .ThenByDescending(ob => ob.RowVersion) .FirstOrDefault(t => t.Id.Equals(id.Identity.Value)); if (user == null) { return(User.Empty()); } return(user.ToUser()); }
public async Task <Order> GetOrder(IEntityIdentity identity) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } var result = await DataAccess.Get(identity); if (result == null) { throw new InvalidOperationException($"Not find by id: {identity.Id}"); } return(result); }
public Emp FindById(IEntityIdentity <Guid> identity) { return(FindById(identity.Id)); }
public Emp GetById(IEntityIdentity <Guid> identity) { return(FindById(identity.Id) ?? throw new EntityNotFoundException(identity)); }
public TestIdentity(IEntityIdentity identity) : base(identity) { }
public void Delete(IEntityIdentity <Guid> identity) { Delete(identity.Id); }
public static IDBConnection GetConnection(string dbCode, EntityOperationType type, IEntityIdentity before, IEntityIdentity after, IEntityRequestContext context) { dbCode = DataConfig.Current.GetConnectionName(dbCode); IDBConnection connection = null; foreach (var operation in context.Operations) { var sqlOperation = operation as SqlOperation; if (sqlOperation == null) { continue; } if (sqlOperation.DbCode == dbCode) { connection = sqlOperation.Connection; } } if (connection == null && context.Who != null) { connection = DatabaseFactory.CreateDatabase(dbCode).AddClaimsDefaults(context.Who); } if (connection == null) { connection = DatabaseFactory.CreateDatabase(dbCode); } if (type != EntityOperationType.Get) { if (!connection.IsInTransaction) { connection.BeginTrans(); } context.Operations.Add(new SqlOperation { DbCode = dbCode, Type = type, Before = before, After = after, Connection = connection }); } return(connection); }
/// <inheritdoc /> protected StringEntityIdentity(IEntityIdentity identity) : base(identity) { }
public static bool HasIdentity(this IEntityIdentity entity) { return(!((entity == null) || entity is NullEntity || string.IsNullOrEmpty(entity.Id))); }
public TodoTaskId(IEntityIdentity identity) : base(identity) { }
public ProjectId(IEntityIdentity identity) : base(identity) { }
public UserId(IEntityIdentity identity) : base(identity) { }
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 EntityNotFoundException(IEntityIdentity identity, string message, Exception inner) : base($"Entity with id '{identity.HumanReadableId}' could not be found. {message}", inner) { }
public EntityNotFoundException(IEntityIdentity identity) : base($"Entity with id '{identity.HumanReadableId}' could not be found.") { }
public virtual T Get(ClaimsPrincipal who, IEntityIdentity entity) { return(Get(new EntityRequestContext { Who = who }, entity)); }
public virtual void Remove(ClaimsPrincipal who, IEntityIdentity entity) { Remove(new EntityRequestContext { Who = who }, entity); }