Exemplo n.º 1
0
        public static List <string> GetReport(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid)
        {
            var job = WpsJob.Load(accessor, cache, serviceProvider, uid);

            if (job == null)
            {
                throw new EntryPointNotFoundException();
            }
            return(job.GetReport());
        }
Exemplo n.º 2
0
        public static Execute GetExecuteRequest(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid)
        {
            var job = WpsJob.Load(accessor, cache, serviceProvider, uid, false);

            if (job == null)
            {
                throw new EntryPointNotFoundException();
            }
            return(job.jobOrder.ExecuteRequest);
        }
Exemplo n.º 3
0
        public static ExecuteResponse GetCachedExecuteResponse(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid)
        {
            var job = WpsJob.Load(accessor, cache, serviceProvider, uid);

            if (job == null)
            {
                throw new EntryPointNotFoundException();
            }
            return(job.GetExecuteResponse());
        }
Exemplo n.º 4
0
        public static void ForceRetry(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid, int retry)
        {
            var job = WpsJob.Load(accessor, cache, serviceProvider, uid);

            if (job == null)
            {
                throw new EntryPointNotFoundException();
            }
            if (job.jobOrder.RecoveryInfo != null)
            {
                job.jobOrder.RecoveryInfo.retry = retry;
                job.jobOrder.SetRecoveryInfo(job.jobOrder.RecoveryInfo);
            }
            job.Run();
        }
Exemplo n.º 5
0
        private string Save(DateTimeOffset absoluteExpiration)
        {
            Guid   uid = Guid.NewGuid();
            WpsJob job = null;

            while (wpsJobCache.TryGetValue <WpsJob>(uid.ToString(), out job))
            {
                Thread.Sleep(100);
                uid = Guid.NewGuid();
            }
            lock (wpsJobCache)
            {
                logger.LogDebug("Set job cache -- {0}", uid.ToString());
                wpsJobCache.Set <WpsJob>(uid.ToString(), this, absoluteExpiration.DateTime);
                if (this.jobOrder != null && this.jobOrder.Uid != null && this.jobOrder.Uid != uid.ToString())
                {
                    logger.LogDebug("Wrong uid -> {0}", this.jobOrder.Uid);
                }
            }

            return(uid.ToString());
        }
Exemplo n.º 6
0
        private static WpsJob Load(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid, bool useCache = true)
        {
            var    logger = serviceProvider.GetService <ILogger <WpsJob> >();
            WpsJob job    = null;

            if (useCache)
            {
                lock (cache) {
                    logger.LogDebug("Get job cache -- {0}", uid);
                    job = cache.Get(uid) as WpsJob;
                    if (job.jobOrder.Uid != uid)
                    {
                        logger.LogDebug("Wrong uid -> {0}", job.jobOrder.Uid);
                    }
                }
            }
            if (job == null)
            {
                try {
                    //read from file
                    var execute = JobOrder.ReadExecuteRequest(uid);
                    if (execute == null)
                    {
                        return(null);
                    }
                    var executeResponse = JobOrder.ReadExecuteResponse(uid);
                    var recoveryInfo    = JobOrder.ReadRecoveryInfo(uid);
                    job          = new WpsJob();
                    job.logger   = logger;
                    job.Uid      = uid;
                    job.progress = new JobProgress();
                    job.progress.Report(executeResponse.Status);
                    job.jobOrder = new JobOrder()
                    {
                        ExecuteRequest = execute, JobProgress = job.progress, CreationTime = executeResponse.Status.creationTime
                    };
                    job.jobOrder.ExecuteResponse = executeResponse;
                    job.jobOrder.Uid             = uid;
                    job.jobOrder.RecoveryInfo    = recoveryInfo;
                    if (executeResponse.Status != null)
                    {
                        job.creationTime = executeResponse.Status.creationTime;
                    }

                    //create wps process
                    string serviceIdentifier = recoveryInfo != null ? recoveryInfo.wpsProcessIdentifier : execute.Identifier.Value;

                    foreach (var processConfig in WebProcessingServiceConfiguration.Settings.Processes)
                    {
                        if (processConfig.Identifier == serviceIdentifier)
                        {
                            job.wpsProcess = processConfig.CreateHandlerInstance(accessor, cache, serviceProvider, true);
                        }
                    }

                    if (job.wpsProcess != null)
                    {
                        job.Task = job.wpsProcess.CreateTask(job.jobOrder);
                    }

                    lock (cache) {
                        logger.LogDebug("Set job cache -- {0}", uid);
                        cache.Set <WpsJob>(uid, job, DateTimeOffset.Now.Add(job.wpsProcess.JobCacheTime).DateTime);
                        if (job.jobOrder.Uid != uid)
                        {
                            logger.LogDebug("Wrong uid -> {0}", job.jobOrder.Uid);
                        }
                    }

                    return(job);
                } catch (Exception e) {
                    return(null);
                }
            }
            return(job);
        }
Exemplo n.º 7
0
        public ExecuteResponse SubmitExecuteProcess(Execute execute)
        {
            WpsJob job = new WpsJob(this, execute);

            return(job.Run());
        }