/// <summary>
        /// Generate project data for the given parameters and cache results locally.
        /// </summary>
        /// <returns>Resulting parameters hash</returns>
        private async Task <(string hash, FdaStatsDTO stats, string reportUrl)> UpdateAsync(ProjectStorage storage, InventorParameters parameters,
                                                                                            string hash, bool bForceUpdate = false)
        {
            _logger.LogInformation("Update the project");
            var bucket = await _userResolver.GetBucketAsync();

            var isUpdateExists = bForceUpdate ? false : await IsGenerated(bucket, storage.GetOssNames(hash));

            FdaStatsDTO stats;
            string      reportUrl;

            if (isUpdateExists)
            {
                _logger.LogInformation("Detected existing outputs at OSS");
                var statsNative = await bucket.DeserializeAsync <List <Statistics> >(storage.GetOssNames(hash).StatsUpdate);

                stats     = FdaStatsDTO.CreditsOnly(statsNative);
                reportUrl = null;
            }
            else
            {
                Project project = storage.Project;

                var inputDocUrl = await bucket.CreateSignedUrlAsync(project.OSSSourceModel);

                UpdateData updateData = await _arranger.ForUpdateAsync(inputDocUrl, storage.Metadata.TLA, parameters);

                ProcessingResult result = await _fdaClient.UpdateAsync(updateData);

                if (!result.Success)
                {
                    _logger.LogError($"Failed to update '{project.Name}' project.");
                    throw new FdaProcessingException($"Failed to update '{project.Name}' project.", result.ReportUrl);
                }

                _logger.LogInformation("Moving files around");

                // rearrange generated data according to the parameters hash
                // NOTE: hash might be changed if Inventor adjust them!
                hash = await _arranger.MoveViewablesAsync(project, storage.IsAssembly);

                // process statistics
                await bucket.UploadAsJsonAsync(storage.GetOssNames(hash).StatsUpdate, result.Stats);

                stats     = FdaStatsDTO.All(result.Stats);
                reportUrl = result.ReportUrl;
            }

            _logger.LogInformation($"Cache the project locally ({hash})");

            // and now cache the generated stuff locally
            await storage.EnsureViewablesAsync(bucket, hash);

            return(hash, stats, reportUrl);
        }
Example #2
0
        /// <summary>
        /// Generate project data for the given parameters and cache results locally.
        /// </summary>
        /// <returns>Resulting parameters hash</returns>
        private async Task <string> UpdateAsync(Project project, ProjectStorage storage, InventorParameters parameters, string hash, bool bForceUpdate = false)
        {
            _logger.LogInformation("Update the project");
            var bucket = await _userResolver.GetBucketAsync();

            var isUpdateExists = bForceUpdate ? false : await IsGenerated(project, bucket, hash);

            if (isUpdateExists)
            {
                _logger.LogInformation("Detected existing outputs at OSS");
            }
            else
            {
                var inputDocUrl = await bucket.CreateSignedUrlAsync(project.OSSSourceModel);

                UpdateData updateData = await _arranger.ForUpdateAsync(inputDocUrl, storage.Metadata.TLA, parameters);

                ProcessingResult result = await _fdaClient.UpdateAsync(updateData);

                if (!result.Success)
                {
                    _logger.LogError($"Failed to update '{project.Name}' project.");
                    throw new FdaProcessingException($"Failed to update '{project.Name}' project.", result.ReportUrl);
                }

                _logger.LogInformation("Moving files around");

                // rearrange generated data according to the parameters hash
                // NOTE: hash might be changed if Inventor adjust them!
                hash = await _arranger.MoveViewablesAsync(project, storage.IsAssembly);
            }

            _logger.LogInformation($"Cache the project locally ({hash})");

            // and now cache the generate stuff locally
            var projectStorage = new ProjectStorage(project);
            await projectStorage.EnsureViewablesAsync(bucket, hash);

            return(hash);
        }