Example #1
0
        /// <summary>
        /// This overriden method adds a job to the collection. Jobs with a dependency ID will be
        /// queued behind earlier jobs with the same ID.
        /// </summary>
        /// <param name="newJobID">The job identifier.</param>
        /// <param name="data">The data.</param>
        /// <param name="RSCallback">The callback.</param>
        /// <param name="ProgressCallback">The progress callback.</param>
        /// <param name="priority">The job priority.</param>
        /// <param name="dependencyID">The dependency identifier.</param>
        /// <param name="ValidateRSCallBack"></param>
        /// <returns>The job ID.</returns>
        protected virtual Guid AddJob(Guid newJobID, IXimuraRQRSEnvelope data, 
            CommandRSCallback RSCallback, CommandProgressCallback ProgressCallback,
            JobPriority priority, string dependencyID, DependencyValidateRSCallback ValidateRSCallBack)
        {
            bool jobNotLinked = true;

            lock (this)
            {
                //Create the job holder object.
                JobHolder newJob = new JobHolder(newJobID, data, RSCallback, ProgressCallback, priority,
                    null, null, ValidateRSCallBack);
                //OK, let's continue as normal.
                //Add the job.
                WorkTable.Add(newJob);

                if (dependencyID != null)
                {
                    //Register the dependency job in the dependency tree.
                    jobNotLinked = RegisterLinkedJob(dependencyID, newJobID);

                    newJob.DependencyID = dependencyID;
                }

                Interlocked.Increment(ref jobRequests);

                if (JobShouldTrace)
                {
                    string dependencyInfo = "";
                    if (dependencyID != null)
                    {
                        dependencyInfo = " Dependency: " + dependencyID + " " + 
                            (string)(jobNotLinked ? "Not Linked" : "Linked");
                    }
                    JobTrace("-->" + jobRequests.ToString() + " CJ=" + CompletionJobID.ToString()
                        + " Job=" + newJobID.ToString() + dependencyInfo);
                }
            }

            if (autoExecute && jobNotLinked)
                SubmitJob(newJobID);

            return newJobID;
        }
Example #2
0
        /// <summary>
        /// This method will remove a job from the collection and flag it as an error.
        /// </summary>
        /// <param name="errorJob">THe job to remove.</param>
        protected virtual void RemoveErrorJob(JobHolder errorJob)
        {
            lock (this)
            {
                Guid? errorID = errorJob.ID;

                while (errorID.HasValue && WorkTable.Contains(errorID.Value))
                {
                    //Add the ID to the error list.
                    errorList.Add(errorID.Value);
                    Interlocked.Increment(ref errorCount);

                    try
                    {
                        //Get the error job, this is used to determine the dependency relationships.
                        errorJob = WorkTable[errorID.Value] as JobHolder;

                        //Remove the job from the collection
                        WorkTable.Remove(errorID.Value);
                        //Set the counters
                        Interlocked.Decrement(ref jobRequests);

                        //Does this job have dependencies? If not, then quit.
                        if (errorJob.DependencyID == null)
                            break;
                        //Is there a next job? If not then quit.
                        if (!errorJob.NextJob.HasValue)
                            break;

                        errorID = errorJob.NextJob.Value;
                    }
                    finally
                    {
                        if (errorJob != null)
                            errorJob.Reset();
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// This method will purge the job from the queue.
 /// </summary>
 /// <param name="job"></param>
 protected virtual void PurgeJob(JobHolder job)
 {
     //Do nothing for the moment.
 }
		/// <summary>
		/// This protected method is used to add a job to the collection.
		/// </summary>
		/// <param name="jobID">The job ID. This should be set to a new Guid.</param>
		/// <param name="data">The data</param>
		/// <param name="RSCallback">The call back completion delegate.</param>
		/// <param name="ProgessCallback">The request progress delegate. Set this to null if not needed.</param>
		/// <param name="priority">The request priority.</param>
		/// <returns>The guid of the job queued.</returns>
		protected virtual Guid AddJob(Guid jobID, IXimuraRQRSEnvelope data, 
			CommandRSCallback RSCallback, CommandProgressCallback ProgessCallback, 
			JobPriority priority)
		{
			//Create a new job holder.
			JobHolder jh = new JobHolder(jobID, data, RSCallback, ProgessCallback, priority);

			//We add the job to the queue as it will only be executed when the Execute()
			//command is called.
			lock (this)
			{
				WorkTable.Add(jh);
				Interlocked.Increment(ref jobRequests);
#if (DEBUG)
				//System.Diagnostics.Debug.WriteLine("Inc: " + jobID.ToString() + " -> " + jobRequests.ToString());
#endif
			}

			return jobID;
		}