Example #1
0
            protected async Task UpdatePaths(Domain.Models.Directory directory, Guid?parentId)
            {
                string parentPath = null;
                string oldPath    = directory.Path;

                if (parentId.HasValue)
                {
                    var parentDirectory = await _db.Directories.FindAsync(parentId);

                    if (parentDirectory == null)
                    {
                        throw new EntityNotFoundException <Directory>("Parent Directory Not Found");
                    }

                    parentPath = parentDirectory.Path;
                }

                var descendants = await _db.Directories.GetChildren(directory, false).ToListAsync();

                directory.SetPath(parentPath);

                foreach (var desc in descendants)
                {
                    desc.Path = desc.Path.Replace(oldPath, directory.Path);
                }
            }
Example #2
0
            private async Task SetPath(Domain.Models.Directory directory)
            {
                directory.Id = Guid.NewGuid();

                if (!directory.ParentId.HasValue)
                {
                    directory.SetPath();
                }
                else
                {
                    var parentDirectory = await _db.Directories.FindAsync(directory.ParentId);

                    if (parentDirectory == null)
                    {
                        throw new EntityNotFoundException <Directory>("Parent Directory not found");
                    }

                    if (parentDirectory.ProjectId != directory.ProjectId)
                    {
                        throw new ConflictException("Parent and child Directories must be in the same Project");
                    }

                    directory.SetPath(parentDirectory.Path);
                }
            }
Example #3
0
            private async Task <Domain.Models.Workspace[]> CheckForResources(Domain.Models.Directory directory)
            {
                var directories = await _db.Directories
                                  .GetChildren(directory, true)
                                  .Include(d => d.Workspaces)
                                  .ToArrayAsync();

                List <Domain.Models.Workspace> workspaces = new List <Domain.Models.Workspace>();

                foreach (var workspace in directories.SelectMany(d => d.Workspaces))
                {
                    if (workspace.GetState().GetResources().Any())
                    {
                        workspaces.Add(workspace);
                    }
                }

                return(workspaces.ToArray());
            }
Example #4
0
        public async Task <ImportResult> ImportDirectory(Directory existingDir, Domain.Models.Directory dirToImport, bool preserveIds)
        {
            ImportResult           result    = new ImportResult();
            List <AsyncLockResult> fileLocks = new List <AsyncLockResult>();

            try
            {
                result = await this.ImportDirectoryInternal(existingDir, dirToImport, preserveIds, fileLocks);
            }
            finally
            {
                foreach (var lockResult in fileLocks)
                {
                    lockResult.Dispose();
                }
            }

            return(result);
        }
Example #5
0
        public static IQueryable <Domain.Models.Directory> GetChildren(this IQueryable <Domain.Models.Directory> query, Domain.Models.Directory directory, bool includeSelf)
        {
            var pattern = $"{directory.Path}%";

            query = query.Where(d => EF.Functions.Like(d.Path, pattern));

            if (!includeSelf)
            {
                query = query.Where(d => d.Id != directory.Id);
            }

            return(query);
        }