예제 #1
0
        public HttpResponseMessage Put(int accessTokenId)
        {
            var token = _tokenManager.GetToken(accessTokenId);

            var bytes = Request.Content.ReadAsByteArrayAsync().Result;

            _webDavManager.UploadFile(token.FilePath, bytes);

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
예제 #2
0
        public ActionResult UploadFilePost(string org, string pathPart)
        {
            var uploadResults = new List <UploadFileResult>();

            foreach (string file in Request.Files)
            {
                var hpf = Request.Files[file] as HttpPostedFileBase;

                if (hpf == null || hpf.ContentLength == 0)
                {
                    continue;
                }

                _webdavManager.UploadFile(pathPart, hpf);

                uploadResults.Add(new UploadFileResult()
                {
                    name = hpf.FileName,
                    size = hpf.ContentLength,
                    type = hpf.ContentType
                });
            }

            var result = Json(new { files = uploadResults });

            //for IE8 which does not accept application/json
            if (Request.Headers["Accept"] != null && !Request.Headers["Accept"].Contains("application/json"))
            {
                result.ContentType = MediaTypeNames.Text.Plain;
            }

            return(result);
        }
예제 #3
0
        public Atom ProcessRequest(int accessTokenId, Stream requestStream)
        {
            var token = _tokenManager.GetToken(accessTokenId);

            var atomRequest = new AtomFromStream(requestStream);

            var requestBatch = new RequestBatch();

            try
            {
                var cobaltFile = _fileManager.Get(token.FilePath) ?? _fileManager.Create(accessTokenId);

                Object          ctx;
                ProtocolVersion protocolVersion;

                requestBatch.DeserializeInputFromProtocol(atomRequest, out ctx, out protocolVersion);
                cobaltFile.CobaltEndpoint.ExecuteRequestBatch(requestBatch);


                foreach (var request in requestBatch.Requests)
                {
                    if (request.GetType() == typeof(PutChangesRequest) &&
                        request.PartitionId == FilePartitionId.Content && request.CompletedSuccessfully)
                    {
                        using (var saveStream = new MemoryStream())
                        {
                            CopyStream(cobaltFile, saveStream);
                            _webDavManager.UploadFile(token.FilePath, saveStream.ToArray());
                        }
                    }
                }


                return(requestBatch.SerializeOutputToProtocol(protocolVersion));
            }

            catch (Exception e)
            {
                Server.Utils.Log.WriteError("Cobalt manager Process request", e);

                throw;
            }
        }