public Task <ICollection> GetQueuedOrphansAsync(string entityName, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <ICollection>(cancellationToken));
            }
            try
            {
                if (HasQueuedOperations)
                {
                    List <object> additions = new List <object>(operationQueue.Count);
                    List <object> removals  = new List <object>(operationQueue.Count);
                    for (int i = 0; i < operationQueue.Count; i++)
                    {
                        IDelayedOperation op = operationQueue[i];
                        if (op.AddedInstance != null)
                        {
                            additions.Add(op.AddedInstance);
                        }
                        if (op.Orphan != null)
                        {
                            removals.Add(op.Orphan);
                        }
                    }
                    return(GetOrphansAsync(removals, additions, entityName, session, cancellationToken));
                }

                return(Task.FromResult <ICollection>(CollectionHelper.EmptyCollection));
            }
            catch (Exception ex)
            {
                return(Task.FromException <ICollection>(ex));
            }
        }
Ejemplo n.º 2
0
 public void queueOperation(IDelayedOperation op)
 {
     lock (operationQueue)
     {
         if (operationQueue.Contains(op))
         {
             // This operation is already queued, see if it's running
             if (op.Equals(CurrentOperation))
             {
                 // It's running, restart it
                 op.Restart();
             }
             else
             {
                 // It's still queued, if it's first up, reset it's wait
                 IDelayedOperation firstOp = operationQueue.Peek();
                 if (firstOp.Equals(op))
                 {
                     op.ResetWait();
                 }
             }
             logger.IfInfo("ExtendWaitOrRestart " + op.OperationType + "!");
         }
         else
         {
             operationQueue.Enqueue(op);
             logger.IfInfo("Queuing new " + op.OperationType + "!");
         }
     }
 }
Ejemplo n.º 3
0
        public void startQueue()
        {
            queueThread = new Thread(delegate()
            {
                while (queueShouldLoop)
                {
                    lock (operationQueue)
                    {
                        if (operationQueue.Count > 0 && operationQueue.Peek() != null && operationQueue.Peek().IsReady)
                        {
                            try
                            {
                                currentOperation = operationQueue.Dequeue();
                            }
                            catch
                            {
                                currentOperation = null;
                            }

                            if (currentOperation != null)
                            {
                                currentOperation.Run();
                                logger.IfInfo(currentOperation.ToString() + " fired");
                            }
                        }
                    }

                    // Sleep to prevent a tight loop
                    Thread.Sleep(DEFAULT_PRECISION);
                }
            });
            queueThread.IsBackground = true;
            queueThread.Start();
        }
Ejemplo n.º 4
0
        public void startQueue()
        {
            queueThread = new Thread(delegate()
            {
                while (queueShouldLoop)
                {
                    lock (operationQueue)
                    {
                        if (operationQueue.Count > 0 && operationQueue.Peek() != null && operationQueue.Peek().IsReady)
                        {
                            try
                            {
                                currentOperation = operationQueue.Dequeue();
                            }
                            catch
                            {
                                currentOperation = null;
                            }

                            if (currentOperation != null)
                            {
                                currentOperation.Run();
                                logger.IfInfo(currentOperation.ToString() + " fired");
                            }
                        }
                    }

                    // Sleep to prevent a tight loop
                    Thread.Sleep(DEFAULT_PRECISION);
                }
            });
            queueThread.IsBackground = true;
            queueThread.Start();
        }
Ejemplo n.º 5
0
 public void queueOperation(IDelayedOperation op)
 {
     lock (operationQueue)
     {
         if (operationQueue.Contains(op))
         {
             // This operation is already queued, see if it's running
             if (op.Equals(CurrentOperation))
             {
                 // It's running, restart it
                 op.Restart();
             }
             else
             {
                 // It's still queued, if it's first up, reset it's wait
                 IDelayedOperation firstOp = operationQueue.Peek();
                 if (firstOp.Equals(op))
                 {
                     op.ResetWait();
                 }
             }
             logger.IfInfo("ExtendWaitOrRestart " + op.OperationType + "!");
         }
         else
         {
             operationQueue.Enqueue(op);
             logger.IfInfo("Queuing new " + op.OperationType + "!");
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Queue an addition, delete etc. if the persistent collection supports it
 /// </summary>
 protected virtual void QueueOperation(IDelayedOperation element)
 {
     if (operationQueue == null)
     {
         operationQueue = new List <IDelayedOperation>(10);
     }
     operationQueue.Add(element);
     dirty = true;             //needed so that we remove this collection from the second-level cache
 }
Ejemplo n.º 7
0
        public ICollection GetQueuedOrphans(string entityName)
        {
            if (HasQueuedOperations)
            {
                List <object> additions = new List <object>(operationQueue.Count);
                List <object> removals  = new List <object>(operationQueue.Count);
                for (int i = 0; i < operationQueue.Count; i++)
                {
                    IDelayedOperation op = operationQueue[i];
                    if (op.AddedInstance != null)
                    {
                        additions.Add(op.AddedInstance);
                    }
                    if (op.Orphan != null)
                    {
                        removals.Add(op.Orphan);
                    }
                }
                return(GetOrphans(removals, additions, entityName, session));
            }

            return(CollectionHelper.EmptyCollection);
        }
		/// <summary>
		/// Queue an addition, delete etc. if the persistent collection supports it
		/// </summary>
		protected void QueueOperation(IDelayedOperation element)
		{
			if (operationQueue == null)
			{
				operationQueue = new List<IDelayedOperation>(10);
			}
			operationQueue.Add(element);
			dirty = true; //needed so that we remove this collection from the second-level cache
		}