Cleanup & Refactoring

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-12-07 17:42:52 -08:00
parent c15e4d5ee8
commit 317fa8058e
13 changed files with 28 additions and 63 deletions

View File

@@ -314,12 +314,7 @@ namespace Lucene.Services {
try {
var hits = searcher.Search(query, 1);
Logger.Information("Search results: {0}", hits.scoreDocs.Length);
if ( hits.scoreDocs.Length > 0 ) {
return new LuceneSearchHit(searcher.Doc(hits.scoreDocs[0].doc), hits.scoreDocs[0].score);
}
else {
return null;
}
return hits.scoreDocs.Length > 0 ? new LuceneSearchHit(searcher.Doc(hits.scoreDocs[0].doc), hits.scoreDocs[0].score) : null;
}
finally {
searcher.Close();

View File

@@ -37,9 +37,8 @@ namespace Orchard.ArchiveLater.Drivers {
}
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) {
var model = new ArchiveLaterViewModel(part);
var model = new ArchiveLaterViewModel(part) {ScheduledArchiveUtc = part.ScheduledArchiveUtc.Value};
model.ScheduledArchiveUtc = part.ScheduledArchiveUtc.Value;
model.ArchiveLater = model.ScheduledArchiveUtc.HasValue;
model.ScheduledArchiveDate = model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture) : String.Empty;
model.ScheduledArchiveTime = model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture) : String.Empty;
@@ -54,7 +53,7 @@ namespace Orchard.ArchiveLater.Drivers {
if (updater.TryUpdateModel(model, Prefix, null, null) ) {
if ( model.ArchiveLater ) {
DateTime scheduled;
string parseDateTime = String.Concat(model.ScheduledArchiveDate, " ", model.ScheduledArchiveTime);
var parseDateTime = String.Concat(model.ScheduledArchiveDate, " ", model.ScheduledArchiveTime);
// use an english culture as it is the one used by jQuery.datepicker by default
if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled)) {

View File

@@ -107,7 +107,7 @@ namespace Orchard.Blogs.Commands {
foreach ( var item in doc.Descendants("item") ) {
if (item != null) {
string postName = item.Element("title").Value;
var postName = item.Element("title").Value;
Context.Output.WriteLine("Adding post: {0}...", postName.Substring(0, Math.Min(postName.Length, 40)));
var post = _contentManager.New("BlogPost");

View File

@@ -143,10 +143,9 @@ namespace Orchard.Localization.Controllers {
}
var metadata = _contentManager.GetItemMetadata(model.Content);
if (metadata.EditorRouteValues == null)
return null; //todo: (heskew) redirect to somewhere better than nowhere
return RedirectToRoute(metadata.EditorRouteValues);
//todo: (heskew) if null, redirect to somewhere better than nowhere
return metadata.EditorRouteValues == null ? null : RedirectToRoute(metadata.EditorRouteValues);
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {

View File

@@ -43,12 +43,7 @@ namespace Orchard.Packaging.Services {
}
public virtual FrameworkName TargetFramework {
get {
if (_targetFramework == null) {
_targetFramework = new FrameworkName(NetFrameworkIdentifier, typeof(string).Assembly.GetNameSafe().Version);
}
return _targetFramework;
}
get { return _targetFramework ?? (_targetFramework = new FrameworkName(NetFrameworkIdentifier, typeof (string).Assembly.GetNameSafe().Version)); }
}
public string GetFullPath(string path) {
@@ -114,11 +109,7 @@ namespace Orchard.Packaging.Services {
}
// Return empty string for the root namespace of this project.
if (propertyName.Equals("RootNamespace", StringComparison.OrdinalIgnoreCase)) {
return String.Empty;
}
return null;
return propertyName.Equals("RootNamespace", StringComparison.OrdinalIgnoreCase) ? String.Empty : null;
}
public IEnumerable<string> GetFiles(string path) {
@@ -164,10 +155,7 @@ namespace Orchard.Packaging.Services {
}
public DateTimeOffset GetLastModified(string path) {
if (DirectoryExists(path)) {
return new DirectoryInfo(GetFullPath(path)).LastWriteTimeUtc;
}
return new FileInfo(GetFullPath(path)).LastWriteTimeUtc;
return DirectoryExists(path) ? new DirectoryInfo(GetFullPath(path)).LastWriteTimeUtc : new FileInfo(GetFullPath(path)).LastWriteTimeUtc;
}
public bool FileExists(string path) {

View File

@@ -153,9 +153,7 @@ namespace Orchard.Roles.Services {
IEnumerable<string> GetPermissionsForRoleByNameInner(string name) {
var roleRecord = GetRoleByName(name);
if (roleRecord == null)
return Enumerable.Empty<string>();
return GetPermissionsForRole(roleRecord.Id);
return roleRecord == null ? Enumerable.Empty<string>() : GetPermissionsForRole(roleRecord.Id);
}

View File

@@ -33,10 +33,7 @@ namespace Orchard.Scripting.Compiler {
public string StringValue { get { return (string)Value; } }
public override string ToString() {
if (IsNull)
return "<null>";
return Value.ToString();
return IsNull ? "<null>" : Value.ToString();
}
}

View File

@@ -92,7 +92,7 @@ namespace Orchard.Scripting.Compiler {
return Error(node.Message);
}
private EvaluationResult EvaluateEquality(EvaluationResult left, EvaluationResult right, Func<bool, bool> operation) {
private static EvaluationResult EvaluateEquality(EvaluationResult left, EvaluationResult right, Func<bool, bool> operation) {
var type = PrimitiveType.InstanceFor(left.Value);
var result = type.EqualityOperator(left, right);
if (result.IsBool)
@@ -100,7 +100,7 @@ namespace Orchard.Scripting.Compiler {
return result;
}
private EvaluationResult EvaluateComparison(EvaluationResult left, EvaluationResult right, Func<int, bool> operation) {
private static EvaluationResult EvaluateComparison(EvaluationResult left, EvaluationResult right, Func<int, bool> operation) {
var type = PrimitiveType.InstanceFor(left.Value);
var result = type.ComparisonOperator(left, right);
if (result.IsInt32)

View File

@@ -7,10 +7,7 @@ namespace Orchard.Scripting.Compiler {
public object Value { get; set; }
public override string ToString() {
if (Value == null)
return String.Format("Token {0} at position {1}", Kind, Position);
else
return String.Format("Token {0} ({1}) at position {2}", Kind, Value, Position);
return Value == null ? String.Format("Token {0} at position {1}", Kind, Position) : String.Format("Token {0} ({1}) at position {2}", Kind, Value, Position);
}
}
}

View File

@@ -199,15 +199,17 @@ namespace Orchard.Scripting.Compiler {
if (Eof())
return CreateToken(TokenKind.Invalid, "Unterminated string literal");
if (Character() == '\\') {
_stringBuilder.Append('\\');
}
else if (Character() == '\'') {
_stringBuilder.Append('\'');
}
else {
_stringBuilder.Append('\\');
_stringBuilder.Append(Character());
switch (Character()) {
case '\\':
_stringBuilder.Append('\\');
break;
case '\'':
_stringBuilder.Append('\'');
break;
default:
_stringBuilder.Append('\\');
_stringBuilder.Append(Character());
break;
}
}
// Regular character in string

View File

@@ -10,10 +10,7 @@ namespace Orchard.Themes.Preview {
public ThemeSelectorResult GetTheme(RequestContext context) {
var previewThemeName = _previewTheme.GetPreviewTheme();
if (string.IsNullOrEmpty(previewThemeName))
return null;
return new ThemeSelectorResult { Priority = 90, ThemeName = previewThemeName };
return string.IsNullOrEmpty(previewThemeName) ? null : new ThemeSelectorResult { Priority = 90, ThemeName = previewThemeName };
}
}
}

View File

@@ -16,11 +16,7 @@ namespace Orchard.Themes.Services {
public ThemeSelectorResult GetTheme(RequestContext context) {
string currentThemeName = _orchardServices.WorkContext.CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName;
if (String.IsNullOrEmpty(currentThemeName)) {
return null;
}
return new ThemeSelectorResult { Priority = -5, ThemeName = currentThemeName };
return String.IsNullOrEmpty(currentThemeName) ? null : new ThemeSelectorResult { Priority = -5, ThemeName = currentThemeName };
}
}

View File

@@ -28,10 +28,7 @@ namespace Orchard.Themes.Services {
var site = _workContextAccessor.GetContext().CurrentSite;
string currentThemeName = site.As<ThemeSiteSettingsPart>().CurrentThemeName;
if (string.IsNullOrEmpty(currentThemeName)) {
return null;
}
return _extensionManager.GetExtension(currentThemeName);
return string.IsNullOrEmpty(currentThemeName) ? null : _extensionManager.GetExtension(currentThemeName);
}
public void SetSiteTheme(string themeName) {