Ejemplo n.º 1
0
        static bool AllowCopyOrMove(FileItemPathInfo pathInfo, FileItemPathInfo destinationPathInfo)
        {
            var sourcePathParts      = pathInfo.GetPathParts <int>();
            var destinationPathParts = destinationPathInfo.GetPathParts <int>();

            if (destinationPathParts.Length < sourcePathParts.Length)
            {
                return(true);
            }

            var isValid = false;

            for (var i = 0; i < destinationPathParts.Length && !isValid; i++)
            {
                isValid = destinationPathParts[i].Key != sourcePathParts[i].Key;
            }
            return(isValid);
        }
Ejemplo n.º 2
0
        bool IsFileItemExists(FileItemPathInfo pathInfo)
        {
            var clientPathParts = pathInfo.GetPathParts <int>();
            var pathKeys        = clientPathParts.Select(p => p.Key).ToArray();
            var foundEntries    = FileManagementDbContext.FileItems
                                  .Where(item => pathKeys.Contains(item.Id))
                                  .Select(item => new { item.Id, item.ParentId, item.Name, item.IsDirectory });

            var isDirectoryExists = true;

            for (var i = 0; i < clientPathParts.Length && isDirectoryExists; i++)
            {
                var entry = foundEntries.FirstOrDefault(e => e.Id == clientPathParts[i].Key);
                isDirectoryExists = entry != null && entry.Name == clientPathParts[i].Name &&
                                    (i == 0 && entry.ParentId == 0 || entry.ParentId == clientPathParts[i - 1].Key);
                if (isDirectoryExists && i < clientPathParts.Length - 1)
                {
                    isDirectoryExists = entry.IsDirectory;
                }
            }
            return(isDirectoryExists);
        }