Passing the HttpContextBase along with XmlRpcContext to enable handlers to determine http url

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4039508
This commit is contained in:
loudej
2009-11-11 01:36:42 +00:00
parent eb9cfcbda2
commit 0fd277ed42
3 changed files with 14 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using Orchard.CmsPages.ViewModels;
using Orchard.Logging;
using Orchard.XmlRpc;
@@ -20,12 +21,16 @@ namespace Orchard.CmsPages.Services {
public ILogger Logger { get; set; }
public void Process(XmlRpcContext context) {
var uriBuilder = new UriBuilder(context.HttpContext.Request.Url);
uriBuilder.Path = context.HttpContext.Request.ApplicationPath;
uriBuilder.Query = string.Empty;
if (context.Request.MethodName == "blogger.getUsersBlogs") {
context.Response = new XRpcMethodResponse()
.Add(new XRpcArray()
.Add(new XRpcStruct()
.Set("url", "http://localhost:40245/")
.Set("url", uriBuilder.Uri.AbsoluteUri)
.Set("blogid", "Orchard.CmsPages")
.Set("blogName", "Orchard Pages")));
}
@@ -61,6 +66,7 @@ namespace Orchard.CmsPages.Services {
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
var result = MetaWeblogNewMediaObject(
uriBuilder,
Convert.ToString(context.Request.Params[0].Value),
Convert.ToString(context.Request.Params[1].Value),
Convert.ToString(context.Request.Params[2].Value),
@@ -140,6 +146,7 @@ namespace Orchard.CmsPages.Services {
}
private XRpcStruct MetaWeblogNewMediaObject(
UriBuilder uriBuilder,
string blogId,
string user,
string password,
@@ -153,7 +160,8 @@ namespace Orchard.CmsPages.Services {
stream.Write(bits, 0, bits.Length);
}
return new XRpcStruct().Set("url", "http://localhost:40245/Files/" + name);
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Files/" + name.TrimStart('/');
return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
}
}
}

View File

@@ -41,7 +41,7 @@ namespace Orchard.XmlRpc.Controllers {
}
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
var context = new XmlRpcContext { Request = request };
var context = new XmlRpcContext { HttpContext = HttpContext, Request = request };
foreach (var handler in _xmlRpcHandlers)
handler.Process(context);
return context.Response;

View File

@@ -1,7 +1,9 @@
using System.Web;
using Orchard.XmlRpc.Models;
namespace Orchard.XmlRpc {
public class XmlRpcContext {
public HttpContextBase HttpContext { get; set; }
public XRpcMethodCall Request { get; set; }
public XRpcMethodResponse Response { get; set; }
}