private async Task <MobileAppContentFile> AddContentFileAsync(IMobileAppContentRequestBuilder requestBuilder, IntuneAppPackage package) { return(await requestBuilder.Files.Request() .WithMaxRetry(10) .WithRetryDelay(30) .WithShouldRetry((delay, count, r) => r.StatusCode == HttpStatusCode.NotFound) .AddAsync(package.File)); }
private async Task CreateAppContentFileAsync(IMobileAppContentRequestBuilder requestBuilder, IntuneAppPackage package) { // add content file var contentFile = await AddContentFileAsync(requestBuilder, package); // refetch until we can get the uri to upload to contentFile = await WaitForStateAsync(requestBuilder.Files[contentFile.Id], MobileAppContentFileUploadState.AzureStorageUriRequestSuccess); var sw = Stopwatch.StartNew(); await CreateBlobAsync(package, contentFile, requestBuilder.Files[contentFile.Id]); logger.LogInformation($"Uploaded app content file in {sw.ElapsedMilliseconds}ms."); // commit await requestBuilder.Files[contentFile.Id].Commit(package.EncryptionInfo).Request().PostAsync(); // refetch until has committed await WaitForStateAsync(requestBuilder.Files[contentFile.Id], MobileAppContentFileUploadState.CommitFileSuccess); }
private async Task CreateAppContentFileAsync(IMobileAppContentRequestBuilder requestBuilder, IntuneAppPackage package) { // add content file var contentFile = await AddContentFileAsync(requestBuilder, package); // waits for the desired status, refreshing the file along the way async Task WaitForStateAsync(MobileAppContentFileUploadState state) { logger.LogInformation($"Waiting for app content file to have a state of {state}."); // ReSharper disable AccessToModifiedClosure - intended var waitStopwatch = Stopwatch.StartNew(); while (true) { contentFile = await requestBuilder.Files[contentFile.Id].Request().GetAsync(); if (contentFile.UploadState == state) { logger.LogInformation($"Waited {waitStopwatch.ElapsedMilliseconds}ms for app content file to have a state of {state}."); return; } var failedStates = new[] { MobileAppContentFileUploadState.AzureStorageUriRequestFailed, MobileAppContentFileUploadState.AzureStorageUriRenewalFailed, MobileAppContentFileUploadState.CommitFileFailed }; if (failedStates.Contains(contentFile.UploadState.GetValueOrDefault())) { throw new InvalidOperationException($"{nameof(contentFile.UploadState)} is in a failed state of {contentFile.UploadState} - was waiting for {state}."); } const int waitTimeout = 240000; const int testInterval = 2000; if (waitStopwatch.ElapsedMilliseconds > waitTimeout) { throw new InvalidOperationException($"Timed out waiting for {nameof(contentFile.UploadState)} of {state} - current state is {contentFile.UploadState}."); } await Task.Delay(testInterval); } // ReSharper restore AccessToModifiedClosure } // refetch until we can get the uri to upload to await WaitForStateAsync(MobileAppContentFileUploadState.AzureStorageUriRequestSuccess); var sw = Stopwatch.StartNew(); await CreateBlobAsync(package, contentFile); logger.LogInformation($"Uploaded app content file in {sw.ElapsedMilliseconds}ms."); // commit await requestBuilder.Files[contentFile.Id].Commit(package.EncryptionInfo).Request().PostAsync(); // refetch until has committed await WaitForStateAsync(MobileAppContentFileUploadState.CommitFileSuccess); }