Пример #1
0
        public void TestGetJobsForDispatch1()
        {
            //Add items ta1 and ta2 (both are meant for dispatch)
            jsm.AddJob(ta1);
            jsm.AddJob(ta2);

            //Add another item. It's not meant for dispatch.
            jsm.AddJob(new MockTradeActivityItem("ACC", DateTime.Today, 1, 4, 3, JobStatus.Dispatching));

            ReadOnlyCollection <ITradeActivityItem> coll = jsm.GetJobsForDispatch(3);

            Assert.AreEqual(2, coll.Count, "Count must be 2.");
            Assert.AreEqual(ta1, coll[0], "Incorrect GetJobsByServiceID implementation.");
            Assert.AreEqual(ta2, coll[1], "Incorrect GetJobsByServiceID implementation.");
        }
Пример #2
0
        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
            }
        }