コード例 #1
0
 public void SolutionMustBeInReview()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         var claim = _claimDatastore.ById(x.ClaimId);
         var soln  = _solutionDatastore.ById(claim.SolutionId);
         return(soln.Status == SolutionReviewStatus);
     })
     .WithMessage("Can only add evidence if solution is in review");
 }
 public void MustBeSameOrganisation()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         var orgId     = _context.OrganisationId();
         var claim     = _claimsDatastore.ById(x);
         var claimSoln = _solutionsDatastore.ById(claim?.SolutionId ?? Guid.NewGuid().ToString());
         return(claimSoln?.OrganisationId == orgId);
     })
     .When(x => _context.HasRole(Roles.Supplier))
     .WithMessage("Cannot add/see evidence for other organisation");
 }
コード例 #3
0
 public void MustBeFromSameOrganisation()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         var evidence = _evidenceDatastore.ById(x.EvidenceId);
         var claim    = _claimDatastore.ById(evidence.ClaimId);
         var soln     = _solutionDatastore.ById(claim.SolutionId);
         var orgId    = _context.OrganisationId();
         return(soln.OrganisationId == orgId);
     })
     .WithMessage("Must be from same organisation");
 }
コード例 #4
0
        public SolutionEx BySolution(string solutionId)
        {
            return(GetInternal(() =>
            {
                var retval = new SolutionEx
                {
                    Solution = _solutionDatastore.ById(solutionId),
                    TechnicalContact = _technicalContactDatastore.BySolution(solutionId).ToList(),
                    ClaimedCapability = _claimedCapabilityDatastore.BySolution(solutionId).ToList(),
                    ClaimedStandard = _claimedStandardDatastore.BySolution(solutionId).ToList()
                };

                // populate Evidence + Review
                retval.ClaimedCapabilityEvidence = retval.ClaimedCapability
                                                   .SelectMany(cc => _claimedCapabilityEvidenceDatastore.ByClaim(cc.Id))
                                                   .SelectMany(x => x)
                                                   .ToList();
                retval.ClaimedCapabilityReview = retval.ClaimedCapabilityEvidence
                                                 .SelectMany(cce => _claimedCapabilityReviewsDatastore.ByEvidence(cce.Id))
                                                 .SelectMany(x => x)
                                                 .ToList();
                retval.ClaimedStandardEvidence = retval.ClaimedStandard
                                                 .SelectMany(cs => _claimedStandardEvidenceDatastore.ByClaim(cs.Id))
                                                 .SelectMany(x => x)
                                                 .ToList();
                retval.ClaimedStandardReview = retval.ClaimedStandardEvidence
                                               .SelectMany(cse => _claimedStandardReviewsDatastore.ByEvidence(cse.Id))
                                               .SelectMany(x => x)
                                               .ToList();

                return retval;
            }));
        }
コード例 #5
0
        public T FilterForSupplier(T input)
        {
            // Supplier: only own Claims
            var soln = _solutionDatastore.ById(input.SolutionId);

            return(_context.OrganisationId() == soln?.OrganisationId ? input : null);
        }
コード例 #6
0
        public SolutionEx BySolution(string solutionId)
        {
            return(GetInternal(() =>
            {
                var retval = new SolutionEx
                {
                    Solution = _solutionDatastore.ById(solutionId),
                    TechnicalContact = _technicalContactDatastore.BySolution(solutionId).ToList(),
                    ClaimedCapability = _claimedCapabilityDatastore.BySolution(solutionId).ToList(),
                    ClaimedStandard = _claimedStandardDatastore.BySolution(solutionId).ToList(),
                    Organisation = _organisationsDatastore.ById(_solutionDatastore.ById(solutionId)?.OrganisationId)
                };

                return retval;
            }));
        }
        public virtual IActionResult ApiSolutionsByIdByIdGet([FromRoute][Required] string id)
        {
            try
            {
                var solution = _datastore.ById(id);

                if (solution.Id == Guid.Empty)
                {
                    return(StatusCode(404));
                }

                return(new ObjectResult(solution));
            }
            catch (Crm.CrmApiException ex)
            {
                return(StatusCode((int)ex.HttpStatus, ex.Message));
            }
        }
        public T FilterForNone(T input)
        {
            // None:  only approved solutions
            var noneSoln = _solutionsFilter.Filter(new[] { _solutionDatastore.ById(input.SolutionId) }).SingleOrDefault();

            if (noneSoln == null)
            {
                return(null);
            }

            return(input);
        }
        public override TechnicalContacts Filter(TechnicalContacts input)
        {
            // None:  only approved solutions
            var noneSoln = _solutionsFilter.Filter(new[] { _solutionDatastore.ById(input.SolutionId) }).SingleOrDefault();

            if (noneSoln == null)
            {
                return(null);
            }

            return(input);
        }
コード例 #10
0
 public void MustBeSameOrganisation()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         var orgId     = _context.OrganisationId();
         var claim     = _claimDatastore.ById(x.Id);
         var claimSoln = _solutionsDatastore.ById(claim?.SolutionId ?? x.SolutionId);
         return(claimSoln?.OrganisationId == orgId);
     })
     .WithMessage("Cannot create/change claim for other organisation");
 }
コード例 #11
0
        public override TechnicalContacts Filter(TechnicalContacts input)
        {
            if (_context.HasRole(Roles.Admin) ||
                _context.HasRole(Roles.Buyer))
            {
                return(input);
            }

            // Supplier: only own TechnicalContacts
            var soln = _solutionDatastore.ById(input.SolutionId);

            return(_context.OrganisationId() == soln.OrganisationId ? input : null);
        }
コード例 #12
0
        public IEnumerable <ClaimBlobInfoMap> EnumerateClaimFolderTree(string solutionId)
        {
            _validator.ValidateAndThrowEx(solutionId, ruleSet: nameof(IEvidenceBlobStoreLogic.EnumerateClaimFolderTree));

            var soln = _solutionsDatastore.ById(solutionId);

            if (soln == null)
            {
                throw new KeyNotFoundException($"Could not find solution: {solutionId}");
            }

            return(_evidenceBlobStoreDatastore.EnumerateClaimFolderTree(this, solutionId));
        }
コード例 #13
0
 public void MustBeValidStatusTransition()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         /// NOTE:  null solution check is not quite correct
         /// as this would result in a FK exception if we let it through
         /// but it is good enough for the moment
         var soln = _solutionDatastore.ById(x.Id);
         if (soln == null)
         {
             return(false);
         }
         var oldStatus = soln.Status;
         var newStatus = x.Status;
         return(ValidStatusTransitions(_context).Any(
                    trans =>
                    trans.OldStatus == oldStatus &&
                    trans.NewStatus == newStatus &&
                    trans.HasValidRole));
     })
     .WithMessage("Invalid Status transition");
 }
コード例 #14
0
 public void SupplierOwn()
 {
     RuleFor(x => x)
     .Must(x =>
     {
         if (_context.HasRole(Roles.Supplier))
         {
             var soln = _solutionDatastore.ById(x.SolutionId);
             return(_context.OrganisationId() == soln.OrganisationId);
         }
         return(_context.HasRole(Roles.Admin));
     })
     .WithMessage("Supplier can only change own Technical Contacts");
 }
コード例 #15
0
        public T FilterForSupplier(T input)
        {
            // Supplier: only own Claims
            foreach (var evidence in input)
            {
                var claim = _claimDatastore.ById(evidence.ClaimId);
                var soln  = _solutionDatastore.ById(claim.SolutionId);
                if (_context.OrganisationId() != soln?.OrganisationId)
                {
                    return(default(T));
                }
            }

            return(input);
        }
コード例 #16
0
 public Solutions ById(string id)
 {
     return(_filter.Filter(new[] { _datastore.ById(id) }).SingleOrDefault());
 }
        private string UploadFileSlicePerSlice(
            IClaimsInfoProvider claimsInfoProvider,
            string claimId,
            Stream file,
            string fileName,
            string subFolder,
            int fileChunkSizeInMB = 3)
        {
            // Each sliced upload requires a unique id
            var uploadId = Guid.NewGuid();

            // Get to folder to upload into
            var claim             = claimsInfoProvider.GetClaimById(claimId);
            var soln              = _solutionsDatastore.ById(claim.SolutionId);
            var org               = _organisationsDatastore.ById(soln.OrganisationId);
            var solnVer           = GetSolutionVersionFolderName(soln);
            var claimFolderRelUrl = Url.Combine(
                SharePoint_OrganisationsRelativeUrl,
                CleanupFileName(org.Name),
                solnVer,
                CleanupFileName(claimsInfoProvider.GetFolderName()),
                CleanupFileName(claimsInfoProvider.GetFolderClaimName(claim)));

            // create subFolder if not exists
            if (!string.IsNullOrEmpty(subFolder))
            {
                CreateSubFolder(claimFolderRelUrl, subFolder);
                claimFolderRelUrl = Url.Combine(claimFolderRelUrl, subFolder);
            }

            var context        = GetClientContext();
            var docClaimFolder = context.Web.GetFolderByServerRelativeUrl(claimFolderRelUrl);

            context.ExecuteQuery();

            // Get the information about the folder that will hold the file
            LogInformation($"UploadFileSlicePerSlice: enumerating {Url.Combine(context.Url, claimFolderRelUrl)}...");
            context.Load(docClaimFolder.Files);
            context.Load(docClaimFolder, folder => folder.ServerRelativeUrl);
            context.ExecuteQuery();

            using (var br = new BinaryReader(file))
            {
                var fileSize = file.Length;
                ClientResult <long> bytesUploaded = null;
                Microsoft.SharePoint.Client.NetCore.File uploadFile = null;

                // Calculate block size in bytes
                var blockSize = fileChunkSizeInMB * 1024 * 1024;

                byte[] buffer         = new byte[blockSize];
                byte[] lastBuffer     = null;
                long   fileoffset     = 0;
                long   totalBytesRead = 0;
                int    bytesRead;
                bool   first = true;
                bool   last  = false;

                // Read data from stream in blocks
                while ((bytesRead = br.Read(buffer, 0, buffer.Length)) > 0)
                {
                    totalBytesRead += bytesRead;

                    // We've reached the end of the file
                    if (totalBytesRead == fileSize)
                    {
                        last = true;

                        // Copy to a new buffer that has the correct size
                        lastBuffer = new byte[bytesRead];
                        Array.Copy(buffer, 0, lastBuffer, 0, bytesRead);
                    }

                    if (first)
                    {
                        using (var contentStream = new MemoryStream())
                        {
                            // Add an empty file.
                            var fileInfo = new FileCreationInformation
                            {
                                ContentStream = contentStream,
                                Url           = fileName,
                                Overwrite     = true
                            };
                            uploadFile = docClaimFolder.Files.Add(fileInfo);

                            // Start upload by uploading the first slice
                            // NOTE:  small files will be contained in the lastBuffer, so use this to upload in one call
                            using (var strm = new MemoryStream(last ? lastBuffer : buffer))
                            {
                                // Call the start upload method on the first slice
                                bytesUploaded = uploadFile.StartUpload(uploadId, strm);

                                LogInformation($"UploadFileSlicePerSlice: uploading first slice...");
                                context.ExecuteQuery();

                                // fileoffset is the pointer where the next slice will be added
                                fileoffset = bytesUploaded.Value;
                            }

                            // NOTE:  small files have already been uploaded from lastBuffer, so reset it
                            lastBuffer = new byte[0];
                        }
                    }

                    // Get a reference to our file
                    LogInformation($"UploadFileSlicePerSlice: getting reference to file...");
                    uploadFile = context.Web.GetFileByServerRelativeUrl(Url.Combine(docClaimFolder.ServerRelativeUrl, fileName));

                    if (last)
                    {
                        // Is this the last slice of data?
                        using (var strm = new MemoryStream(lastBuffer))
                        {
                            // End sliced upload by calling FinishUpload
                            LogInformation($"UploadFileSlicePerSlice: uploading last slice...");
                            uploadFile = uploadFile.FinishUpload(uploadId, fileoffset, strm);
                            context.Load(uploadFile);
                            context.ExecuteQuery();

                            return(uploadFile.UniqueId.ToString());
                        }
                    }

                    if (first)
                    {
                        // we can only start the upload once
                        first = false;

                        continue;
                    }

                    using (var strm = new MemoryStream(buffer))
                    {
                        // Continue sliced upload
                        LogInformation($"UploadFileSlicePerSlice: uploading intermediate slice...");
                        bytesUploaded = uploadFile.ContinueUpload(uploadId, fileoffset, strm);
                        context.ExecuteQuery();

                        // update fileoffset for the next slice
                        fileoffset = bytesUploaded.Value;
                    }
                }
            }

            return(string.Empty);
        }