--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-11-23 14:10:49 -08:00
15 changed files with 117 additions and 27 deletions

View File

@@ -44,6 +44,18 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
_azureBlobStorageProvider.DeleteFile("notexisting");
}
[Test]
public void RootFolderAreNotCropped() {
_azureBlobStorageProvider.CreateFolder("default");
_azureBlobStorageProvider.CreateFolder("foo");
var folders = _azureBlobStorageProvider.ListFolders("");
Assert.That(folders.Count(), Is.EqualTo(2));
Assert.That(folders.Any(f => f.GetName() == "default"), Is.True);
Assert.That(folders.Any(f => f.GetName() == "foo"), Is.True);
}
[Test]
public void CreateFileShouldReturnCorrectStorageFile() {
var storageFile = _azureBlobStorageProvider.CreateFile("foo.txt");
@@ -105,6 +117,17 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders(null).First().GetPath());
}
[Test]
public void CreateFolderWithSubFolder() {
_azureBlobStorageProvider.CreateFolder("folder");
Assert.AreEqual(0, _azureBlobStorageProvider.ListFolders("folder").Count());
_azureBlobStorageProvider.CreateFolder("folder/folder");
Assert.AreEqual(1, _azureBlobStorageProvider.ListFolders("folder").Count());
Assert.AreEqual(0, _azureBlobStorageProvider.ListFiles("folder/folder").Count());
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders("folder").First().GetName());
}
[Test]
public void DeleteFolderShouldDeleteFilesAlso() {
_azureBlobStorageProvider.CreateFile("folder/foo1.txt");

View File

@@ -51,10 +51,42 @@ namespace Orchard.Azure {
}
private static void EnsurePathIsRelative(string path) {
if (path.StartsWith("/") || path.StartsWith("http://"))
if ( path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://") )
throw new ArgumentException("Path must be relative");
}
public string Combine(string path1, string path2) {
if ( path1 == null) {
throw new ArgumentNullException("path1");
}
if ( path2 == null ) {
throw new ArgumentNullException("path2");
}
if ( String.IsNullOrEmpty(path2) ) {
return path1;
}
if ( String.IsNullOrEmpty(path1) ) {
return path2;
}
if ( path2.StartsWith("http://") || path2.StartsWith("https://") )
{
return path2;
}
var ch = path1[path1.Length - 1];
if (ch != '/')
{
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
}
return (path1 + path2);
}
public IStorageFile GetFile(string path) {
EnsurePathIsRelative(path);
@@ -75,7 +107,7 @@ namespace Orchard.Azure {
EnsurePathIsRelative(path);
string prefix = String.Concat(Container.Name, "/", _root, path);
string prefix = String.Concat(Combine(Container.Name, _root), path);
if ( !prefix.EndsWith("/") )
prefix += "/";
@@ -121,7 +153,7 @@ namespace Orchard.Azure {
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
// Creating a virtually hidden file to make the directory an existing concept
CreateFile(path + "/" + FolderEntry);
CreateFile(Combine(path, FolderEntry));
}
}
@@ -224,7 +256,7 @@ namespace Orchard.Azure {
}
public string GetPath() {
return _blob.Uri.ToString().Substring(_rootPath.Length+1);
return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/');
}
public string GetName() {
@@ -263,11 +295,12 @@ namespace Orchard.Azure {
}
public string GetName() {
return Path.GetDirectoryName(GetPath() + "/");
var path = GetPath();
return path.Substring(path.LastIndexOf('/') +1 );
}
public string GetPath() {
return _blob.Uri.ToString().Substring(_rootPath.Length + 1).TrimEnd('/');
return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/');
}
public long GetSize() {

View File

@@ -9,12 +9,14 @@ using Orchard.Commands;
using Orchard.Data;
using Orchard.Data.Migration.Generator;
using Orchard.Data.Providers;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Environment.ShellBuilders;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
using Orchard.Localization;
using Orchard.Tests.Environment;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Stubs;
@@ -49,6 +51,7 @@ namespace Orchard.Tests.Modules.CodeGeneration.Commands {
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<SchemaCommandGenerator>().As<ISchemaCommandGenerator>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
_container = builder.Build();
_extensionManager = _container.Resolve<IExtensionManager>();

View File

@@ -32,6 +32,8 @@ using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records;
using Path = Bleroy.FluentPath.Path;
using Orchard.Tests.Stubs;
using Orchard.Tests.Environment;
using Orchard.Environment;
namespace Orchard.Tests.Modules.Migrations {
[TestFixture]
@@ -85,6 +87,7 @@ namespace Orchard.Tests.Modules.Migrations {
builder.RegisterType<SchemaCommandGenerator>().As<ISchemaCommandGenerator>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();

View File

@@ -8,12 +8,14 @@ using Orchard.Data;
using Orchard.Data.Migration.Interpreters;
using Orchard.Data.Migration.Schema;
using Orchard.Data.Providers;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
using Orchard.Reports.Services;
using Orchard.Tests.ContentManagement;
using System.IO;
using Orchard.Tests.Environment;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Stubs;
@@ -47,6 +49,7 @@ namespace Orchard.Tests.DataMigration {
builder.RegisterType<DefaultDataMigrationInterpreter>().As<IDataMigrationInterpreter>();
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST" }).As<ShellSettings>();

View File

@@ -0,0 +1,9 @@
using Orchard.Environment;
namespace Orchard.Tests.Environment {
public class StubHostEnvironment : HostEnvironment {
public override void ResetSiteCompilation() {
}
}
}

View File

@@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using Autofac;
using NUnit.Framework;
using Orchard.Environment;
using Orchard.Logging;
using Orchard.Tests.Environment;
namespace Orchard.Tests.Logging {
[TestFixture]
@@ -13,6 +15,7 @@ namespace Orchard.Tests.Logging {
var builder = new ContainerBuilder();
builder.RegisterModule(new LoggingModule());
builder.RegisterType<Thing>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
var container = builder.Build();
var thing = container.Resolve<Thing>();
Assert.That(thing.Logger, Is.Not.Null);
@@ -46,6 +49,7 @@ namespace Orchard.Tests.Logging {
var builder = new ContainerBuilder();
builder.RegisterModule(new LoggingModule());
builder.RegisterType<Thing>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
var container = builder.Build();
var thing = container.Resolve<Thing>();
Assert.That(thing.Logger, Is.Not.Null);

View File

@@ -226,6 +226,7 @@
<Compile Include="Environment\Extensions\ExtensionLoaderCoordinatorTests.cs" />
<Compile Include="Environment\State\DefaultProcessingEngineTests.cs" />
<Compile Include="Environment\RunningShellTableTests.cs" />
<Compile Include="Environment\StubHostEnvironment.cs" />
<Compile Include="Environment\Utility\Build.cs" />
<Compile Include="FileSystems\AppData\AppDataFolderTests.cs" />
<Compile Include="Environment\Configuration\DefaultTenantManagerTests.cs" />

View File

@@ -52,13 +52,13 @@ namespace Orchard.ContentTypes.Controllers {
ModelState.AddModelError("DisplayName", T("A type with the same name already exists.").ToString());
}
var typeViewModel = _contentDefinitionService.AddType(viewModel);
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel();
return View(viewModel);
}
var typeViewModel = _contentDefinitionService.AddType(viewModel);
Services.Notifier.Information(T("The \"{0}\" content type has been created.", typeViewModel.DisplayName));
return RedirectToAction("Edit", new { id = typeViewModel.Name });

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Orchard.Media.Models;
namespace Orchard.Media.Helpers {
@@ -9,12 +10,12 @@ namespace Orchard.Media.Helpers {
if (String.IsNullOrEmpty(mediaPath)) {
return navigations;
}
if (!mediaPath.Contains("\\")) {
if ( !mediaPath.Contains(Path.DirectorySeparatorChar.ToString()) && !mediaPath.Contains(Path.AltDirectorySeparatorChar.ToString()) ) {
navigations.Add(new FolderNavigation { FolderName = mediaPath, FolderPath = mediaPath });
return navigations;
}
string[] navigationParts = mediaPath.Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
string[] navigationParts = mediaPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries);
string currentPath = String.Empty;
foreach (string navigationPart in navigationParts) {
currentPath = (string.IsNullOrEmpty(currentPath) ? navigationPart : currentPath + "\\" + navigationPart);

View File

@@ -66,7 +66,7 @@ namespace Orchard.Media.Services {
_storageProvider.CreateFolder(name);
return;
}
_storageProvider.CreateFolder(mediaPath + "\\" + name);
_storageProvider.CreateFolder(_storageProvider.Combine(mediaPath, name));
}
public void DeleteFolder(string name) {
@@ -79,12 +79,12 @@ namespace Orchard.Media.Services {
}
public void DeleteFile(string name, string folderName) {
_storageProvider.DeleteFile(folderName + "\\" + name);
_storageProvider.DeleteFile(_storageProvider.Combine(folderName, name));
}
public void RenameFile(string name, string newName, string folderName) {
if (FileAllowed(newName, false)) {
_storageProvider.RenameFile(folderName + "\\" + name, folderName + "\\" + newName);
_storageProvider.RenameFile(_storageProvider.Combine(folderName, name), _storageProvider.Combine(folderName, newName));
}
}
@@ -193,14 +193,14 @@ namespace Orchard.Media.Services {
}
}
private static string RenameFolderPath(string path, string newName) {
var lastIndex = path.LastIndexOf("\\");
private string RenameFolderPath(string path, string newName) {
var lastIndex = Math.Max(path.LastIndexOf(Path.DirectorySeparatorChar), path.LastIndexOf(Path.AltDirectorySeparatorChar));
if (lastIndex == -1) {
return newName;
}
return path.Substring(0, lastIndex) + "\\" + newName;
return _storageProvider.Combine(path.Substring(0, lastIndex), newName);
}
}
}

View File

@@ -8,7 +8,7 @@
<p>@Html.ActionLink(T("Media Folders").ToString(), "Index") &#62;
@foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) {
@Html.ActionLink(navigation.FolderName, "Edit",
new {name = navigation.FolderName, mediaPath = navigation.FolderPath})
new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) <text>&#62;</text>
}
@T("Folder Properties")</p>

View File

@@ -1,9 +1,11 @@
using System.Linq;
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Indexing;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Search.Services;
using Orchard.Search.ViewModels;
using Orchard.Search.Models;
@@ -29,26 +31,29 @@ namespace Orchard.Search.Controllers {
_contentManager = contentManager;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
Shape = shapeFactory;
}
private IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public ILogger Logger { get; set; }
dynamic Shape { get; set; }
public ActionResult Index(Pager pager, string q = "") {
var searchFields = Services.WorkContext.CurrentSite.As<SearchSettingsPart>().SearchedFields;
IPageOfItems<ISearchHit> searchHits;
if (q.Trim().StartsWith("?") || q.Trim().StartsWith("*")) {
searchHits = new PageOfItems<ISearchHit>(new ISearchHit[] { });
Services.Notifier.Error(T("'*' or '?' not allowed as first character in WildcardQuery"));
}
else {
IPageOfItems<ISearchHit> searchHits = new PageOfItems<ISearchHit>(new ISearchHit[] { });
try {
searchHits = _searchService.Query(q, pager.Page, pager.PageSize,
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
searchFields,
searchHit => searchHit);
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
searchFields,
searchHit => searchHit);
}
catch(Exception e) {
Services.Notifier.Error(T("Invalid search query: {0}", q));
Logger.Error(e, "Invalid search query: " + q);
}
var list = Shape.List();

View File

@@ -148,6 +148,10 @@ namespace Orchard.FileSystems.Media {
File.Move(Map(path), Map(newPath));
}
public string Combine(string path1, string path2) {
return Path.Combine(path1, path2);
}
#endregion
private class FileSystemStorageFile : IStorageFile {

View File

@@ -12,5 +12,6 @@ namespace Orchard.FileSystems.Media {
void DeleteFile(string path);
void RenameFile(string path, string newPath);
IStorageFile CreateFile(string path);
string Combine(string path1, string path2);
}
}