Files
Orchard/src/Orchard.Web/Modules/Orchard.Media/Services/XmlRpcHandler.cs
Nathan Heskew bb3e63b9d9 Updating XmlRpc functionality to clear up the confusion with Live Writer (WLW) and categories (since there is not category support)
- updated IXmlRpcHandler to also have a vvoid SetCapabilities(XElement element) so handlers can specify what capabilities they support
- updated the WLW manifest to have a thiner capability set (e.g. no category support) so handlers can light up what they support
- updated the XmlRpcHandlers to add what capabilities they support. there'a room for imporoving (adding/removing) specified capabilities here so the WLW only shows features for what's supported
- added WLW support for tags so a tags input can be used in place of the categories input in the WLW UI

--HG--
branch : dev
2010-11-17 15:36:57 -08:00

70 lines
2.9 KiB
C#

using System;
using System.IO;
using System.Web;
using System.Xml.Linq;
using JetBrains.Annotations;
using Orchard.Core.XmlRpc;
using Orchard.Core.XmlRpc.Models;
using Orchard.Security;
using Orchard.Utility.Extensions;
namespace Orchard.Media.Services {
[UsedImplicitly]
public class XmlRpcHandler : IXmlRpcHandler {
private readonly IMembershipService _membershipService;
private readonly IAuthorizationService _authorizationService;
public XmlRpcHandler(IMembershipService membershipService, IAuthorizationService authorizationService) {
_membershipService = membershipService;
_authorizationService = authorizationService;
}
public void SetCapabilities(XElement options) {
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
options.SetElementValue(XName.Get("supportsFileUpload", manifestUri), "Yes");
}
public void Process(XmlRpcContext context) {
var uriBuilder = new UriBuilder(context.HttpContext.Request.ToUrlString()) {
Path = context.HttpContext.Request.ApplicationPath,
Query = string.Empty
};
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),
(XRpcStruct)context.Request.Params[3].Value);
context.Response = new XRpcMethodResponse().Add(result);
}
}
private XRpcStruct MetaWeblogNewMediaObject(
UriBuilder uriBuilder,
string blogId,
string userName,
string password,
XRpcStruct file) {
var user = _membershipService.ValidateUser(userName, password);
if (!_authorizationService.TryCheckAccess(Permissions.UploadMediaFiles, user, null)) {
//TEMP: return appropriate access-denied response for user
throw new ApplicationException("Access denied");
}
var name = file.Optional<string>("name");
var bits = file.Optional<byte[]>("bits");
var target = HttpContext.Current.Server.MapPath("~/Media/" + name);
Directory.CreateDirectory(Path.GetDirectoryName(target));
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
stream.Write(bits, 0, bits.Length);
}
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Media/" + name.TrimStart('/');
return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
}
}
}