/// <summary>
        /// Retrieves any "Submitted" entities from the data layer and adds them to the working set.
        /// </summary>
        sealed protected override void RetrieveEntities()
        {
            try
            {
                if (WorkingSet.Values.Count(x => !x) == 0)
                {
                    var entities = Dal.GetSubmittedEntities().ToList();
                    foreach (var entity in entities)
                    {
                        var id = entity.Id;
                        if (!WorkingSet.TryAdd(id, false))
                        {
                            Trace.TraceError(String.Format("Error adding entity with id {0} to working set.", id));
                        }
                        else
                        {
                            Task.Factory.StartNew(() => ProcessEntity(entity), CancellationSource.Token);
                        }
                    }

                    Trace.WriteLine(String.Format("Added {0} entities to the working set.", entities.Count));
                }
                else
                {
                    Trace.WriteLine(String.Format("No entities added due to working set still not processed."));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error updating working set: " + ex.StackTrace);
            }
        }
Example #2
0
        /// <summary>
        /// Retrieves any "Submitted" entities from the data layer and adds them to the working set.
        /// </summary>
        sealed protected override void RetrieveEntities()
        {
            try
            {
                if (WorkingSet.Values.Count(x => !x) == 0)
                {
                    var entities = Dal.GetSubmittedEntities().ToList();
                    foreach (var entity in entities)
                    {
                        var id = entity.Id;
                        if (!WorkingSet.TryAdd(id, false))
                        {
                            Trace.TraceError(String.Format("Error adding entity with id {0} to working set.", id));
                        }
                        else
                        {
                            if (!ThreadPool.QueueUserWorkItem(ProcessEntity, entity))
                            {
                                Trace.TraceError(String.Format("Error queuing entity with id {0} to thread pool.", id));
                            }
                        }
                    }

                    Trace.WriteLine(String.Format("Added {0} entities to the working set.", entities.Count));
                }
                else
                {
                    Trace.WriteLine(String.Format("No entities added due to working set still not processed."));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error updating working set: " + ex.StackTrace);
            }
        }