Exemplo n.º 1
0
        private async Task <List <Guid> > CheckSubFolders(StorageFolder subFolder)
        {
            var      artifactsInserted = new List <Guid>();
            Category category;

            if (!await _categoryRepository.DoesExist(subFolder.Name))
            {
                // category does not exist, create it
                category = new Category
                {
                    Name   = subFolder.Name,
                    Active = true
                };
                await _categoryRepository.SaveAsync(category);
            }
            else
            {
                category = await _categoryRepository.Get(subFolder.Name);
            }

            var subFolderArtifacts = await subFolder.GetFilesAsync();

            foreach (StorageFile artifact in subFolderArtifacts)
            {
                Artifact newArtifact;
                if (!await _artifactRepo.DoesExist(artifact.Name))
                {
                    // artifact doesn't exist, create one
                    newArtifact = await InsertArtifact(artifact);

                    artifactsInserted.Add(newArtifact.ID);
                }
                else
                {
                    newArtifact = await _artifactRepo.GetArtifactByFileName(artifact.Name);
                }
                if (!await _artifactCategoryRepository.DoesExist(newArtifact, category))
                {
                    // need to add the artifact to the newly created category
                    await _artifactCategoryRepository.AddRelationship(newArtifact, category);
                }
            }

            var moreSubFolders = await subFolder.GetFoldersAsync();

            foreach (StorageFolder anotherSubFolder in moreSubFolders)
            {
                //TODO add sub category Relationship here
                artifactsInserted.AddRange(await CheckSubFolders(anotherSubFolder));
            }

            return(artifactsInserted);
        }