public void Queue(SerializedOperation aOperation) { Trace("Queue() - START - enabled: {0}, count: {1}, OpInProg: {2}", Enabled, iQueue.Count, OperationInProgress); lock ( iQueue ) { Trace("Queue() - aOperation.Enabled: {0}, aOperation: {1}", aOperation.Enabled, aOperation.GetType().Name); aOperation.OperationManager = this; iQueue.Add(aOperation); // Sort the list so that the highest priority item is first Comparison <SerializedOperation> sortByPriority = delegate(SerializedOperation aLeft, SerializedOperation aRight) { // We want highest-to-lowest sort order int ret = aLeft.CompareTo(aRight); return(ret * -1); }; iQueue.Sort(sortByPriority); Trace("Queue() - {{{0}}} - Queue now contains {1} entries, amEnabled: {2}", aOperation.GetType(), Count, Enabled); } StartNextOperation(); Trace("Queue() - END - enabled: {0}, count: {1}, OpInProg: {2}", Enabled, iQueue.Count, OperationInProgress); Trace(""); Trace(""); }
internal void OperationCompleted(SerializedOperation aOperation) { OperationInProgress = false; Trace("OpComplete() - Operation completed {{{0}}}, queue contains {1} more entries, amEnabled: {2}", aOperation.GetType(), Count, Enabled); // StartNextOperation(); }
private void StartNextOperation() { TraceQueue(string.Format("StartNextOperation() - START - Enabled: {0}", Enabled)); lock ( iQueue ) { Trace("StartNextOperation() - count: {0}, OpInProg: {1}", iQueue.Count, OperationInProgress); bool enabled = Enabled; if (enabled) { if (OperationInProgress) { Trace("StartNextOperation() - Already running operation!"); } else { SerializedOperation op = FindNextOp(); if (op != null) { iQueue.Remove(op); // Trace(string.Empty); Trace(string.Empty); Trace("StartNextOperation() - ****************************************************************************"); Trace("StartNextOperation() - starting op: {0}/{1} [{2}]", 1, iQueue.Count + 1, op.GetType() + " - " + op.ToString()); Trace("StartNextOperation() - ****************************************************************************"); // op.Start(); OperationInProgress = true; } else { Trace("StartNextOperation() - Queue is empty or no enabled items!"); if (StateHandler != null) { StateHandler(TState.EStateOperationsCompleted); } } } } else { Trace("StartNextOperation() - Queue is disabled!"); } } Trace("StartNextOperation() - END - count: {0}, OpInProg: {1}, Enabled: {2}", iQueue.Count, OperationInProgress, Enabled); Trace(""); }
private SerializedOperation FindNextOp() { TraceQueue("FindNextOp()"); SerializedOperation ret = null; // foreach (SerializedOperation op in iQueue) { System.Diagnostics.Debug.Assert(!op.IsBusy); if (op.Enabled) { ret = op; break; } } // return(ret); }
internal void OnOperationEnabledStatusChanged(SerializedOperation aOperation) { StartNextOperation(); }