Beispiel #1
0
        public Task <bool> IsReferenceAllowedAsync(UserId requester, Shared.FileId fileId)
        {
            requester.AssertNotNull("requester");
            fileId.AssertNotNull("fileId");

            return(this.fileOwnership.IsOwnerAsync(requester, fileId));
        }
Beispiel #2
0
        public CreateThumbnailsMessage(
            Fifthweek.Api.FileManagement.Shared.FileId fileId,
            System.String containerName,
            System.String inputBlobName,
            System.Collections.Generic.List <Fifthweek.WebJobs.Thumbnails.Shared.ThumbnailDefinition> items,
            System.Boolean overwrite)
        {
            if (fileId == null)
            {
                throw new ArgumentNullException("fileId");
            }

            if (containerName == null)
            {
                throw new ArgumentNullException("containerName");
            }

            if (inputBlobName == null)
            {
                throw new ArgumentNullException("inputBlobName");
            }

            if (overwrite == null)
            {
                throw new ArgumentNullException("overwrite");
            }

            this.FileId        = fileId;
            this.ContainerName = containerName;
            this.InputBlobName = inputBlobName;
            this.Items         = items;
            this.Overwrite     = overwrite;
        }
Beispiel #3
0
        public async Task <FileWaitingForUpload> ExecuteAsync(Shared.FileId fileId)
        {
            fileId.AssertNotNull("fileId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                var items = await connection.QueryAsync <File>(
                    string.Format(
                        @"SELECT {1}, {2}, {3}, {4} FROM Files WHERE {0}=@FileId",
                        File.Fields.Id,
                        File.Fields.UserId,
                        File.Fields.FileNameWithoutExtension,
                        File.Fields.FileExtension,
                        File.Fields.Purpose),
                    new { FileId = fileId.Value });

                var result = items.SingleOrDefault();

                if (result == null)
                {
                    throw new InvalidOperationException("The file " + fileId + " couldn't be found.");
                }

                return(new FileWaitingForUpload(fileId, new UserId(result.UserId), result.FileNameWithoutExtension, result.FileExtension, result.Purpose));
            }
        }
Beispiel #4
0
        public async Task AssertReferenceAllowedAsync(UserId requester, Shared.FileId fileId)
        {
            requester.AssertNotNull("requester");
            fileId.AssertNotNull("fileId");

            var isUsageAllowed = await this.IsReferenceAllowedAsync(requester, fileId);

            if (!isUsageAllowed)
            {
                throw new UnauthorizedException("The user " + requester.Value + " does not have permission to reference file " + fileId.Value);
            }
        }
Beispiel #5
0
        public async Task ExecuteAsync(
            Shared.FileId fileId,
            UserId userId,
            ChannelId channelId,
            string fileNameWithoutExtension,
            string fileExtension,
            string purpose,
            DateTime timeStamp)
        {
            fileId.AssertNotNull("fileId");
            userId.AssertNotNull("userId");
            fileNameWithoutExtension.AssertNotNull("fileNameWithoutExtension");
            fileExtension.AssertNotNull("fileExtension");
            purpose.AssertNotNull("purpose");

            if (fileNameWithoutExtension.Length > File.MaximumFileNameLength)
            {
                fileNameWithoutExtension = fileNameWithoutExtension.Substring(0, File.MaximumFileNameLength);
            }

            if (fileExtension.Length > File.MaximumFileExtensionLength)
            {
                fileExtension = fileExtension.Substring(0, File.MaximumFileExtensionLength);
            }

            var file = new File(
                fileId.Value,
                userId.Value,
                channelId == null ? (Guid?)null : channelId.Value,
                FileState.WaitingForUpload,
                timeStamp,
                null,
                null,
                null,
                null,
                fileNameWithoutExtension,
                fileExtension,
                0L,
                purpose,
                null,
                null);

            using (var connection = this.connectionFactory.CreateConnection())
            {
                await connection.InsertAsync(file);
            }
        }
        public OrphanedFileData(
            Fifthweek.Api.FileManagement.Shared.FileId fileId,
            Fifthweek.Api.Channels.Shared.ChannelId channelId,
            System.String purpose)
        {
            if (fileId == null)
            {
                throw new ArgumentNullException("fileId");
            }

            if (purpose == null)
            {
                throw new ArgumentNullException("purpose");
            }

            this.FileId    = fileId;
            this.ChannelId = channelId;
            this.Purpose   = purpose;
        }
        public async Task ExecuteAsync(Shared.FileId fileId, long blobSize, DateTime timeStamp)
        {
            fileId.AssertNotNull("fileId");

            var newFile = new File
            {
                State = FileState.UploadComplete,
                UploadCompletedDate = timeStamp,
                BlobSizeBytes       = blobSize,
                Id = fileId.Value,
            };

            using (var connection = this.connectionFactory.CreateConnection())
            {
                await connection.UpdateAsync(
                    newFile,
                    File.Fields.State | File.Fields.UploadCompletedDate | File.Fields.BlobSizeBytes);
            }
        }
Beispiel #8
0
        public async Task <bool> IsOwnerAsync(UserId userId, Shared.FileId fileId)
        {
            userId.AssertNotNull("userId");
            fileId.AssertNotNull("fileId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                return(await connection.ExecuteScalarAsync <bool>(
                           @"IF EXISTS(SELECT *
                                FROM   Files
                                WHERE  Id = @FileId
                                AND    UserId = @UserId)
                        SELECT 1 AS FOUND
                    ELSE
                        SELECT 0 AS FOUND",
                           new
                {
                    FileId = fileId.Value,
                    UserId = userId.Value
                }));
            }
        }
Beispiel #9
0
        public async Task <string> ExecuteAsync(Shared.FileId fileId)
        {
            fileId.AssertNotNull("fileId");

            using (var connection = this.connectionFactory.CreateConnection())
            {
                var extension = await connection.ExecuteScalarAsync <string>(
                    @"SELECT FileExtension
                      FROM   Files
                      WHERE  Id = @FileId",
                    new
                {
                    FileId = fileId.Value
                });

                if (extension == null)
                {
                    throw new Exception(string.Format("File not found. {0}", fileId));
                }

                return(extension);
            }
        }