Exemple #1
0
        public static JobTracker CreateJobTracker(string typeName, int userId, long size, bool cancelable = false)
        {
            // We are starting some async job that we want to track the progress of.
            if (size <= 0)
            {
                return(null);    // not allowed.
            }

            string cacheKey = MakeKey(typeName, userId);
            var    job      = CacheT <JobTracker> .Get(cacheKey);

            if (job == null)
            {
                job = new JobTracker {
                    JobTypeName = typeName, UserId = userId, Progress = new Progress2(size)
                };
            }
            else if (job.IsComplete)
            {
                // just re-use done job
                job.FailureMsg = null;
                job.IsComplete = false;
                job.SetStartSize(size);
            }
            else
            {
                return(null);    // cant dupe the active job.
            }

            if (cancelable)
            {
                job.Cancellation = new CancellationTokenSource();
            }

            CacheT <JobTracker> .Set(cacheKey, job, 24 * 60 * 60);    // update time

            return(job);
        }
Exemple #2
0
 public static JobTracker FindJobTracker(string typeName, int userId)
 {
     // Find the job in the global name space.
     return(CacheT <JobTracker> .Get(MakeKey(typeName, userId)));
 }