internal MinHeapItem(uint pqueue, MinHeapItem other) { this.entrytime = other.entrytime; this.entryorder = other.entryorder; this.value = other.value; this.pqueue = pqueue; }
internal MinHeapItem(uint pqueue, UInt64 entryorder, IEntityUpdate value) { this.entrytime = Util.EnvironmentTickCount(); this.entryorder = entryorder; this.value = value; this.pqueue = pqueue; }
internal bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue) { for (int i = 0; i < m_numberOfQueues; ++i) { // To get the fair queing, we cycle through each of the // queues when finding an element to dequeue, this code // assumes that the distribution of updates in the queues // is polynomial, probably quadractic (eg distance of PI * R^2) uint h = (uint)((m_nextQueue + i) % m_numberOfQueues); if (m_heaps[h].Count > 0) { m_nextQueue = (uint)((h + 1) % m_numberOfQueues); MinHeapItem item = m_heaps[h].RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime); value = item.Value; return(true); } } timeinqueue = 0; value = default(IEntityUpdate); return(false); }
public async Task UpdateReturnsExpectedType() { await TestObject.Insert(TestEntity); IEntityUpdate <TestSimpleEntity> actual = TestObject.Update(TestEntity.ID); Assert.IsInstanceOfType(actual, typeof(SimpleEntityUpdate <TestSimpleEntity>)); }
public async Task UpdatePopulatesUpdateDelegateFactory() { await TestObject.Insert(TestEntity); IEntityUpdate <TestSimpleEntity> actual = TestObject.Update(TestEntity.ID); SimpleEntityUpdate <TestSimpleEntity> actualUpdate = (SimpleEntityUpdate <TestSimpleEntity>)actual; Assert.AreSame(MockUpdateDelegateFactory.Object, actualUpdate.UpdateDelegateFactory); }
public async Task UpdatePopulatesExpressionParser() { await TestObject.Insert(TestEntity); IEntityUpdate <TestSimpleEntity> actual = TestObject.Update(TestEntity.ID); SimpleEntityUpdate <TestSimpleEntity> actualUpdate = (SimpleEntityUpdate <TestSimpleEntity>)actual; Assert.AreSame(MockExpressionParser.Object, actualUpdate.ExpressionParser); }
public async Task UpdatePopulatesEntity() { await TestObject.Insert(TestEntity); IEntityUpdate <TestSimpleEntity> actual = TestObject.Update(TestEntity.ID); SimpleEntityUpdate <TestSimpleEntity> actualUpdate = (SimpleEntityUpdate <TestSimpleEntity>)actual; Assert.AreSame(TestClonedEntity, actualUpdate.UpdatingEntity); }
/// <summary> </summary> /// <param name="invoiceAdd">this is a test</param> /// <returns></returns> /// <remarks> /// /// /// </remarks> public async Task <IEntityView> EntityUpdate(IEntityUpdate entityUpdate) { try { var result = new EntityView(); using (var db = new InvoiceContext()) { if (db.Entitys.Any(w => w.EntityId == entityUpdate.EntityId)) { var entity = db.Entitys.First(w => w.EntityId == entityUpdate.EntityId); entity.EntityExternalRef = entityUpdate.EntityExternalRef; entity.LogoURL = entityUpdate.LogoURL; entity.Name = entityUpdate.Name; entity.SMTPEmailDisplayName = entityUpdate.SMTPEmailDisplayName; entity.SMTPEmailFromAddress = entityUpdate.SMTPEmailFromAddress; entity.SMTPHost = entityUpdate.SMTPHost; entity.SMTPPassword = entityUpdate.SMTPPassword; entity.SMTPUserName = entityUpdate.SMTPUserName; await db.SaveChangesAsync(); result.EntityExternalRef = entity.EntityExternalRef; result.EntityId = entity.EntityId; result.LogoURL = entity.LogoURL; result.Name = entity.Name; result.SMTPEmailDisplayName = entity.SMTPEmailDisplayName; result.SMTPEmailFromAddress = entity.SMTPEmailFromAddress; result.SMTPHost = entity.SMTPHost; result.SMTPPassword = entity.SMTPPassword; result.SMTPUserName = entity.SMTPUserName; return(result); } } } catch (Exception e) { LogFactory.GetLogger().Log(LogLevel.Error, e); return(new EntityView() { __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to create EntityView", __CQRSStatusCode = 500 }); } return(null); }
public bool Enqueue(uint pqueue, IEntityUpdate value) { LookupItem lookup; uint localid = value.Entity.LocalId; UInt64 entry = m_nextRequest++; if (m_lookupTable.TryGetValue(localid, out lookup)) { entry = lookup.Heap[lookup.Handle].EntryOrder; value.Update(lookup.Heap[lookup.Handle].Value); lookup.Heap.Remove(lookup.Handle); } pqueue = Util.Clamp <uint>(pqueue, 0, m_numberOfQueues - 1); lookup.Heap = m_heaps[pqueue]; lookup.Heap.Add(new MinHeapItem(pqueue, entry, value), ref lookup.Handle); m_lookupTable[localid] = lookup; return(true); }
public void RemoveUpdate(IEntityUpdate entity) { update.Remove(entity); }
public void AddUpdate(IEntityUpdate entity) { update.Add(entity); }
/// <summary> /// Remove an item from one of the queues. Specifically, it removes the /// oldest item from the next queue in order to provide fair access to /// all of the queues /// </summary> public bool TryDequeue(out IEntityUpdate value, out Int32 timeinqueue) { // If there is anything in priority queue 0, return it first no // matter what else. Breaks fairness. But very useful. for (int iq = 0; iq < NumberOfImmediateQueues; iq++) { if (m_heaps[iq].Count > 0) { MinHeapItem item = m_heaps[iq].RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Environment.TickCount - item.EntryTime; value = item.Value; return(true); } } // To get the fair queing, we cycle through each of the // queues when finding an element to dequeue. // We pull (NumberOfQueues - QueueIndex) items from each queue in order // to give lower numbered queues a higher priority and higher percentage // of the bandwidth. // Check for more items to be pulled from the current queue if (m_heaps[m_nextQueue].Count > 0 && m_countFromQueue > 0) { m_countFromQueue--; MinHeapItem item = m_heaps[m_nextQueue].RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Environment.TickCount - item.EntryTime; value = item.Value; return(true); } // Find the next non-immediate queue with updates in it for (int i = 0; i < NumberOfQueues; ++i) { m_nextQueue = (uint)((m_nextQueue + 1) % NumberOfQueues); m_countFromQueue = m_queueCounts[m_nextQueue]; // if this is one of the immediate queues, just skip it if (m_nextQueue < NumberOfImmediateQueues) { continue; } if (m_heaps[m_nextQueue].Count > 0) { m_countFromQueue--; MinHeapItem item = m_heaps[m_nextQueue].RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Environment.TickCount - item.EntryTime; value = item.Value; return(true); } } timeinqueue = 0; value = default(IEntityUpdate); return(false); }
public void AddUpdate(IEntityUpdate entity) { updateObjects.Add(entity); }
public void SetReturnsItself() { IEntityUpdate <TestSimpleEntity> actual = TestObject.Set(TestSetExpression, TestSetValue); Assert.AreSame(TestObject, actual); }