private void processQueue(QueuedOperation pending) { for (int i = 0; i < pending.Queues.Length; i++) { if (queues[pending.Queues[i]].Peek() != pending) { return; } } Delegate baseOnComplete = pending.Operation["on-complete"]; pending.Operation["on-complete"] = (Action <HttpOperation, HttpResponse>) delegate(HttpOperation self, HttpResponse response) { try { baseOnComplete.DynamicInvoke(self, response); } catch (Exception ex) { Log.LogException(this, ex); } removeFromQueue(pending); }; base.sendOperation(pending.Operation, pending.Parameters); }
private void addToQueue(QueuedOperation pending) { for (int i = 0; i < pending.Queues.Length; i++) { string key = pending.Queues[i]; if (!queues.ContainsKey(key)) { queues.Add(key, new Queue <QueuedOperation>()); } queues[key].Enqueue(pending); } }
protected override void sendOperation(HttpOperation operation, params string[] parameters) { RequestQueueAttribute[] array = (RequestQueueAttribute[])operation.GetType().GetCustomAttributes(typeof(RequestQueueAttribute), inherit: true); if (array.Length == 0) { base.sendOperation(operation, parameters); return; } QueuedOperation pending = new QueuedOperation(operation, parameters, array); addToQueue(pending); processQueue(pending); }
private void removeFromQueue(QueuedOperation pending) { for (int i = 0; i < pending.Queues.Length; i++) { Queue <QueuedOperation> queue = queues[pending.Queues[i]]; QueuedOperation queuedOperation = queue.Dequeue(); if (queuedOperation != pending) { Log.LogErrorFormatted(this, "Expected {0} at the front of queue {1} but found {2}", pending, queue, queuedOperation); processQueue(queuedOperation); } if (queue.Count > 0) { processQueue(queue.Peek()); } } }
private void ExecuteTriggerableOperations() { try { while (lstTriggeredOperations.Count > 0) { QueuedOperation qo = lstTriggeredOperations[0]; switch (qo.Type) { case QueuedOperationType.Insert: AppendAsyncEventMessage("Triggering Insert NewIndex=" + qo.NewIndex + ", NewCount=" + qo.NewCount); Insert(qo.NewIndex, qo.NewCount); break; case QueuedOperationType.Remove: AppendAsyncEventMessage("Triggering Remove OldIndex=" + qo.OldIndex + ", OldCount=" + qo.OldCount); Remove(qo.OldIndex, qo.OldCount); break; case QueuedOperationType.Replace: AppendAsyncEventMessage("Triggering Replace OldIndex=" + qo.OldIndex + ", OldCount=" + qo.OldCount + ", NewCount=" + qo.NewCount); Replace(qo.OldIndex, qo.OldCount, qo.NewCount); break; case QueuedOperationType.Shrink: AppendAsyncEventMessage("Triggering Shrink Index=" + qo.NewIndex + ", Amount=" + qo.NewCount * 20); Shrink(qo.NewIndex, qo.NewCount); break; case QueuedOperationType.Expand: AppendAsyncEventMessage("Triggering Expand Index=" + qo.NewIndex + ", Amount=" + qo.NewCount * 20); Expand(qo.NewIndex, qo.NewCount); break; } lstTriggeredOperations.RemoveAt(0); } } catch (Exception ex) { txtExceptionReport.Text = ex.ToString(); lstScrollPresenterEvents.Items.Add(ex.ToString()); } }
private void ExecuteQueuedOperations() { try { while (lstQueuedOperations.Count > 0) { QueuedOperation qo = lstQueuedOperations[0]; switch (qo.Type) { case QueuedOperationType.Insert: AppendAsyncEventMessage("Unqueuing Insert NewIndex=" + qo.NewIndex + ", NewCount=" + qo.NewCount); dataSource.Insert(qo.NewIndex, qo.NewCount, qo.Reset); break; case QueuedOperationType.Remove: AppendAsyncEventMessage("Unqueuing Remove OldIndex=" + qo.OldIndex + ", OldCount=" + qo.OldCount); dataSource.Remove(qo.OldIndex, qo.OldCount, qo.Reset); break; case QueuedOperationType.Replace: AppendAsyncEventMessage("Unqueuing Replace OldIndex=" + qo.OldIndex + ", OldCount=" + qo.OldCount + ", NewCount=" + qo.NewCount); dataSource.Replace(qo.OldIndex, qo.OldCount, qo.NewCount, qo.Reset); break; case QueuedOperationType.Reset: AppendAsyncEventMessage("Unqueuing Reset"); dataSource.Reset(); break; } lstQueuedOperations.RemoveAt(0); } } catch (Exception ex) { txtExceptionReport.Text = ex.ToString(); lstScrollerEvents.Items.Add(ex.ToString()); } }