public async Task <MKit_Kit> GetKitDetailAsync(string userId, long projectSnapshotId, int thumbnailSize) { using var log = BeginFunction(nameof(KitMicroService), nameof(GetKitDetailAsync), userId, projectSnapshotId, thumbnailSize); try { //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var entry = await ProjectMicroService.GetProjectAsync(projectSnapshotId).ConfigureAwait(false); if (entry == null) { log.Result(null); return(null); } log.Message("Project entry retrieved."); var kit = ProjectLibraryKitUtility.CreateKit(entry); log.Message("Kit created."); var result = Create.MKit_Kit(kit, entry.Name, entry.ProjectId, null, thumbnailSize, InventoryMicroService); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <byte[]> GetProjectThumbnailAsync(string userId, Guid projectId, int thumbnailSize) { using var log = BeginFunction(nameof(ProjectUserService), nameof(GetProjectThumbnailAsync), userId, projectId, thumbnailSize); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false); var kit = ProjectLibraryKitUtility.CreateKit(entry); var renderer = new DesignRenderer(); using var image = renderer.CreateBitmap(kit, thumbnailSize); using var ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); var result = ms.ToArray(); log.Result(string.Format("byte[{0}]", result.Length)); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MKit_UpdateSpecificationResponse> UpdateKitSpecificationAsync(string userId, Guid projectId, MKit_KitSpecificationUpdate specificationUpdate) { using var log = BeginFunction(nameof(KitMicroService), nameof(UpdateKitSpecificationAsync), userId, projectId, specificationUpdate); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false); var kit = ProjectLibraryKitUtility.CreateKit(entry); var specification = kit.KitSpecification.Clone(); var standardSizes = kit.Design.GetStandardSizes(); var serviceErrorBuilder = new ServiceErrorBuilder(); UpdateSpecification(specification, specificationUpdate, standardSizes, serviceErrorBuilder); kit.KitSpecification = specification; if (serviceErrorBuilder.ServiceError != null) { serviceErrorBuilder.AddPageError("Kit not updated."); var result = new MKit_UpdateSpecificationResponse() { ServiceError = serviceErrorBuilder.ServiceError }; log.Result(result); return(result); } else { var data = ProjectLibraryKitUtility.CreateProjectSpecification(kit); _ = await ProjectMicroService.UpdateProjectAsync(projectId, data, GetUtcNow()).ConfigureAwait(false); var result = new MKit_UpdateSpecificationResponse(); log.Result(result); return(result); } } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MKit_Kit> GetKitDetailPreviewAsync(string userId, Guid projectId, int thumbnailSize, MKit_KitSpecificationUpdate specificationUpdate) { using var log = BeginFunction(nameof(KitMicroService), nameof(GetKitDetailPreviewAsync), userId, projectId, thumbnailSize, specificationUpdate); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var entry = await ProjectMicroService.GetProjectAsync(projectId).ConfigureAwait(false); if (entry == null) { log.Result(null); return(null); } var kit = ProjectLibraryKitUtility.CreateKit(entry); var specification = kit.KitSpecification.Clone(); var standardSizes = kit.Design.GetStandardSizes(); var serviceErrorBuilder = new ServiceErrorBuilder(); UpdateSpecification(specification, specificationUpdate, standardSizes, serviceErrorBuilder); kit.KitSpecification = specification; var result = Create.MKit_Kit(kit, entry.Name, entry.ProjectId, null, thumbnailSize, InventoryMicroService); if (serviceErrorBuilder.ServiceError != null) { serviceErrorBuilder.AddPageError("One or more input values are incorrect."); result.ServiceError = serviceErrorBuilder.ServiceError; } log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <string> CreateProjectAsync(string userId, string projectType, string projectName, Guid designId) { using var log = BeginFunction(nameof(ProjectUserService), nameof(CreateProjectAsync), projectType, userId, projectName, designId); try { await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); string result; if (projectType == ProjectType_Kit) { var mDesign = await DesignMicroService.GetDesignAsync(designId).ConfigureAwait(false); var design = new Design.Core.Design(JToken.Parse(mDesign.DesignArtifactValue)); var projectData = ProjectLibraryKitUtility.CreateProjectSpecification(design); var ownerReference = CreateOwnerReference.FromUserId(userId); var ownerId = await ProjectMicroService.AllocateOwnerAsync(ownerReference).ConfigureAwait(false); var id = await ProjectMicroService.CreateProjectAsync(ownerId, projectName, ProjectTypeCodes.Kit, mDesign.DesignSnapshotId, projectData, GetUtcNow()).ConfigureAwait(false); result = id.ToString(); } else { throw new ArgumentException(string.Format("Unknown projectType {0}", projectType), nameof(projectType)); } log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }