Beispiel #1
0
        private async Task <WopiResponse> ProcessPutRelativeFileRequestAsync(PutRelativeFileRequest wopiRequest,
                                                                             CancellationToken cancellationToken)
        {
            if (!int.TryParse(wopiRequest.FileId, out var contentId))
            {
                return new WopiResponse {
                           StatusCode = HttpStatusCode.NotFound
                }
            }
            ;
            if (!(await Node.LoadNodeAsync(contentId, cancellationToken).ConfigureAwait(false) is File file))
            {
                return new WopiResponse {
                           StatusCode = HttpStatusCode.NotFound
                }
            }
            ;

            var allowIncrementalNaming = wopiRequest.SuggestedTarget != null;
            var allowOverwrite         = wopiRequest.OverwriteRelativeTarget;
            var targetName             = wopiRequest.SuggestedTarget ?? wopiRequest.RelativeTarget;

            if (targetName.StartsWith("."))
            {
                targetName = Path.GetFileNameWithoutExtension(file.Name) + targetName;
            }

            File targetFile = null;

            if (!allowIncrementalNaming)
            {
                var targetPath = $"{file.ParentPath}/{targetName}";
                var node       = await Node.LoadNodeAsync(targetPath, cancellationToken).ConfigureAwait(false);

                if (node != null)
                {
                    if (!allowOverwrite || !(node is File loadedFile))
                    {
                        return new PutRelativeFileResponse {
                                   StatusCode = HttpStatusCode.NotImplemented
                        }
                    }
                    ;
                    targetFile = loadedFile;
                }
            }

            if (targetFile == null)
            {
                targetFile = new File(file.Parent)
                {
                    Name = targetName
                };
                targetFile.AllowIncrementalNaming = allowIncrementalNaming;
            }
            else
            {
                throw new NotImplementedException(); //TODO:WOPI: ProcessPutRelativeFileRequest Check lock
            }

            targetFile.Binary.FileName = targetName;
            targetFile.Binary.SetStream(wopiRequest.RequestStream);
            targetFile.Save();              //TODO:WOPI: ProcessPutRelativeFileRequest shared lock?

            var url = "__notimplemented__"; //TODO:WOPI: ProcessPutRelativeFileRequest Generate correct URL

            return(new PutRelativeFileResponse
            {
                StatusCode = HttpStatusCode.NotImplemented,
                Name = targetFile.Name,
                Url = url,
            });
        }
Beispiel #2
0
        private WopiResponse ProcessPutRelativeFileRequest(PutRelativeFileRequest wopiReq, PortalContext portalContext)
        {
            if (!int.TryParse(wopiReq.FileId, out var contentId))
            {
                return new WopiResponse {
                           StatusCode = HttpStatusCode.NotFound
                }
            }
            ;
            if (!(Node.LoadNode(contentId) is File file))
            {
                return new WopiResponse {
                           StatusCode = HttpStatusCode.NotFound
                }
            }
            ;

            var allowIncrementalNaming = wopiReq.SuggestedTarget != null;
            var allowOverwrite         = wopiReq.OverwriteRelativeTarget;
            var targetName             = wopiReq.SuggestedTarget ?? wopiReq.RelativeTarget;

            if (targetName.StartsWith("."))
            {
                targetName = Path.GetFileNameWithoutExtension(file.Name) + targetName;
            }

            File targetFile = null;

            if (!allowIncrementalNaming)
            {
                var targetPath = $"{file.ParentPath}/{targetName}";
                var node       = Node.LoadNode(targetPath);
                if (node != null)
                {
                    if (!allowOverwrite || !(node is File loadedFile))
                    {
                        return new PutRelativeFileResponse {
                                   StatusCode = HttpStatusCode.NotImplemented
                        }
                    }
                    ;

                    targetFile = loadedFile;
                }
            }

            if (targetFile == null)
            {
                targetFile = new File(file.Parent)
                {
                    Name = targetName
                };
                targetFile.AllowIncrementalNaming = allowIncrementalNaming;
            }
            else
            {
                throw new NotImplementedException(); //UNDONE:! Check lock
            }

            targetFile.Binary.FileName = targetName;
            targetFile.Binary.SetStream(wopiReq.RequestStream);
            targetFile.Save();

            var url = "__notimplemented__"; //UNDONE:! Generate correct URL

            return(new PutRelativeFileResponse
            {
                StatusCode = HttpStatusCode.OK,
                Name = targetFile.Name,
                Url = url,
            });
        }