private int CreateOrCheckId(int?id) { if (id.HasValue) { var idValue = id.Value; if (_actorContext.Contains(idValue)) { throw Error.AlreadyExists($"Actor with id {idValue} already exists"); } using (Lock.Enter(_freeIds)) { _freeIds.Remove(idValue); } return(idValue); } var actorId = Interlocked.Increment(ref _nextId); while (_actorContext.Contains(actorId)) { actorId = Interlocked.Increment(ref _nextId); } return(actorId); }
public AssetContext(IEnumerable <Asset> assets) { _assets = assets.ToArray(); CollectionUtils.EnsureUnique( _assets, asset => throw Error.AlreadyExists($"Asset with id '{asset.Id}' already exists")); _filters = new Dictionary <int, IAssetFilter>(32); _groups = new Dictionary <int, IAssetGroup>(32); _singleAssets = new Dictionary <int, object>(); }