Refactoring

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-12-07 16:47:30 -08:00
parent 2b7b92c439
commit f6cfeb3d66
15 changed files with 42 additions and 46 deletions

View File

@@ -13,7 +13,6 @@ namespace Orchard.Core.Common.Drivers {
private readonly IAuthenticationService _authenticationService;
private readonly IAuthorizationService _authorizationService;
private readonly IMembershipService _membershipService;
private readonly IClock _clock;
public CommonPartDriver(
IOrchardServices services,
@@ -26,7 +25,6 @@ namespace Orchard.Core.Common.Drivers {
_authenticationService = authenticationService;
_authorizationService = authorizationService;
_membershipService = membershipService;
_clock = clock;
T = NullLocalizer.Instance;
Services = services;
}

View File

@@ -16,13 +16,11 @@ namespace Orchard.Core.Settings.Drivers {
private readonly ISiteService _siteService;
private readonly ICultureManager _cultureManager;
private readonly IMembershipService _membershipService;
private readonly INotifier _notifier;
public SiteSettingsPartDriver(ISiteService siteService, ICultureManager cultureManager, IMembershipService membershipService, INotifier notifier) {
_siteService = siteService;
_cultureManager = cultureManager;
_membershipService = membershipService;
_notifier = notifier;
T = NullLocalizer.Instance;
}

View File

@@ -49,7 +49,7 @@ namespace Lucene.Services {
}
public ISearchBuilder Parse(string defaultField, string query) {
return Parse(new string[] {defaultField}, query);
return Parse(new[] {defaultField}, query);
}
public ISearchBuilder Parse(string[] defaultFields, string query) {

View File

@@ -106,18 +106,20 @@ namespace Orchard.Blogs.Commands {
}
foreach ( var item in doc.Descendants("item") ) {
string postName = item.Element("title").Value;
if (item != null) {
string postName = item.Element("title").Value;
Context.Output.WriteLine("Adding post: {0}...", postName.Substring(0, Math.Min(postName.Length, 40)));
var post = _contentManager.New("BlogPost");
post.As<ICommonPart>().Owner = owner;
post.As<ICommonPart>().Container = blog;
var slug = Slugify(postName);
post.As<RoutePart>().Slug = slug;
post.As<RoutePart>().Path = post.As<RoutePart>().GetPathWithSlug(slug);
post.As<RoutePart>().Title = postName;
post.As<BodyPart>().Text = item.Element("description").Value;
_contentManager.Create(post);
Context.Output.WriteLine("Adding post: {0}...", postName.Substring(0, Math.Min(postName.Length, 40)));
var post = _contentManager.New("BlogPost");
post.As<ICommonPart>().Owner = owner;
post.As<ICommonPart>().Container = blog;
var slug = Slugify(postName);
post.As<RoutePart>().Slug = slug;
post.As<RoutePart>().Path = post.As<RoutePart>().GetPathWithSlug(slug);
post.As<RoutePart>().Title = postName;
post.As<BodyPart>().Text = item.Element("description").Value;
_contentManager.Create(post);
}
}

View File

@@ -170,7 +170,7 @@ namespace Orchard.ContentTypes.Controllers {
}
if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); ;
Services.TransactionManager.Cancel();
return AddPartsTo(id);
}

View File

@@ -17,7 +17,7 @@ namespace Orchard.Indexing.Settings {
}
private string _contentTypeName;
private bool _tasksCreated = false;
private bool _tasksCreated;
public override IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition) {
var model = definition.Settings.GetModel<TypeIndexing>();

View File

@@ -45,7 +45,7 @@ namespace Orchard.Packaging.Services {
public virtual FrameworkName TargetFramework {
get {
if (_targetFramework == null) {
_targetFramework = new FrameworkName(NetFrameworkIdentifier, typeof(string).Assembly.GetNameSafe().Version);;
_targetFramework = new FrameworkName(NetFrameworkIdentifier, typeof(string).Assembly.GetNameSafe().Version);
}
return _targetFramework;
}

View File

@@ -11,7 +11,6 @@ using System.Globalization;
namespace Orchard.PublishLater.Drivers {
public class PublishLaterPartDriver : ContentPartDriver<PublishLaterPart> {
private const string TemplateName = "Parts/PublishLater";
private readonly ICommonService _commonService;
private readonly IPublishLaterService _publishLaterService;
private const string DatePattern = "M/d/yyyy";
private const string TimePattern = "h:mm tt";
@@ -20,7 +19,6 @@ namespace Orchard.PublishLater.Drivers {
IOrchardServices services,
ICommonService commonService,
IPublishLaterService publishLaterService) {
_commonService = commonService;
_publishLaterService = publishLaterService;
T = NullLocalizer.Instance;
Services = services;

View File

@@ -93,7 +93,8 @@ namespace Orchard.Tags.Services {
var taggedContentItems = GetTaggedContentItems(tagRecord.Id);
foreach (var tagContentItem in tagsContentItems) {
if (!taggedContentItems.Any(c => c.ContentItem.Id == tagContentItem.TagsPartRecord.Id)) {
ContentTagRecord item = tagContentItem;
if (!taggedContentItems.Any(c => c.ContentItem.Id == item.TagsPartRecord.Id)) {
TagContentItem(tagContentItem.TagsPartRecord, tagName);
}
_contentTagRepository.Delete(tagContentItem);

View File

@@ -5,7 +5,6 @@ using Orchard.Users.Services;
namespace Orchard.Users.Commands {
public class UserCommands : DefaultOrchardCommandHandler {
private readonly IContentManager _contentManager;
private readonly IMembershipService _membershipService;
private readonly IUserService _userService;
@@ -13,7 +12,6 @@ namespace Orchard.Users.Commands {
IContentManager contentManager,
IMembershipService membershipService,
IUserService userService) {
_contentManager = contentManager;
_membershipService = membershipService;
_userService = userService;
}

View File

@@ -20,13 +20,11 @@ namespace Orchard.Users.Services {
private readonly IOrchardServices _orchardServices;
private readonly IMessageManager _messageManager;
private readonly IEnumerable<IUserEventHandler> _userEventHandlers;
private readonly IClock _clock;
public MembershipService(IOrchardServices orchardServices, IMessageManager messageManager, IEnumerable<IUserEventHandler> userEventHandlers, IClock clock) {
_orchardServices = orchardServices;
_messageManager = messageManager;
_userEventHandlers = userEventHandlers;
_clock = clock;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}

View File

@@ -23,7 +23,6 @@ namespace Orchard.Users.Services {
private readonly IMembershipService _membershipService;
private readonly IClock _clock;
private readonly IMessageManager _messageManager;
private readonly ShellSettings _shellSettings;
private readonly IEncryptionService _encryptionService;
public UserService(IContentManager contentManager, IMembershipService membershipService, IClock clock, IMessageManager messageManager, ShellSettings shellSettings, IEncryptionService encryptionService) {
@@ -31,7 +30,6 @@ namespace Orchard.Users.Services {
_membershipService = membershipService;
_clock = clock;
_messageManager = messageManager;
_shellSettings = shellSettings;
_encryptionService = encryptionService;
Logger = NullLogger.Instance;
}

View File

@@ -49,12 +49,14 @@ namespace Orchard.Environment.Descriptor {
public ShellDescriptor Fetch(string name) {
VerifyCacheFile();
var text = _appDataFolder.ReadFile(DescriptorCacheFileName);
XmlDocument xmlDocument = new XmlDocument();
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(text);
XmlNode rootNode = xmlDocument.DocumentElement;
foreach (XmlNode tenantNode in rootNode.ChildNodes) {
if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) {
return GetShellDecriptorForCacheText(tenantNode.InnerText);
if (rootNode != null) {
foreach (XmlNode tenantNode in rootNode.ChildNodes) {
if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) {
return GetShellDecriptorForCacheText(tenantNode.InnerText);
}
}
}
@@ -67,20 +69,22 @@ namespace Orchard.Environment.Descriptor {
var text = _appDataFolder.ReadFile(DescriptorCacheFileName);
bool tenantCacheUpdated = false;
var saveWriter = new StringWriter();
XmlDocument xmlDocument = new XmlDocument();
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(text);
XmlNode rootNode = xmlDocument.DocumentElement;
foreach (XmlNode tenantNode in rootNode.ChildNodes) {
if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) {
tenantNode.InnerText = GetCacheTextForShellDescriptor(descriptor);
tenantCacheUpdated = true;
break;
if (rootNode != null) {
foreach (XmlNode tenantNode in rootNode.ChildNodes) {
if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) {
tenantNode.InnerText = GetCacheTextForShellDescriptor(descriptor);
tenantCacheUpdated = true;
break;
}
}
if (!tenantCacheUpdated) {
XmlElement newTenant = xmlDocument.CreateElement(name);
newTenant.InnerText = GetCacheTextForShellDescriptor(descriptor);
rootNode.AppendChild(newTenant);
}
}
if (!tenantCacheUpdated) {
XmlElement newTenant = xmlDocument.CreateElement(name);
newTenant.InnerText = GetCacheTextForShellDescriptor(descriptor);
rootNode.AppendChild(newTenant);
}
xmlDocument.Save(saveWriter);
@@ -90,7 +94,7 @@ namespace Orchard.Environment.Descriptor {
#endregion
private static string GetCacheTextForShellDescriptor(ShellDescriptor descriptor) {
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.Append(descriptor.SerialNumber + "|");
foreach (var feature in descriptor.Features) {
sb.Append(feature.Name + ";");
@@ -106,7 +110,7 @@ namespace Orchard.Environment.Descriptor {
private static ShellDescriptor GetShellDecriptorForCacheText(string p) {
string[] fields = p.Trim().Split(new[] { "|" }, StringSplitOptions.None);
ShellDescriptor shellDescriptor = new ShellDescriptor {SerialNumber = Convert.ToInt32(fields[0])};
var shellDescriptor = new ShellDescriptor {SerialNumber = Convert.ToInt32(fields[0])};
string[] features = fields[1].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
shellDescriptor.Features = features.Select(feature => new ShellFeature { Name = feature }).ToList();
string[] parameters = fields[2].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -10,7 +10,7 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
}
public class ConfiguredEnginesCache : IConfiguredEnginesCache {
IViewEngine _bare = null;
IViewEngine _bare;
readonly ConcurrentDictionary<string, IViewEngine> _shallow = new ConcurrentDictionary<string, IViewEngine>();
readonly ConcurrentDictionary<string, IViewEngine> _deep = new ConcurrentDictionary<string, IViewEngine>();

View File

@@ -4,6 +4,7 @@ using System.Reflection;
using Orchard.Validation;
namespace Orchard.Utility {
/// <summary>
/// Allows static reflection on members (methods, fields, properties).
/// This code has been adapted from the following blog post:
/// http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!694.entry