Ejemplo n.º 1
0
        protected override void Handle(IHttpContext context, TFSSourceControlProvider sourceControlProvider)
        {
            IHttpRequest  request  = context.Request;
            IHttpResponse response = context.Response;

            try
            {
                string path    = GetPath(request);
                bool   created = Put(sourceControlProvider, path, request.InputStream, request.Headers["X-SVN-Base-Fulltext-MD5"], request.Headers["X-SVN-Result-Fulltext-MD5"]);

                if (created)
                {
                    SetResponseSettings(response, "text/html", Encoding.UTF8, 201);

                    response.AppendHeader("Location", "http://" + request.Headers["Host"] + "/" + Helper.Decode(path));

                    string responseContent = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" +
                                             "<html><head>\n" +
                                             "<title>201 Created</title>\n" +
                                             "</head><body>\n" +
                                             "<h1>Created</h1>\n" +
                                             "<p>Resource /" + Helper.EncodeB(Helper.Decode(path)) +
                                             " has been created.</p>\n" +
                                             "<hr />\n" +
                                             "<address>Apache at" + request.Url.Host +
                                             " Port " + request.Url.Port + "</address>\n" +
                                             "</body></html>\n";

                    WriteToResponse(response, responseContent);
                }
                else
                {
                    SetResponseSettings(response, "text/plain", Encoding.UTF8, 204);
                }
            }
            catch (ConflictException ex)
            {
                RequestCache.Items["RequestBody"] = null;
                DefaultLogger logger = Container.Resolve <DefaultLogger>();
                logger.ErrorFullDetails(ex, context);

                SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 409);
                string responseContent =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<D:error xmlns:D=\"DAV:\" xmlns:m=\"http://apache.org/dav/xmlns\" xmlns:C=\"svn:\">\n" +
                    "<C:error/>\n" +
                    "<m:human-readable errcode=\"160024\">\n" +
                    "The version resource does not correspond to the resource within the transaction.  Either the requested version resource is out of date (needs to be updated), or the requested version resource is newer than the transaction root (restart the commit).\n" +
                    "</m:human-readable>\n" +
                    "</D:error>\n";
                WriteToResponse(response, responseContent);
            }
        }
        protected override void Handle(IHttpContext context, TFSSourceControlProvider sourceControlProvider)
        {
            IHttpRequest  request  = context.Request;
            IHttpResponse response = context.Response;
            CheckoutData  data     = Helper.DeserializeXml <CheckoutData>(request.InputStream);

            try
            {
                string path     = GetPath(request);
                string location = CheckOut(sourceControlProvider, data, path);
                SetResponseSettings(response, "text/html", Encoding.UTF8, 201);
                response.AppendHeader("Cache-Control", "no-cache");
                string locationUrl = "http://" + request.Headers["Host"] + Helper.EncodeC(location);
                response.AppendHeader("Location", Helper.UrlEncodeIfNeccesary(locationUrl));
                string responseContent =
                    "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" +
                    "<html><head>\n" +
                    "<title>201 Created</title>\n" +
                    "</head><body>\n" +
                    "<h1>Created</h1>\n" +
                    "<p>Checked-out resource " + Helper.Encode(location, true) + " has been created.</p>\n" +
                    "<hr />\n" +
                    "<address>Apache at " + request.Url.Host + " Port " +
                    request.Url.Port + "</address>\n" +
                    "</body></html>\n";
                WriteToResponse(response, responseContent);
            }
            catch (ConflictException ex)
            {
                RequestCache.Items["RequestBody"] = data;
                DefaultLogger logger = Container.Resolve <DefaultLogger>();
                logger.ErrorFullDetails(ex, context);

                SetResponseSettings(response, "text/xml; charset=\"utf-8\"", Encoding.UTF8, 409);
                string responseContent =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<D:error xmlns:D=\"DAV:\" xmlns:m=\"http://apache.org/dav/xmlns\" xmlns:C=\"svn:\">\n" +
                    "<C:error/>\n" +
                    "<m:human-readable errcode=\"160024\">\n" +
                    "The version resource does not correspond to the resource within the transaction.  Either the requested version resource is out of date (needs to be updated), or the requested version resource is newer than the transaction root (restart the commit).\n" +
                    "</m:human-readable>\n" +
                    "</D:error>\n";
                WriteToResponse(response, responseContent);
            }
            catch
            {
                RequestCache.Items["RequestBody"] = data;
                throw;
            }
        }