예제 #1
0
        public void TestRemoveJobs()
        {
            //Add ta1 and ta2
            TestAddJob2();

            IList <ITradeActivityItem> list = new List <ITradeActivityItem>();

            list.Add(ta1);
            list.Add(ta2);

            jsm.RemoveJobs(list);

            //All indices must now be empty.
            Assert.IsNull(jsm.GetJobByQueueID(2), "Wrong RemoveJob implementation.");
            Assert.IsNull(jsm.GetJobByQueueID(3), "Wrong RemoveJob implementation.");
            Assert.AreEqual(0, jsm.GetJobsByServiceID(3).Count, "Wrong RemoveJob implementation.");
            Assert.AreEqual(0, jsm.GetJobsByStatus(JobStatus.Queued).Count, "Wrong RemoveJob implementation.");
            Assert.AreEqual(
                0, jsm.GetJobsByStatusAndServiceID(JobStatus.Queued, 3).Count, "Wrong RemoveJob implementation.");
        }
예제 #2
0
파일: Demo.cs 프로젝트: kurtrips/tc
        public void TestDemo()
        {
            //Base operations

            // create JobStatusManager
            JobStatusManager jobManager = new JobStatusManager();

            // add job
            jobManager.AddJob(job1);

            // Remove job
            jobManager.RemoveJob(job1.QueueID);

            // add a list of jobs
            jobManager.AddJobs(list);

            // Remove a list of jobs
            jobManager.RemoveJobs(list);


            //Get data for various criteria

            // get concrete job (QueueID is unique job identifier)
            ITradeActivityItem item1 = jobManager.GetJobByQueueID(2);

            // Get count of jobs with given status
            int jobsCount1 = jobManager.GetJobCountByStatus(JobStatus.Queued);

            // get jobs with given status
            ReadOnlyCollection <ITradeActivityItem> jobs2 = jobManager.GetJobsByStatus(JobStatus.Queued);

            // get jobs for given service
            ReadOnlyCollection <ITradeActivityItem> jobs3 = jobManager.GetJobsByServiceID(3);

            // Get count of jobs with given status for given service
            int jobCount2 = jobManager.GetJobCountByStatusServiceID(JobStatus.Queued, 3);

            // get jobs for given service and with given status
            ReadOnlyCollection <ITradeActivityItem> jobs4 = jobManager.GetJobsByStatusAndServiceID(JobStatus.Queued, 3);

            // get jobs for given service and with JobStatus.Queued status
            ReadOnlyCollection <ITradeActivityItem> jobs5 = jobManager.GetJobsForDispatch(3);

            // we can get exclusive access to JobStatusManager to execute not thread safe operations
            lock (jobManager.SyncRoot)
            {
                foreach (ITradeActivityItem job in jobs4)
                {
                    Console.WriteLine(job.QueueID);
                }
            }


            //Monitor jobs for given criteria
            //The application can get read only wrapper for given condition once and uses it many times.
            //The wrapper provides read only access to collection of jobs for given criteria.

            // get jobs for dispatch once
            ReadOnlyCollection <ITradeActivityItem> jobs = jobManager.GetJobsForDispatch(3);

            // call by timer for example
            foreach (ITradeActivityItem job in jobs)
            {
                // process job
            }
        }