Updated mediaService to use IFileSystem

This commit is contained in:
Matt@MBP13-PC
2012-08-20 12:36:56 -01:00
parent 91acf40b3b
commit 298e06974e
3 changed files with 23 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("umbraco")]
[assembly: InternalsVisibleTo("businesslogic")]
[assembly: InternalsVisibleTo("umbraco.editorControls")]
[assembly: InternalsVisibleTo("umbraco.webservices")]
[assembly: InternalsVisibleTo("Umbraco.Tests")]
[assembly: InternalsVisibleTo("Umbraco.Core")]

View File

@@ -6,6 +6,7 @@ using System.Web.Services;
using umbraco.IO;
using umbraco.cms.businesslogic.media;
using umbraco.cms.businesslogic.property;
using Umbraco.Core.IO;
namespace umbraco.webservices.media
{
@@ -14,6 +15,12 @@ namespace umbraco.webservices.media
[ToolboxItem(false)]
public class mediaService : BaseWebService
{
internal IMediaFileSystem _fs;
public mediaService()
{
_fs = FileSystemProviderManager.Current.GetFileSystemProvider<IMediaFileSystem>();
}
override public Services Service
{
@@ -100,12 +107,9 @@ namespace umbraco.webservices.media
{
if (!(p.Value == System.DBNull.Value))
{
string fileName = (string)p.Value;
string filePath = umbraco.IO.IOHelper.MapPath(fileName);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
var path = _fs.GetRelativePath(p.Value.ToString());
if(_fs.FileExists(path))
_fs.DeleteFile(path, true);
}
}
@@ -124,16 +128,17 @@ namespace umbraco.webservices.media
Media m = new Media(id);
var path = _fs.GetRelativePath(m.getProperty("umbracoFile").Id, filename);
System.IO.Directory.CreateDirectory(IOHelper.MapPath(SystemDirectories.Media + "/" + m.getProperty("umbracoFile").Id));
string fullFilePath = IOHelper.MapPath(SystemDirectories.Media + "/" + m.getProperty("umbracoFile").Id + "/" + filename);
var stream = new MemoryStream();
stream.Write(contents, 0, contents.Length);
stream.Seek(0, 0);
File.WriteAllBytes(fullFilePath, contents);
_fs.AddFile(path, stream);
FileInfo f = new FileInfo(fullFilePath);
m.getProperty("umbracoFile").Value = SystemDirectories.Media + "/" + filename;
m.getProperty("umbracoExtension").Value = f.Extension.Replace(".", "");
m.getProperty("umbracoBytes").Value = f.Length.ToString();
m.getProperty("umbracoFile").Value = _fs.GetUrl(path);
m.getProperty("umbracoExtension").Value = Path.GetExtension(filename).Substring(1);
m.getProperty("umbracoBytes").Value = _fs.GetSize(path);
}

View File

@@ -120,6 +120,10 @@
<Project>{CCD75EC3-63DB-4184-B49D-51C1DD337230}</Project>
<Name>umbraco.cms</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
<Project>{31785bc3-256c-4613-b2f5-a1b0bdded8c1}</Project>
<Name>Umbraco.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Web\Umbraco.Web.csproj">
<Project>{651E1350-91B6-44B7-BD60-7207006D7003}</Project>
<Name>umbraco.presentation</Name>