Code styling

This commit is contained in:
Benedek Farkas
2025-09-24 23:50:35 +02:00
parent 26f6dcaf9c
commit 7329240c65
2 changed files with 18 additions and 24 deletions

View File

@@ -4,7 +4,6 @@ using Orchard.Commands;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Indexing.Services; using Orchard.Indexing.Services;
using Orchard.Tasks.Indexing; using Orchard.Tasks.Indexing;
using Orchard.Utility.Extensions;
using static Orchard.Indexing.Helpers.IndexingHelpers; using static Orchard.Indexing.Helpers.IndexingHelpers;
namespace Orchard.Indexing.Commands { namespace Orchard.Indexing.Commands {
@@ -92,19 +91,19 @@ namespace Orchard.Indexing.Commands {
return; return;
} }
if ( !_indexManager.HasIndexProvider() ) { if (!_indexManager.HasIndexProvider()) {
Context.Output.WriteLine(T("No index available")); Context.Output.WriteLine(T("No index available"));
return; return;
} }
var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(index); var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(index);
var results = searchBuilder.Parse( new [] {"body", "title"}, Query).Search(); var results = searchBuilder.Parse(new[] { "body", "title" }, Query).Search();
Context.Output.WriteLine("{0} result{1}\r\n-----------------\r\n", results.Count(), results.Count() > 0 ? "s" : ""); Context.Output.WriteLine("{0} result{1}\r\n-----------------\r\n", results.Count(), results.Count() > 0 ? "s" : "");
Context.Output.WriteLine("┌──────────────────────────────────────────────────────────────┬────────┐"); Context.Output.WriteLine("┌──────────────────────────────────────────────────────────────┬────────┐");
Context.Output.WriteLine("│ {0} │ {1,6} │", "Title" + new string(' ', 60 - "Title".Length), "Score"); Context.Output.WriteLine("│ {0} │ {1,6} │", "Title" + new string(' ', 60 - "Title".Length), "Score");
Context.Output.WriteLine("├──────────────────────────────────────────────────────────────┼────────┤"); Context.Output.WriteLine("├──────────────────────────────────────────────────────────────┼────────┤");
foreach ( var searchHit in results ) { foreach (var searchHit in results) {
var contentItem = _contentManager.Get(searchHit.ContentItemId); var contentItem = _contentManager.Get(searchHit.ContentItemId);
var metadata = _contentManager.GetItemMetadata(contentItem); var metadata = _contentManager.GetItemMetadata(contentItem);
var title = String.IsNullOrWhiteSpace(metadata.DisplayText) ? "- no title -" : metadata.DisplayText; var title = String.IsNullOrWhiteSpace(metadata.DisplayText) ? "- no title -" : metadata.DisplayText;
@@ -127,7 +126,7 @@ namespace Orchard.Indexing.Commands {
return; return;
} }
if ( !_indexManager.HasIndexProvider() ) { if (!_indexManager.HasIndexProvider()) {
Context.Output.WriteLine(T("No index available")); Context.Output.WriteLine(T("No index available"));
return; return;
} }
@@ -136,11 +135,10 @@ namespace Orchard.Indexing.Commands {
} }
[CommandName("index refresh")] [CommandName("index refresh")]
[CommandHelp("index refresh /ContentItem:<content item id> \r\n\t" + "Refreshes the index for the specifed <content item id>")] [CommandHelp("index refresh /ContentItem:<content item id> \r\n\t" + "Refreshes the index for the specified <content item id>")]
[OrchardSwitches("ContentItem")] [OrchardSwitches("ContentItem")]
public void Refresh() { public void Refresh() {
int contentItemId; if (!int.TryParse(ContentItem, out int contentItemId)) {
if ( !int.TryParse(ContentItem, out contentItemId) ) {
Context.Output.WriteLine(T("Invalid content item id. Not an integer.")); Context.Output.WriteLine(T("Invalid content item id. Not an integer."));
return; return;
} }
@@ -148,15 +146,14 @@ namespace Orchard.Indexing.Commands {
var contentItem = _contentManager.Get(contentItemId); var contentItem = _contentManager.Get(contentItemId);
_indexingTaskManager.CreateUpdateIndexTask(contentItem); _indexingTaskManager.CreateUpdateIndexTask(contentItem);
Context.Output.WriteLine(T("Content Item marked for reindexing")); Context.Output.WriteLine(T("Content Item marked for re-indexing"));
} }
[CommandName("index delete")] [CommandName("index delete")]
[CommandHelp("index delete /ContentItem:<content item id>\r\n\t" + "Deletes the specifed <content item id> from the index")] [CommandHelp("index delete /ContentItem:<content item id>\r\n\t" + "Deletes the specified <content item id> from the index")]
[OrchardSwitches("ContentItem")] [OrchardSwitches("ContentItem")]
public void Delete() { public void Delete() {
int contentItemId; if (!int.TryParse(ContentItem, out int contentItemId)) {
if(!int.TryParse(ContentItem, out contentItemId)) {
Context.Output.WriteLine(T("Invalid content item id. Not an integer.")); Context.Output.WriteLine(T("Invalid content item id. Not an integer."));
return; return;
} }

View File

@@ -2,12 +2,11 @@
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Indexing.Services; using Orchard.Indexing.Services;
using Orchard.Indexing.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Security; using Orchard.Security;
using Orchard.Indexing.ViewModels;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
using static Orchard.Indexing.Helpers.IndexingHelpers; using static Orchard.Indexing.Helpers.IndexingHelpers;
namespace Orchard.Indexing.Controllers { namespace Orchard.Indexing.Controllers {
@@ -41,7 +40,7 @@ namespace Orchard.Indexing.Controllers {
try { try {
return _indexingService.GetIndexEntry(x); return _indexingService.GetIndexEntry(x);
} }
catch(Exception e) { catch (Exception e) {
Logger.Error(e, "Index couldn't be read: " + x); Logger.Error(e, "Index couldn't be read: " + x);
return new IndexEntry { return new IndexEntry {
IndexName = x, IndexName = x,
@@ -51,8 +50,6 @@ namespace Orchard.Indexing.Controllers {
}); });
} }
// Services.Notifier.Information(T("The index might be corrupted. If you can't recover click on Rebuild."));
return View(viewModel); return View(viewModel);
} }
@@ -60,7 +57,7 @@ namespace Orchard.Indexing.Controllers {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage the search index."))) if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage the search index.")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
return View("Create", String.Empty); return View("Create");
} }
[HttpPost, ActionName("Create")] [HttpPost, ActionName("Create")]
@@ -83,9 +80,9 @@ namespace Orchard.Indexing.Controllers {
provider.CreateIndex(id); provider.CreateIndex(id);
Services.Notifier.Information(T("Index named {0} created successfully", id)); Services.Notifier.Information(T("Index named {0} created successfully", id));
} }
catch(Exception e) { catch (Exception e) {
Services.Notifier.Error(T("An error occurred while creating the index: {0}", id)); Services.Notifier.Error(T("An error occurred while creating the index: {0}", id));
Logger.Error("An error occurred while creatign the index " + id, e); Logger.Error("An error occurred while creating the index " + id, e);
return View("Create", id); return View("Create", id);
} }