From bfda9230cec84b7281c4f01844adc02869983b1a Mon Sep 17 00:00:00 2001 From: xietao Date: Tue, 23 Aug 2022 23:54:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DigitalPlatform.Install/InstallHelper.cs | 10 +- .../BiblioStatis/OutputDocxCatalog.cs | 375 +++++++++++++++++- dp2Circulation/dp2Circulation.csproj | 2 +- dp2Installer/dp2Installer.csproj | 2 +- dp2LibraryXE/MainForm.cs | 8 + dp2LibraryXE/design.txt | 13 + dp2LibraryXE/dp2LibraryXE.csproj | 32 +- 7 files changed, 420 insertions(+), 22 deletions(-) create mode 100644 dp2LibraryXE/design.txt diff --git a/DigitalPlatform.Install/InstallHelper.cs b/DigitalPlatform.Install/InstallHelper.cs index 233f9da1a..c5714b35e 100644 --- a/DigitalPlatform.Install/InstallHelper.cs +++ b/DigitalPlatform.Install/InstallHelper.cs @@ -101,7 +101,15 @@ public static void DeleteOldFiles( && IndexOf(excludeFileNames, line) != -1) continue; string path = Path.Combine(strTargetDir, line); - File.Delete(path); + try + { + File.Delete(path); + } + catch(DirectoryNotFoundException) // 2022/8/23 + { + + } + proc_deleted?.Invoke(path); } diff --git a/dp2Circulation/BiblioStatis/OutputDocxCatalog.cs b/dp2Circulation/BiblioStatis/OutputDocxCatalog.cs index 96c1a1a20..efba0ce79 100644 --- a/dp2Circulation/BiblioStatis/OutputDocxCatalog.cs +++ b/dp2Circulation/BiblioStatis/OutputDocxCatalog.cs @@ -15,6 +15,7 @@ using DigitalPlatform.Typography; using DigitalPlatform.LibraryClient; using DigitalPlatform.LibraryClient.localhost; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace dp2Circulation { @@ -208,12 +209,14 @@ public override void OnRecord(object sender, StatisEventArgs e) } // 归并连续的号码 - barcodes.Sort((a, b) => { + barcodes.Sort((a, b) => + { if (a.Length != b.Length) return a.Length - b.Length; // 位数少的在前 return string.CompareOrdinal(a, b); // 同样位数的比较先后 }); - barcodes = StringUtil.CompactNumbers(barcodes); + // barcodes = OutputDocxCatalog.CompactNumbersEx(barcodes); + barcodes = CompactNumbersEx(barcodes); bool first = _index == _BiblioNoStart; @@ -522,7 +525,375 @@ void loader_Prompt(object sender, MessagePromptEventArgs e) } } +#if OLD // 合并连续的号码 + // 一条书目信息下有4册实体,021001,021002,021003,021004,显示成:021001-021004,“021001”“-”“021004”各占一行,一共占3行。 + public static List CompactNumbersEx(List source) + { + List results = new List(); + + string strPrev = ""; + string strStart = ""; + string strTail = ""; + int delta = 0; // strStart 和 strTail 之间间隔的号码个数 + for (int i = 0; i < source.Count; i++) + { + string strCurrent = source[i]; + if (string.IsNullOrEmpty(strPrev) == false) + { + string strResult = ""; + + string strError = ""; + // 给一个被字符引导的数字增加一个数量。 + // 例如 B019X + 1 变成 B020X + int nRet = StringUtil.IncreaseNumber(strPrev, + 1, + out strResult, + out strError); + if (nRet == -1) + continue; + delta++; + if (strCurrent == strResult) + { + if (strStart == "") + { + strStart = strPrev; + delta = 0; + } + strTail = strCurrent; + } + else + { + if (strStart != "") + { + //int nLengh = GetCommonPartLength(strStart, strTail); + //results.Add(strStart + "-" + strTail.Substring(nLengh)); + { + results.Add(strStart); + if (delta > 1) + results.Add("-"); + results.Add(strTail); + delta = 0; + } + strStart = ""; + strTail = ""; + } + else + { + // results.Add(strCurrent); + results.Add(strPrev); + delta = 0; + } + } + } + + strPrev = strCurrent; + } + + if (strStart != "") + { + //int nLengh = GetCommonPartLength(strStart, strTail); + //results.Add(strStart + "-" + strTail.Substring(nLengh)); + { + results.Add(strStart); + if (delta > 1) + results.Add("-"); + results.Add(strTail); + delta = 0; + } + strStart = ""; + strTail = ""; + strPrev = ""; // 2022/8/23 + } + + if (string.IsNullOrEmpty(strPrev) == false) + { + results.Add(strPrev); + } + return results; + } +#endif + + public static List CompactNumbersEx(List source) + { + List results = new List(); + int start = 0; + while (start < source.Count) + { + var break_pos = FindBreak(start); + Debug.Assert(break_pos > start); + if (break_pos <= start + 3) // 三个及以内 + { + for (int i = start; i < break_pos; i++) + { + results.Add(source[i]); + } + } + else + { + results.Add(source[start]); + results.Add("-"); + results.Add(source[break_pos - 1]); + } + start = break_pos; + + } + return results; + + // 从指定位置开始,探测连续号码范围的断点位置。断点位置就是下一个不连续的开头位置 + int FindBreak(int start_param) + { + string prev = source[start_param]; + for (int i = start_param + 1; i < source.Count; i++) + { + string current = source[i]; + // 给一个被字符引导的数字增加一个数量。 + // 例如 B019X + 1 变成 B020X + int nRet = StringUtil.IncreaseNumber(prev, + 1, + out string larger, + out string strError); + if (nRet == -1) + return i; // TODO: 抛出异常 + if (current != larger) + return i; + prev = current; + } + + return source.Count; + } + + } + + } + [TestClass] + public class TestOutputDocxCatalog + { + [TestMethod] + public void Test_compactNumber_01() + { + List source = new List(); + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(0, result.Count); + } + + [TestMethod] + public void Test_compactNumber_02() + { + List source = new List() { "0000001" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(1, result.Count); + Assert.AreEqual("0000001", result[0]); + } + + [TestMethod] + public void Test_compactNumber_03() + { + // 只有两个号码的连续范围,合并后依然表达为两个独立号码 + List source = new List() { "0000001", + "0000002" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(2, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("0000002", result[1]); + } + + [TestMethod] + public void Test_compactNumber_04() + { + List source = new List() { + "0000001", + "0000002", + "0000003", + "0000004", + "0000005", + "0000006", + "0000007", + "0000008", + "0000009", + "0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("-", result[1]); + Assert.AreEqual("0000010", result[2]); + + } + + [TestMethod] + public void Test_compactNumber_05() + { + List source = new List() { + "0000001", + "0000002", + "0000009", + "0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(4, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("0000002", result[1]); + Assert.AreEqual("0000009", result[2]); + Assert.AreEqual("0000010", result[3]); + } + + [TestMethod] + public void Test_compactNumber_06() + { + List source = new List() { + "0000001", + "0000009", + "0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("0000009", result[1]); + Assert.AreEqual("0000010", result[2]); + } + + [TestMethod] + public void Test_compactNumber_07() + { + List source = new List() { + "0000001", + "0000002", + "0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("0000002", result[1]); + Assert.AreEqual("0000010", result[2]); + } + + [TestMethod] + public void Test_compactNumber_08() + { + List source = new List() { + "0000001", + "0000003", + "0000005" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("0000001", result[0]); + Assert.AreEqual("0000003", result[1]); + Assert.AreEqual("0000005", result[2]); + } + + // + + [TestMethod] + public void Test_compactNumber_12() + { + List source = new List() { "B0000001" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(1, result.Count); + Assert.AreEqual("B0000001", result[0]); + } + + [TestMethod] + public void Test_compactNumber_13() + { + List source = new List() { "B0000001", + "B0000002" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(2, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("B0000002", result[1]); + } + + [TestMethod] + public void Test_compactNumber_14() + { + List source = new List() { + "B0000001", + "B0000002", + "B0000003", + "B0000004", + "B0000005", + "B0000006", + "B0000007", + "B0000008", + "B0000009", + "B0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("-", result[1]); + Assert.AreEqual("B0000010", result[2]); + } + + [TestMethod] + public void Test_compactNumber_15() + { + List source = new List() { + "B0000001", + "B0000002", + "B0000009", + "B0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(4, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("B0000002", result[1]); + Assert.AreEqual("B0000009", result[2]); + Assert.AreEqual("B0000010", result[3]); + } + + [TestMethod] + public void Test_compactNumber_16() + { + List source = new List() { + "B0000001", + "B0000009", + "B0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("B0000009", result[1]); + Assert.AreEqual("B0000010", result[2]); + } + + [TestMethod] + public void Test_compactNumber_17() + { + List source = new List() { + "B0000001", + "B0000002", + "B0000010" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("B0000002", result[1]); + Assert.AreEqual("B0000010", result[2]); + } + + [TestMethod] + public void Test_compactNumber_20() + { + List source = new List() { + "B0000001", + "B0000002", + "B0000003" }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("B0000002", result[1]); + Assert.AreEqual("B0000003", result[2]); + } + + [TestMethod] + public void Test_compactNumber_21() + { + List source = new List() { + "B0000001", + "B0000002", + "B0000003", + "B0000004" + }; + var result = OutputDocxCatalog.CompactNumbersEx(source); + Assert.AreEqual(3, result.Count); + Assert.AreEqual("B0000001", result[0]); + Assert.AreEqual("-", result[1]); + Assert.AreEqual("B0000004", result[2]); + } } } diff --git a/dp2Circulation/dp2Circulation.csproj b/dp2Circulation/dp2Circulation.csproj index b21382b33..e6a18243f 100644 --- a/dp2Circulation/dp2Circulation.csproj +++ b/dp2Circulation/dp2Circulation.csproj @@ -54,7 +54,7 @@ dp2 V3 true publish.htm - 295 + 296 3.8.0.%2a false true diff --git a/dp2Installer/dp2Installer.csproj b/dp2Installer/dp2Installer.csproj index 14f74b84f..6c42e77cd 100644 --- a/dp2Installer/dp2Installer.csproj +++ b/dp2Installer/dp2Installer.csproj @@ -36,7 +36,7 @@ dp2 V3 true publish.htm - 327 + 328 3.2.2.%2a false true diff --git a/dp2LibraryXE/MainForm.cs b/dp2LibraryXE/MainForm.cs index 045c8a9d3..cf99f24fc 100644 --- a/dp2LibraryXE/MainForm.cs +++ b/dp2LibraryXE/MainForm.cs @@ -29,6 +29,7 @@ using DigitalPlatform.CirculationClient; using DigitalPlatform.LibraryClient; using System.Text; +using System.Runtime.InteropServices.ComTypes; namespace dp2LibraryXE { @@ -461,6 +462,13 @@ await Task.Run(() => { } } + catch(Exception ex) // 2022/8/23 + { + string error = $"Initialize() 出现异常: {ExceptionUtil.GetDebugText(ex)}"; + WriteErrorLog(error); + MessageBox.Show(this, error); + // TODO: 在 Web 控件上显示一行红色的报错文字 + } finally { #if NO diff --git a/dp2LibraryXE/design.txt b/dp2LibraryXE/design.txt new file mode 100644 index 000000000..79875842e --- /dev/null +++ b/dp2LibraryXE/design.txt @@ -0,0 +1,13 @@ + +2022/8/23 +关于 SQLite.interop.dll 文件编译时自动拷贝到 bin\debug\x86 x64 目录: + +https://stackoverflow.com/questions/13028069/unable-to-load-dll-sqlite-interop-dll +Add the following to your csproj on your "main"/root project + + + true + false + false + false + \ No newline at end of file diff --git a/dp2LibraryXE/dp2LibraryXE.csproj b/dp2LibraryXE/dp2LibraryXE.csproj index c94453511..2b92fde37 100644 --- a/dp2LibraryXE/dp2LibraryXE.csproj +++ b/dp2LibraryXE/dp2LibraryXE.csproj @@ -20,6 +20,10 @@ true + true + false + false + false c:\publish\dp2libraryxe\v3_dev\ true Web @@ -38,7 +42,7 @@ dp2 V3 true publish.htm - 276 + 280 3.1.2.%2a false true @@ -232,15 +236,10 @@ SelectSqlServerDialog.cs + Always - - Always - - - Always - FirstRunDialog.cs @@ -494,19 +493,18 @@ CD /D $(ProjectDir) $(ProjectDir)..\updateAssemblyBinding\bin\debug\updateAssemblyBinding.exe source:$(ProjectDir)..\dp2opac\web.config target:$(ProjectDir)web.config - CALL copyopac.bat -CALL copydata.bat - -CALL copyinterop.bat +CALL copydata.bat - ECHO copy sqlite.interop.dll to x86 and x64 from bin\debug directory -CD /D $(ProjectDir) -MD x86 -xcopy $(TargetDir)x86 x86 /Y -MD x64 -xcopy $(TargetDir)x64 x64 /Y + REM ECHO copy sqlite.interop.dll to x86 and x64 from bin\debug directory +REM CD /D $(ProjectDir) +REM MD x86 +REM xcopy $(TargetDir)x86 x86 /Y +REM MD x64 +REM xcopy $(TargetDir)x64 x64 /Y + +