예제 #1
0
        public async Task <InvokeResult <FirmwareDownloadRequest> > RequestDownloadLinkAsync(string deviceRepoId, string deviceId, string firmwareId, string revisionId, EntityHeader org, EntityHeader user)
        {
            var firmware = await _repo.GetFirmwareAsync(firmwareId);

            if (firmware.OwnerOrganization.Id != org.Id)
            {
                return(InvokeResult <FirmwareDownloadRequest> .FromError("Can not request firmware from a different organization."));
            }

            var revision = firmware.Revisions.SingleOrDefault(rev => rev.Id == revisionId);

            if (revision == null)
            {
                throw new RecordNotFoundException(nameof(FirmwareRevision), revisionId);
            }

            var request = new FirmwareDownloadRequest()
            {
                FirmwareId         = firmwareId,
                FirmwareName       = $"{firmware.FirmwareSku} {revision.VersionCode}",
                OrgId              = org.Id,
                FirmwareRevisionId = revisionId,
                ExpiresUTC         = DateTime.UtcNow.AddMinutes(30).ToJSONString(),
                DeviceId           = deviceId,
                DeviceRepoId       = deviceRepoId,
                Status             = "New",
                PercentRequested   = 0,
            };

            await AuthorizeAsync(firmware, AuthorizeResult.AuthorizeActions.Update, user, org, "updateDeviceFirmware");

            await _repo.AddDownloadRequestAsync(request);

            return(InvokeResult <FirmwareDownloadRequest> .Create(request));
        }
 public static FirmwareDownloadRequestDTO FromRequest(FirmwareDownloadRequest request)
 {
     return(new FirmwareDownloadRequestDTO()
     {
         RowKey = request.DownloadId,
         PartitionKey = request.OrgId,
         Expired = request.Expired,
         DeviceId = request.DeviceId,
         Timestamp = request.Timestamp,
         ExpiresUTC = request.ExpiresUTC,
         FirmwareName = request.FirmwareName,
         PercentRequested = request.PercentRequested,
         Status = request.Status,
         DeviceRepoId = request.DeviceRepoId,
         FirmwareId = request.FirmwareId,
         Error = request.Error,
         FirmwareRevisionId = request.FirmwareRevisionId
     });
 }
예제 #3
0
        public Task UpdateDownloadRequestAsync(FirmwareDownloadRequest request)
        {
            var downloadRequestRepo = new FirmwareDownloadRequestRepo(_repoSettings.FirmwareRequestSettings.AccountId, _repoSettings.FirmwareRequestSettings.AccessKey, _adminLogger);

            return(downloadRequestRepo.UpdateRequestAsync(request));
        }
 public Task UpdateRequestAsync(FirmwareDownloadRequest request)
 {
     return(UpdateAsync(FirmwareDownloadRequestDTO.FromRequest(request)));
 }
 public Task AddRequestAsync(FirmwareDownloadRequest request)
 {
     return(InsertAsync(FirmwareDownloadRequestDTO.FromRequest(request)));
 }