예제 #1
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
            }
        }
예제 #2
0
        public void TestAddJob1()
        {
            //Add
            jsm.AddJob(ta1);

            //Check if item was added to all indices correctly.
            Assert.AreEqual(ta1, jsm.GetJobByQueueID(2), "Wrong AddJob implementation.");
            Assert.AreEqual(ta1, jsm.GetJobsByServiceID(3)[0], "Wrong AddJob implementation.");
            Assert.AreEqual(ta1, jsm.GetJobsByStatus(JobStatus.Queued)[0], "Wrong AddJob implementation.");
            Assert.AreEqual(
                ta1, jsm.GetJobsByStatusAndServiceID(JobStatus.Queued, 3)[0], "Wrong AddJob implementation.");
        }