public Task<EventInStorage> Fetch(FetchEventRequest request) { if (_queue.Count >= _maxSize) throw new StorageReaderBusyException(_maxSize); var entry = new Entry(request, _maxAgeBeforeDrop); _queue.Enqueue(entry); return entry.Task; }
public Dictionary<Guid, EventInStorage> FetchEvent(FetchEventRequest[] request) { var results = _events.Join(request, x => new Tuple<Guid, string, object>(x.EventId, x.Context, x.Stream), x => new Tuple<Guid, string, object>(x.EventId, x.Context, x.Stream), (x, y) => new KeyValuePair<Guid, EventInStorage>(y.RequestId, x)) .ToDictionary(x => x.Key, x => x.Value); ReadCount++; return results; }
public Dictionary<Guid, EventInStorage> FetchEvent(FetchEventRequest[] request) { try { return doFetchEvents(request); } catch (Exception e) { throw new EventStorageException(e); } }
public Entry(FetchEventRequest request, TimeSpan maxAge) { Request = request; _maxAge = maxAge; _dropTime = DateTime.Now.Add(maxAge); _task = new TaskCompletionSource<EventInStorage>(); }
public EventNotFoundException(FetchEventRequest request) : base(string.Format("The event with context: {0}, stream: {1}, eventId: {2} was not found.", request.Context, request.Stream, request.EventId)) { Request = request; }
private SqlParameter getFetchParameter(FetchEventRequest[] requestses) { var table = getEmptyFetchEventsTable(); addFetchRequestsToTable(requestses, table); var parameter = new SqlParameter("Events", SqlDbType.Structured); parameter.Value = table; parameter.TypeName = "EventRequestParameter"; return parameter; }
private Dictionary<Guid, EventInStorage> doFetchEvents(FetchEventRequest[] request) { var results = new Dictionary<Guid, EventInStorage>(); var parameter = getFetchParameter(request); using (var connection = new SqlConnection(_connectionString)) using (var command = new SqlCommand("FetchEvent", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(parameter); command.Connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var requestId = reader.GetGuid(0); var e = readEventInStorage(reader, 1); results[requestId] = e; } return results; } } }
private void addFetchRequestsToTable(FetchEventRequest[] requestses, DataTable table) { foreach (var request in requestses) { table.Rows.Add(request.EventId, request.Stream, request.Context, request.RequestId); } }