Refactoring

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-12-07 16:11:29 -08:00
parent eab448cb21
commit 2b7b92c439
10 changed files with 23 additions and 32 deletions

View File

@@ -1,33 +1,25 @@
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Orchard.FileSystems.VirtualPath;
using Orchard.Services;
namespace Orchard.Core.Common.Services {
public class BbcodeFilter : IHtmlFilter {
private readonly IVirtualPathProvider _virtualPathProvider;
public BbcodeFilter(IVirtualPathProvider virtualPathProvider) {
_virtualPathProvider = virtualPathProvider;
}
public string ProcessContent(string text) {
return BbcodeReplace(text);
}
// Can be moved somewhere else once we have IoC enabled body text filters.
private string BbcodeReplace(string text) {
private static string BbcodeReplace(string text) {
if (string.IsNullOrEmpty(text))
return string.Empty;
Regex urlRegex = new Regex(@"\[url\]([^\]]+)\[\/url\]");
Regex urlRegexWithLink = new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]");
Regex imgRegex = new Regex(@"\[img\]([^\]]+)\[\/img\]");
var urlRegex = new Regex(@"\[url\]([^\]]+)\[\/url\]");
var urlRegexWithLink = new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]");
var imgRegex = new Regex(@"\[img\]([^\]]+)\[\/img\]");
text = urlRegex.Replace(text, "<a href=\"$1\">$1</a>");
text = urlRegexWithLink.Replace(text, "<a href=\"$1\">$2</a>");
//text = imgRegex.Replace(text, "<img src=\"$1\" />");
var matches = imgRegex.Matches(text).OfType<Match>().OrderByDescending(m => m.Groups[0].Index);
foreach(var match in matches) {

View File

@@ -218,7 +218,8 @@ namespace Orchard.Core.Settings.Metadata {
return null;
}
}
string Compose(XElement map) {
static string Compose(XElement map) {
if (map == null)
return null;

View File

@@ -26,7 +26,7 @@ namespace Orchard.Core.XmlRpc.Services {
};
}
private IDictionary<Type, Func<XRpcData, XElement>> _dispatch;
private readonly IDictionary<Type, Func<XRpcData, XElement>> _dispatch;
XElement IMapper<XRpcMethodResponse, XElement>.Map(XRpcMethodResponse source) {
return new XElement(

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Orchard.Media.Extensions {
public static class LongExtensions {
private static List<string> units = new List<string>(5) {"B", "KB", "MB", "GB", "TB"}; // Not going further. Anything beyond MB is probably overkill anyway.
private static readonly List<string> units = new List<string>(5) {"B", "KB", "MB", "GB", "TB"}; // Not going further. Anything beyond MB is probably overkill anyway.
public static string ToFriendlySizeString(this long bytes) {
var somethingMoreFriendly = TryForTheNextUnit(bytes, units[0]);

View File

@@ -38,14 +38,12 @@ namespace Orchard.Packaging.Services {
}
public override IQueryable<IPackage> GetPackages() {
IEnumerable<IPackage> packages;
packages = from extension in _extensionManager.AvailableExtensions()
let id = "Orchard." + extension.ExtensionType + "." + extension.Id
let version = Version.Parse(extension.Version)
let package = SourceRepository.FindPackage(id, version)
where package != null
select package;
IEnumerable<IPackage> packages = from extension in _extensionManager.AvailableExtensions()
let id = "Orchard." + extension.ExtensionType + "." + extension.Id
let version = Version.Parse(extension.Version)
let package = SourceRepository.FindPackage(id, version)
where package != null
select package;
return packages.AsQueryable();
}

View File

@@ -62,7 +62,7 @@ namespace Orchard.Packaging.Services {
return context.Stream;
}
private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
private static void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
context.Builder.Id = "Orchard." + extensionDescriptor.ExtensionType + "." + extensionDescriptor.Id;
context.Builder.Version = new Version(extensionDescriptor.Version);
context.Builder.Title = extensionDescriptor.Name ?? extensionDescriptor.Id;
@@ -74,7 +74,7 @@ namespace Orchard.Packaging.Services {
}
}
private void EmbedProjectFiles(CreateContext context, params string[] itemGroupTypes) {
private static void EmbedProjectFiles(CreateContext context, params string[] itemGroupTypes) {
IEnumerable<XElement> itemGroups = context.Project
.Elements(Ns("Project"))
.Elements(Ns("ItemGroup"));
@@ -90,7 +90,7 @@ namespace Orchard.Packaging.Services {
}
}
private void EmbedReferenceFiles(CreateContext context) {
private static void EmbedReferenceFiles(CreateContext context) {
var entries = context.Project
.Elements(Ns("Project"))
.Elements(Ns("ItemGroup"))
@@ -113,7 +113,7 @@ namespace Orchard.Packaging.Services {
}
}
private void EmbedThemeFiles(CreateContext context) {
private static void EmbedThemeFiles(CreateContext context) {
var basePath = context.SourcePath;
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
// ignore dlls, etc
@@ -128,7 +128,7 @@ namespace Orchard.Packaging.Services {
}
}
private XName Ns(string localName) {
private static XName Ns(string localName) {
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
}

View File

@@ -144,7 +144,7 @@ namespace Orchard.Packaging.Services {
}
}
private bool TryGetSolutionPath(string applicationPath, out string parentPath) {
private static bool TryGetSolutionPath(string applicationPath, out string parentPath) {
try {
parentPath = Directory.GetParent(applicationPath).Parent.FullName;
var solutionPath = Path.Combine(parentPath, SolutionFilename);

View File

@@ -136,7 +136,7 @@ namespace Orchard.Widgets.Services {
return false;
}
private int ParsePosition(WidgetPart widgetPart) {
private static int ParsePosition(WidgetPart widgetPart) {
int value;
if (!int.TryParse(widgetPart.Record.Position, out value))
return 0;

View File

@@ -12,7 +12,7 @@ namespace Orchard.Mvc.ViewEngines.Razor {
Logger = NullLogger.Instance;
RazorCompilationEventsShim.EnsureInitialized();
}
static string[] DisabledFormats = new[] { "~/Disabled" };
static readonly string[] DisabledFormats = new[] { "~/Disabled" };
public ILogger Logger { get; set; }

View File

@@ -11,7 +11,7 @@ namespace Orchard.Mvc.ViewEngines.WebForms {
Logger = NullLogger.Instance;
}
static string[] DisabledFormats = new[] { "~/Disabled" };
static readonly string[] DisabledFormats = new[] { "~/Disabled" };
public ILogger Logger { get; set; }