public async Task <IEnumerable <string> > ItemizeAllAsync(IStatus status) { var enumerateGameDetailsDirectoriesTask = await statusController.CreateAsync(status, "Enumerate gameDetails directories"); var directories = new List <string>(); var current = 0; var gameDetailsIds = await gameDetailsDataController.ItemizeAllAsync(enumerateGameDetailsDirectoriesTask); var gameDetailsCount = await gameDetailsDataController.CountAsync(enumerateGameDetailsDirectoriesTask); foreach (var id in gameDetailsIds) { var gameDetails = await gameDetailsDataController.GetByIdAsync(id, enumerateGameDetailsDirectoriesTask); await statusController.UpdateProgressAsync( enumerateGameDetailsDirectoriesTask, ++current, gameDetailsCount, gameDetails.Title); directories.AddRange( await itemizeGameDetailsDirectoriesAsyncDelegate.ItemizeAsync( gameDetails, enumerateGameDetailsDirectoriesTask)); } await statusController.CompleteAsync(enumerateGameDetailsDirectoriesTask); return(directories); }
public async Task <IEnumerable <string> > ItemizeAsync(GameDetails gameDetails, IStatus status) { var enumerateGameDetailsFilesStatus = await statusController.CreateAsync(status, "Enumerate game details files"); var gameDetailsFiles = new List <string>(); var gameDetailsManualUrls = await itemizeGameDetailsManualUrlsDelegate.ItemizeAsync(gameDetails, status); var gameDetailsManualUrlsCount = gameDetailsManualUrls.Count(); var gameDetailsResolvedUris = await routingController.TraceRoutesAsync( gameDetails.Id, gameDetailsManualUrls, enumerateGameDetailsFilesStatus); // that means that routes information is incomplete and // it's not possible to map manualUrls to resolvedUrls if (gameDetailsManualUrlsCount != gameDetailsResolvedUris.Count) { await statusController.CompleteAsync(enumerateGameDetailsFilesStatus); throw new ArgumentException($"Product {gameDetails.Id} resolvedUris count doesn't match manualUrls count"); } for (var ii = 0; ii < gameDetailsResolvedUris.Count; ii++) { // since we don't download all languages and operating systems // we don't have routes for each and every gameDetails uri // however the ones we have should represent expected files for that product if (string.IsNullOrEmpty(gameDetailsResolvedUris[ii])) { continue; } //var localFileUri = Path.Combine( // getDirectoryDelegate.GetDirectory(gameDetailsManualUrls.ElementAt(ii)), //getFilenameDelegate.GetFilename(gameDetailsResolvedUris[ii])); var localFilePath = getPathDelegate.GetPath( gameDetailsManualUrls.ElementAt(ii), gameDetailsResolvedUris[ii]); gameDetailsFiles.Add(localFilePath); } await statusController.CompleteAsync(enumerateGameDetailsFilesStatus); if (gameDetailsManualUrlsCount != gameDetailsFiles.Count) { throw new ArgumentException($"Product {gameDetails.Id} files count doesn't match manualUrls count"); } return(gameDetailsFiles); }
public async Task <IEnumerable <string> > ItemizeAsync(GameDetails gameDetails, IStatus status) { var gameDetailsDirectories = new List <string>(); foreach (var manualUrl in await itemizeGameDetailsManualUrlsAsyncDelegate.ItemizeAsync(gameDetails, status)) { var directory = getDirectoryDelegate.GetDirectory(manualUrl); if (!gameDetailsDirectories.Contains(directory)) { gameDetailsDirectories.Add(directory); } } return(gameDetailsDirectories); }
public async Task <IDictionary <long, IList <string> > > GetDownloadSourcesAsync(IStatus status) { var getDownloadSourcesStatus = await statusController.CreateAsync(status, "Get download sources"); var gameDetailsDownloadSources = new Dictionary <long, IList <string> >(); var current = 0; foreach (var id in await updatedDataController.ItemizeAllAsync(getDownloadSourcesStatus)) { await statusController.UpdateProgressAsync( getDownloadSourcesStatus, ++current, await updatedDataController.CountAsync(getDownloadSourcesStatus), id.ToString()); var gameDetails = await gameDetailsDataController.GetByIdAsync(id, getDownloadSourcesStatus); if (!gameDetailsDownloadSources.ContainsKey(id)) { gameDetailsDownloadSources.Add(id, new List <string>()); } foreach (var manualUrl in await itemizeGameDetailsManualUrlsAsyncController.ItemizeAsync(gameDetails, status)) { if (!gameDetailsDownloadSources[id].Contains(manualUrl)) { gameDetailsDownloadSources[id].Add(manualUrl); } } } await statusController.CompleteAsync(getDownloadSourcesStatus); return(gameDetailsDownloadSources); }
public override async Task ProcessActivityAsync(IStatus status) { var validateProductsStatus = await statusController.CreateAsync(status, "Validate products"); var current = 0; var validateProductsList = await itemizeAllProductsAsyncDelegate.ItemizeAllAsync(validateProductsStatus); var validateProductsCount = validateProductsList.Count(); foreach (var id in validateProductsList) { var gameDetails = await gameDetailsDataController.GetByIdAsync(id, validateProductsStatus); var validationResults = await validationResultsDataController.GetByIdAsync(id, validateProductsStatus); if (validationResults == null) { validationResults = new ValidationResult { Id = id, Title = gameDetails.Title } } ; await statusController.UpdateProgressAsync(validateProductsStatus, ++current, validateProductsCount, gameDetails.Title); var localFiles = new List <string>(); var getLocalFilesTask = await statusController.CreateAsync(validateProductsStatus, "Enumerate local product files"); foreach (var manualUrl in await itemizeGameDetailsManualUrlsAsyncDelegate.ItemizeAsync(gameDetails, getLocalFilesTask)) { var resolvedUri = await routingController.TraceRouteAsync(id, manualUrl, getLocalFilesTask); // use directory from source and file from resolved URI var localFile = Path.Combine( productFileDirectoryDelegate.GetDirectory(manualUrl), productFileFilenameDelegate.GetFilename(resolvedUri)); localFiles.Add(localFile); } await statusController.CompleteAsync(getLocalFilesTask); // check if current validation results allow us to skip validating current product // otherwise - validate all the files again // ... var fileValidationResults = new List <IFileValidationResult>(localFiles.Count); var validateFilesTask = await statusController.CreateAsync( validateProductsStatus, "Validate product files"); var currentFile = 0; foreach (var localFile in localFiles) { await statusController.UpdateProgressAsync(validateFilesTask, ++currentFile, localFiles.Count, localFile); var validationFile = formatValidationFileDelegate.Format(localFile); try { fileValidationResults.Add(await fileValidationController.ValidateFileAsync( localFile, validationFile, validateFilesTask)); } catch (Exception ex) { await statusController.FailAsync(validateProductsStatus, $"{localFile}: {ex.Message}"); } } await statusController.CompleteAsync(validateFilesTask); validationResults.Files = fileValidationResults.ToArray(); var updateValidationResultsTask = await statusController.CreateAsync( validateProductsStatus, "Update validation results"); await validationResultsDataController.UpdateAsync(validationResults, validateProductsStatus); await statusController.CompleteAsync(updateValidationResultsTask); } await statusController.CompleteAsync(validateProductsStatus); } }