/// <summary> /// Injects an asyncronous waiter which will inject the provided response for one potential future request. /// It will check every 5 milliseconds to see if a request item is inserted in the queue, and in that case respond to it. /// </summary> public static void InjectResponse <TRequest, TResponse>(TResponse injectedResponse) { var service = GetServiceKey(typeof(TRequest), typeof(TResponse)); // Get queue item: while (true) { var latestCondition = QueryOption.OrderByDescending <IIntegrationQueueItem>(x => x.RequestDate); var item = Database.Find <IIntegrationQueueItem>(x => x.IntegrationService == service && x.ResponseDate == null, latestCondition); if (item != null) { item = item.Clone() as IIntegrationQueueItem; item.Response = JsonConvert.SerializeObject(injectedResponse); item.ResponseDate = LocalTime.Now; Database.Save(item); return; } Thread.Sleep(5); } }
static int DefaultNewIdGenerator(Type type) { if (type.BaseType != typeof(IntEntity)) { return(DefaultNewIdGenerator(type.BaseType)); } Func <Type, int> initialize = (t => { if (TransientEntityAttribute.IsTransient(t)) { return(1); } return(Database.GetList(t, new[] { QueryOption.Take(1), QueryOption.OrderByDescending("ID") }) .FirstOrDefault().Get(x => (int)x.GetId() + 1) ?? 1); }); return(LastUsedIds.AddOrUpdate(type, initialize, (t, old) => old + 1)); }