コード例 #1
0
        public async Task Run(object o, object context)
        {
            recipients = o.GetConvertedObject <string[]>();

            log.LogDebug($"Starting to process {customerProjects?.Count} projects");

            foreach (var project in customerProjects)
            {
                JobRequest jobRequest;

                try
                {
                    log.LogInformation($"Processing project {project.Name}");
                    // Create a relevant filter
                    var filter = await filters.CreateFilter(project.ProjectUID, new FilterRequest()
                    {
                        FilterType = FilterType.Transient, FilterJson = FILTER_JSON
                    }, headers);

                    log.LogDebug($"Created filter {filter.FilterDescriptor.FilterUid}");
                    //generate filename
                    var generatedFilename = $"{project.Name + " " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH-mm-ss")}";
                    log.LogDebug($"Generated filename {generatedFilename}");
                    //generate uri
                    var baseUri = await serviceResolution.ResolveService("productivity3dinternal_service_public_v2");

                    var requestUri = $"{baseUri.Endpoint}/api/v2/export/machinepasses?projectUid={project.ProjectUID}&filename={generatedFilename}&filterUid={filter.FilterDescriptor.FilterUid}&coordType=0&outputType=0&restrictOutput=False&rawDataOutput=False";
                    log.LogDebug($"Export request url {requestUri}");
                    var jobExportRequest = new ScheduleJobRequest()
                    {
                        Url = requestUri, Timeout = 9000000, Filename = generatedFilename
                    };
                    jobRequest = new JobRequest()
                    {
                        JobUid = Guid.Parse("c3cbb048-05c1-4961-a799-70434cb2f162"), SetupParameters = jobExportRequest, RunParameters = headers, AttributeFilters = SpecialFilters.ExportFilter
                    };
                }
                catch (Exception e)
                {
                    log.LogError(e, $"Failed to prepare for exports with exception");
                    throw;
                }

                try
                {
                    log.LogDebug($"Firing export job for project {project.Name}");
                    var hangfireJobId = jobRunner.QueueHangfireJob(jobRequest, exportEmailGenerator);
                    JobStorage.Current.GetConnection().SetJobParameter(hangfireJobId, Tags.PROJECTNAME_TAG, JsonConvert.SerializeObject(project.Name));
                    JobStorage.Current.GetConnection().SetJobParameter(hangfireJobId, Tags.RECIPIENTS_TAG, JsonConvert.SerializeObject(recipients));
                }
                catch (Exception e)
                {
                    log.LogError(e, $"Queue VSS job failed with exception {e.Message}");
                    throw;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Convert a simple filter into a Real Filter via the Filter service
        /// </summary>
        /// <returns>Filter UID</returns>
        private async Task <Guid> ConvertSimpleFilter(SimpleFilter simpleFilter)
        {
            if (simpleFilter == null)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest,
                                                              (int)Now3DExecutionStates.ErrorCodes.FilterConvertFailure,
                                                              null,
                                                              "No Simple Filter found");
            }

            var project = await _projectProxy.GetProjectForCustomer(CustomerUid, simpleFilter.ProjectUid, CustomHeaders);

            if (project == null)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest,
                                                              (int)Now3DExecutionStates.ErrorCodes.FilterConvertFailure,
                                                              null,
                                                              $"Cannot find project {simpleFilter.ProjectUid} for Customer {CustomerUid}");
            }

            var file = await _fileImportProxy.GetFileForProject(simpleFilter.ProjectUid, UserId, simpleFilter.DesignFileUid,
                                                                CustomHeaders);

            if (file == null)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest,
                                                              (int)Now3DExecutionStates.ErrorCodes.FilterConvertFailure,
                                                              null,
                                                              $"Cannot find file {simpleFilter.DesignFileUid} for project {simpleFilter.ProjectUid}");
            }

            var filterModel = new Filter.Abstractions.Models.Filter(simpleFilter.StartDateUtc,
                                                                    simpleFilter.EndDateUtc,
                                                                    simpleFilter.DesignFileUid,
                                                                    file.Name,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    simpleFilter.LiftNumber);

            var filterRequest = FilterRequest.Create(filterModel);

            var result = await _filterServiceProxy.CreateFilter(simpleFilter.ProjectUid, filterRequest, CustomHeaders);

            if (result.Code != 0)
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest,
                                                              (int)Now3DExecutionStates.ErrorCodes.DataError,
                                                              result.Code.ToString(),
                                                              result.Message);
            }

            var guid = Guid.Parse(result.FilterDescriptor.FilterUid);

            Log.LogInformation($"Converted Simple filter '{JsonConvert.SerializeObject(simpleFilter)}' to a " +
                               $"{nameof(FilterRequest)}: '{JsonConvert.SerializeObject(filterRequest)}'. FilterUID: {guid}");

            return(guid);
        }