Esempio n. 1
0
        public static ExecuteResponse GetExecuteResponse(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider, string uid)
        {
            var job = WpsJob.Load(accessor, cache, serviceProvider, uid, false);

            if (job == null)
            {
                var response = JobOrder.ReadExecuteResponse(uid);
                if (response == null)
                {
                    throw new EntryPointNotFoundException();
                }
                return(response);
            }
            return(job.GetExecuteResponse());
        }
Esempio n. 2
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);
        }