mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
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:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using System.Web.Hosting;
|
||||||
using Orchard.CmsPages.ViewModels;
|
using Orchard.CmsPages.ViewModels;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.XmlRpc;
|
using Orchard.XmlRpc;
|
||||||
@@ -20,12 +21,16 @@ namespace Orchard.CmsPages.Services {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public void Process(XmlRpcContext context) {
|
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") {
|
if (context.Request.MethodName == "blogger.getUsersBlogs") {
|
||||||
context.Response = new XRpcMethodResponse()
|
context.Response = new XRpcMethodResponse()
|
||||||
.Add(new XRpcArray()
|
.Add(new XRpcArray()
|
||||||
.Add(new XRpcStruct()
|
.Add(new XRpcStruct()
|
||||||
.Set("url", "http://localhost:40245/")
|
.Set("url", uriBuilder.Uri.AbsoluteUri)
|
||||||
.Set("blogid", "Orchard.CmsPages")
|
.Set("blogid", "Orchard.CmsPages")
|
||||||
.Set("blogName", "Orchard Pages")));
|
.Set("blogName", "Orchard Pages")));
|
||||||
}
|
}
|
||||||
@@ -61,6 +66,7 @@ namespace Orchard.CmsPages.Services {
|
|||||||
|
|
||||||
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
||||||
var result = MetaWeblogNewMediaObject(
|
var result = MetaWeblogNewMediaObject(
|
||||||
|
uriBuilder,
|
||||||
Convert.ToString(context.Request.Params[0].Value),
|
Convert.ToString(context.Request.Params[0].Value),
|
||||||
Convert.ToString(context.Request.Params[1].Value),
|
Convert.ToString(context.Request.Params[1].Value),
|
||||||
Convert.ToString(context.Request.Params[2].Value),
|
Convert.ToString(context.Request.Params[2].Value),
|
||||||
@@ -140,6 +146,7 @@ namespace Orchard.CmsPages.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private XRpcStruct MetaWeblogNewMediaObject(
|
private XRpcStruct MetaWeblogNewMediaObject(
|
||||||
|
UriBuilder uriBuilder,
|
||||||
string blogId,
|
string blogId,
|
||||||
string user,
|
string user,
|
||||||
string password,
|
string password,
|
||||||
@@ -147,13 +154,14 @@ namespace Orchard.CmsPages.Services {
|
|||||||
var name = file.Optional<string>("name");
|
var name = file.Optional<string>("name");
|
||||||
var bits = file.Optional<byte[]>("bits");
|
var bits = file.Optional<byte[]>("bits");
|
||||||
|
|
||||||
var target = HttpContext.Current.Server.MapPath("~/Files/"+name);
|
var target = HttpContext.Current.Server.MapPath("~/Files/" + name);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||||
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
|
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
|
||||||
stream.Write(bits, 0, bits.Length);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Orchard.XmlRpc.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
|
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
|
||||||
var context = new XmlRpcContext { Request = request };
|
var context = new XmlRpcContext { HttpContext = HttpContext, Request = request };
|
||||||
foreach (var handler in _xmlRpcHandlers)
|
foreach (var handler in _xmlRpcHandlers)
|
||||||
handler.Process(context);
|
handler.Process(context);
|
||||||
return context.Response;
|
return context.Response;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using System.Web;
|
||||||
using Orchard.XmlRpc.Models;
|
using Orchard.XmlRpc.Models;
|
||||||
|
|
||||||
namespace Orchard.XmlRpc {
|
namespace Orchard.XmlRpc {
|
||||||
public class XmlRpcContext {
|
public class XmlRpcContext {
|
||||||
|
public HttpContextBase HttpContext { get; set; }
|
||||||
public XRpcMethodCall Request { get; set; }
|
public XRpcMethodCall Request { get; set; }
|
||||||
public XRpcMethodResponse Response { get; set; }
|
public XRpcMethodResponse Response { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user