From 0bdead1f1c09e5c0fbe7964403258603d8840d40 Mon Sep 17 00:00:00 2001 From: qiuhaotc Date: Sat, 28 Nov 2020 11:56:01 +0800 Subject: [PATCH] manage indexes page --- src/.editorconfig | 10 ++ .../CodeIndexConfiguration.cs | 6 +- src/CodeIndex.Common/IndexConfig.cs | 30 ++-- src/CodeIndex.Common/IndexStatus.cs | 14 +- src/CodeIndex.Common/IndexStatusInfo.cs | 22 +-- .../Pages/IndexManagement.razor | 130 ++++++++++++++++++ src/CodeIndex.Test/Common/IndexConfigTest.cs | 70 +++++----- .../Common/IndexStatusInfoTest.cs | 22 +-- src/CodeIndex.sln | 5 + 9 files changed, 227 insertions(+), 82 deletions(-) create mode 100644 src/.editorconfig diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000..890a9ab --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,10 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\qiuha\Documents\CodeIndex\src codebase based on best match to current usage at 2020/11/28 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space diff --git a/src/CodeIndex.Common/CodeIndexConfiguration.cs b/src/CodeIndex.Common/CodeIndexConfiguration.cs index c0e80d7..d9c783a 100644 --- a/src/CodeIndex.Common/CodeIndexConfiguration.cs +++ b/src/CodeIndex.Common/CodeIndexConfiguration.cs @@ -5,7 +5,7 @@ namespace CodeIndex.Common { public class CodeIndexConfiguration { - const char SplitChar = '|'; + public const char SplitChar = '|'; public string LuceneIndex { get; set; } = string.Empty; public string MonitorFolder { get; set; } = string.Empty; @@ -23,10 +23,10 @@ public class CodeIndexConfiguration public string[] ExcludedExtensionsArray => excludedExtensionsArray ??= GetSplitStringArray(ExcludedExtensions); public string[] ExcludedPathsArray => excludedPathsArray ??= GetSplitStringArray(ExcludedPaths); public string[] IncludedExtensionsArray => includedExtensionsArray ??= GetSplitStringArray(IncludedExtensions); - + public int MaximumResults { - get => maximumResults; + get => maximumResults; set { value.RequireRange(nameof(maximumResults), 10000000, 100); diff --git a/src/CodeIndex.Common/IndexConfig.cs b/src/CodeIndex.Common/IndexConfig.cs index 4f6bcab..ea8e5e9 100644 --- a/src/CodeIndex.Common/IndexConfig.cs +++ b/src/CodeIndex.Common/IndexConfig.cs @@ -3,19 +3,19 @@ namespace CodeIndex.Common { - public class IndexConfig - { - public Guid Pk { get; set; } - public string IndexName { get; set; } - public string MonitorFolder { get; set; } - public IEnumerable IncludedExtensions { get; set; } - public IEnumerable ExcludedExtensions { get; set; } - public int MaxContentHighlightLength { get; set; } - public IEnumerable ExcludedPaths { get; set; } - public int SaveIntervalSeconds { get; set; } - public string OpenIDEUriFormat { get; set; } - public string MonitorFolderRealPath { get; set; } - public DateTime IndexCreatedDate { get; set; } - public DateTime IndexLastUpdatedDate { get; set; } - } + public class IndexConfig + { + public Guid Pk { get; set; } + public string IndexName { get; set; } + public string MonitorFolder { get; set; } + public IEnumerable IncludedExtensions { get; set; } + public IEnumerable ExcludedExtensions { get; set; } + public int MaxContentHighlightLength { get; set; } + public IEnumerable ExcludedPaths { get; set; } + public int SaveIntervalSeconds { get; set; } + public string OpenIDEUriFormat { get; set; } + public string MonitorFolderRealPath { get; set; } + public DateTime IndexCreatedDate { get; set; } + public DateTime IndexLastUpdatedDate { get; set; } + } } diff --git a/src/CodeIndex.Common/IndexStatus.cs b/src/CodeIndex.Common/IndexStatus.cs index 342b7f0..746d268 100644 --- a/src/CodeIndex.Common/IndexStatus.cs +++ b/src/CodeIndex.Common/IndexStatus.cs @@ -1,10 +1,10 @@ namespace CodeIndex.Common { - public enum IndexStatus - { - Created, - Initializing, - Monitoring, - Deleting - } + public enum IndexStatus + { + Created, + Initializing, + Monitoring, + Deleting + } } diff --git a/src/CodeIndex.Common/IndexStatusInfo.cs b/src/CodeIndex.Common/IndexStatusInfo.cs index 6f19b9d..4c75f3a 100644 --- a/src/CodeIndex.Common/IndexStatusInfo.cs +++ b/src/CodeIndex.Common/IndexStatusInfo.cs @@ -1,15 +1,15 @@ namespace CodeIndex.Common { - public class IndexStatusInfo - { - public IndexStatusInfo(IndexStatus indexStatus, IndexConfig indexConfig) - { - indexConfig.RequireNotNull(nameof(indexConfig)); - IndexStatus = indexStatus; - IndexConfig = indexConfig; - } + public class IndexStatusInfo + { + public IndexStatusInfo(IndexStatus indexStatus, IndexConfig indexConfig) + { + indexConfig.RequireNotNull(nameof(indexConfig)); + IndexStatus = indexStatus; + IndexConfig = indexConfig; + } - public IndexStatus IndexStatus { get; set; } - public IndexConfig IndexConfig { get; } - } + public IndexStatus IndexStatus { get; set; } + public IndexConfig IndexConfig { get; } + } } diff --git a/src/CodeIndex.Server/Pages/IndexManagement.razor b/src/CodeIndex.Server/Pages/IndexManagement.razor index 7981176..6953c10 100644 --- a/src/CodeIndex.Server/Pages/IndexManagement.razor +++ b/src/CodeIndex.Server/Pages/IndexManagement.razor @@ -6,6 +6,136 @@ +
+ +

Stored Indexes

+ +
+ @foreach (var indexStatus in IndexStatusInfos) + { +
+
+
+

Name: @indexStatus.IndexConfig.IndexName

+

Status: @indexStatus.IndexStatus

+

Monitor Folder: @indexStatus.IndexConfig.MonitorFolder

+ + +
+
+
+ } +
+ +
+ +

+ Add or Edit Index Info + +

+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ @code { + public List IndexStatusInfos { get; set; } + + public IndexStatusInfo IndexStatusInfoForEditOrAdd { get; set; } = new IndexStatusInfo(IndexStatus.Created, new IndexConfig()); + + public string IncludedExtensions { get; set; } = string.Empty; + public string ExcludedExtensions { get; set; } = string.Empty; + public string ExcludedPaths { get; set; } = string.Empty; + + protected override void OnInitialized() + { + base.OnInitialized(); + + IndexStatusInfos = new List{ + new IndexStatusInfo(IndexStatus.Created, new IndexConfig + { + IndexName = "Dummy1", + MonitorFolder = "c:/dummy1" + }), + new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig + { + IndexName = "Dummy2", + MonitorFolder = "c:/dummy2" + }), + new IndexStatusInfo(IndexStatus.Deleting, new IndexConfig + { + IndexName = "Dummy3", + MonitorFolder = "c:/dummy3" + }), + new IndexStatusInfo(IndexStatus.Monitoring, new IndexConfig + { + IndexName = "Dummy4", + MonitorFolder = "c:/dummy4" + }) + }; + } + + void Edit(IndexStatusInfo indexStatusInfo) + { + IndexStatusInfoForEditOrAdd = indexStatusInfo; + } + + void Delete(IndexStatusInfo indexStatusInfo) + { + IndexStatusInfos.Remove(indexStatusInfo); + } + + void SaveIndexInfo() + { + IndexStatusInfoForEditOrAdd.IndexConfig.IncludedExtensions = IncludedExtensions.Split(CodeIndexConfiguration.SplitChar); + IndexStatusInfoForEditOrAdd.IndexConfig.ExcludedExtensions = ExcludedExtensions.Split(CodeIndexConfiguration.SplitChar); + IndexStatusInfoForEditOrAdd.IndexConfig.ExcludedPaths = ExcludedPaths.Split(CodeIndexConfiguration.SplitChar); + + if (!IndexStatusInfos.Contains(IndexStatusInfoForEditOrAdd)) + { + IndexStatusInfos.Add(IndexStatusInfoForEditOrAdd); + } + + IndexStatusInfoForEditOrAdd = new IndexStatusInfo(IndexStatus.Created, new IndexConfig()); + + IncludedExtensions = string.Empty; + ExcludedExtensions = string.Empty; + ExcludedPaths = string.Empty; + } } diff --git a/src/CodeIndex.Test/Common/IndexConfigTest.cs b/src/CodeIndex.Test/Common/IndexConfigTest.cs index 454a17b..7d812d8 100644 --- a/src/CodeIndex.Test/Common/IndexConfigTest.cs +++ b/src/CodeIndex.Test/Common/IndexConfigTest.cs @@ -4,40 +4,40 @@ namespace CodeIndex.Test { - class IndexConfigTest - { - [Test] - public void TestConstructor() - { - var pk = Guid.NewGuid(); - var config = new IndexConfig - { - ExcludedExtensions = new[] { "A" }, - ExcludedPaths = new[] { "B" }, - IncludedExtensions = new[] { "C" }, - IndexCreatedDate = new DateTime(2020, 1, 1), - IndexLastUpdatedDate = new DateTime(2020, 1, 2), - IndexName = "ABC", - MaxContentHighlightLength = 100, - MonitorFolder = "BCA", - MonitorFolderRealPath = "AAA", - OpenIDEUriFormat = "BBB", - Pk = pk, - SaveIntervalSeconds = 10 - }; + class IndexConfigTest + { + [Test] + public void TestConstructor() + { + var pk = Guid.NewGuid(); + var config = new IndexConfig + { + ExcludedExtensions = new[] { "A" }, + ExcludedPaths = new[] { "B" }, + IncludedExtensions = new[] { "C" }, + IndexCreatedDate = new DateTime(2020, 1, 1), + IndexLastUpdatedDate = new DateTime(2020, 1, 2), + IndexName = "ABC", + MaxContentHighlightLength = 100, + MonitorFolder = "BCA", + MonitorFolderRealPath = "AAA", + OpenIDEUriFormat = "BBB", + Pk = pk, + SaveIntervalSeconds = 10 + }; - CollectionAssert.AreEquivalent(config.ExcludedExtensions, new[] { "A" }); - CollectionAssert.AreEquivalent(config.ExcludedPaths, new[] { "B" }); - CollectionAssert.AreEquivalent(config.IncludedExtensions, new[] { "C" }); - Assert.AreEqual(new DateTime(2020, 1, 1), config.IndexCreatedDate); - Assert.AreEqual(new DateTime(2020, 1, 2), config.IndexLastUpdatedDate); - Assert.AreEqual("ABC", config.IndexName); - Assert.AreEqual(100, config.MaxContentHighlightLength); - Assert.AreEqual("BCA", config.MonitorFolder); - Assert.AreEqual("AAA", config.MonitorFolderRealPath); - Assert.AreEqual("BBB", config.OpenIDEUriFormat); - Assert.AreEqual(pk, config.Pk); - Assert.AreEqual(10, config.SaveIntervalSeconds); - } - } + CollectionAssert.AreEquivalent(config.ExcludedExtensions, new[] { "A" }); + CollectionAssert.AreEquivalent(config.ExcludedPaths, new[] { "B" }); + CollectionAssert.AreEquivalent(config.IncludedExtensions, new[] { "C" }); + Assert.AreEqual(new DateTime(2020, 1, 1), config.IndexCreatedDate); + Assert.AreEqual(new DateTime(2020, 1, 2), config.IndexLastUpdatedDate); + Assert.AreEqual("ABC", config.IndexName); + Assert.AreEqual(100, config.MaxContentHighlightLength); + Assert.AreEqual("BCA", config.MonitorFolder); + Assert.AreEqual("AAA", config.MonitorFolderRealPath); + Assert.AreEqual("BBB", config.OpenIDEUriFormat); + Assert.AreEqual(pk, config.Pk); + Assert.AreEqual(10, config.SaveIntervalSeconds); + } + } } \ No newline at end of file diff --git a/src/CodeIndex.Test/Common/IndexStatusInfoTest.cs b/src/CodeIndex.Test/Common/IndexStatusInfoTest.cs index a29e3a6..544f7f3 100644 --- a/src/CodeIndex.Test/Common/IndexStatusInfoTest.cs +++ b/src/CodeIndex.Test/Common/IndexStatusInfoTest.cs @@ -4,15 +4,15 @@ namespace CodeIndex.Test { - class IndexStatusInfoTest - { - [Test] - public void TestConstructor() - { - var statusInfo = new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig()); - Assert.IsNotNull(statusInfo.IndexConfig); - Assert.AreEqual(IndexStatus.Initializing, statusInfo.IndexStatus); - Assert.Throws(() => _ = new IndexStatusInfo(default, null)); - } - } + class IndexStatusInfoTest + { + [Test] + public void TestConstructor() + { + var statusInfo = new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig()); + Assert.IsNotNull(statusInfo.IndexConfig); + Assert.AreEqual(IndexStatus.Initializing, statusInfo.IndexStatus); + Assert.Throws(() => _ = new IndexStatusInfo(default, null)); + } + } } diff --git a/src/CodeIndex.sln b/src/CodeIndex.sln index 7bd1bf1..4c04f18 100644 --- a/src/CodeIndex.sln +++ b/src/CodeIndex.sln @@ -27,6 +27,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{B0519424-9D6 ..\doc\UseExtension.gif = ..\doc\UseExtension.gif EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D0B5A7C3-31A4-463A-B27E-2D246D5BF8DD}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU