-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathReplication.cs
4189 lines (3653 loc) · 150 KB
/
Replication.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using DigitalPlatform.IO;
using DigitalPlatform.LibraryClient;
using DigitalPlatform.LibraryClient.localhost;
using DigitalPlatform.Text;
using DigitalPlatform.Xml;
namespace DigitalPlatform.LibraryServer.Reporting
{
/// <summary>
/// 同步和复制功能
/// </summary>
public class Replication
{
// 初始化
public int Initialize(
LibraryChannel channel,
out string strError)
{
strError = "";
int nRet = CheckVersion(channel,
out strError);
if (nRet == -1)
return -1;
nRet = GetDbFromInfos(channel,
out strError);
if (nRet == -1)
return -1;
nRet = GetAllDatabaseInfo(channel,
out strError);
if (nRet == -1)
return -1;
nRet = InitialBiblioDbProperties(channel,
out strError);
if (nRet == -1)
return -1;
return 0;
}
#region 初始化各种数据结构
public string ServerVersion { get; set; }
public string ServerUID { get; set; }
public int CheckVersion(LibraryChannel channel,
out string strError)
{
strError = "";
long lRet = channel.GetVersion(null,
out string strVersion,
out string strUID,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 获得版本号的过程发生错误:" + strError;
return -1;
}
this.ServerUID = strUID;
if (string.IsNullOrEmpty(strVersion) == true)
strVersion = "2.0";
this.ServerVersion = strVersion;
return 1;
}
/// <summary>
/// 书目库检索路径信息集合
/// </summary>
public BiblioDbFromInfo[] BiblioDbFromInfos = null; // 书目库检索路径信息
public string Lang = "zh";
// 初始化各种检索途径信息
public int GetDbFromInfos(LibraryChannel channel,
out string strError)
{
strError = "";
// 获得书目库的检索途径
BiblioDbFromInfo[] infos = null;
long lRet = channel.ListDbFroms(null,
"biblio",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出书目库检索途径过程发生错误:" + strError;
return -1;
}
this.BiblioDbFromInfos = infos;
#if NO
if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "3.6") >= 0)
{
infos = null;
lRet = channel.ListDbFroms(Stop,
"authority",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出规范库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.AuthorityDbFromInfos = infos;
}
// 获得读者库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"reader",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出读者库检索途径过程发生错误:" + strError;
goto ERROR1;
}
if (infos != null && this.BiblioDbFromInfos != null
&& infos.Length > 0 && this.BiblioDbFromInfos.Length > 0
&& infos[0].Caption == this.BiblioDbFromInfos[0].Caption)
{
// 如果第一个元素的caption一样,则说明GetDbFroms API是旧版本的,不支持获取读者库的检索途径功能
this.ReaderDbFromInfos = null;
}
else
{
this.ReaderDbFromInfos = infos;
}
if (StringUtil.CompareVersion(this.ServerVersion, "2.11") >= 0)
{
// 获得实体库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"item",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出实体库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.ItemDbFromInfos = infos;
// 获得期库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"issue",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出期库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.IssueDbFromInfos = infos;
// 获得订购库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"order",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出订购库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.OrderDbFromInfos = infos;
// 获得评注库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"comment",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出评注库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.CommentDbFromInfos = infos;
}
if (StringUtil.CompareVersion(this.ServerVersion, "2.17") >= 0)
{
// 获得发票库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"invoice",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出发票库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.InvoiceDbFromInfos = infos;
// 获得违约金库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"amerce",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出违约金库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.AmerceDbFromInfos = infos;
}
if (StringUtil.CompareVersion(this.ServerVersion, "2.47") >= 0)
{
// 获得预约到书库的检索途径
infos = null;
lRet = channel.ListDbFroms(Stop,
"arrived",
this.Lang,
out infos,
out strError);
if (lRet == -1)
{
strError = "针对服务器 " + channel.Url + " 列出预约到书库检索途径过程发生错误:" + strError;
goto ERROR1;
}
this.ArrivedDbFromInfos = infos;
}
// 需要检查一下Caption是否有重复(但是style不同)的,如果有,需要修改Caption名
this.CanonicalizeBiblioFromValues();
#endif
return 0;
}
/// <summary>
/// 书目库属性集合
/// </summary>
public static List<BiblioDbProperty> BiblioDbProperties = null;
public int InitialBiblioDbProperties(LibraryChannel channel,
out string strError)
{
strError = "";
int nRet = 0;
BiblioDbProperties = new List<BiblioDbProperty>();
// this.AuthorityDbProperties = new List<BiblioDbProperty>();
if (this.AllDatabaseDom == null)
return 0;
{
XmlNodeList nodes = this.AllDatabaseDom.DocumentElement.SelectNodes("database[@type='biblio']");
foreach (XmlNode node in nodes)
{
string strName = DomUtil.GetAttr(node, "name");
string strType = DomUtil.GetAttr(node, "type");
// string strRole = DomUtil.GetAttr(node, "role");
// string strLibraryCode = DomUtil.GetAttr(node, "libraryCode");
BiblioDbProperty property = new BiblioDbProperty();
BiblioDbProperties.Add(property);
property.DbName = DomUtil.GetAttr(node, "name");
property.ItemDbName = DomUtil.GetAttr(node, "entityDbName");
property.Syntax = DomUtil.GetAttr(node, "syntax");
property.IssueDbName = DomUtil.GetAttr(node, "issueDbName");
property.OrderDbName = DomUtil.GetAttr(node, "orderDbName");
property.CommentDbName = DomUtil.GetAttr(node, "commentDbName");
property.Role = DomUtil.GetAttr(node, "role");
bool bValue = true;
nRet = DomUtil.GetBooleanParam(node,
"inCirculation",
true,
out bValue,
out strError);
property.InCirculation = bValue;
}
}
/*
{
XmlNodeList nodes = this.AllDatabaseDom.DocumentElement.SelectNodes("database[@type='authority']");
foreach (XmlNode node in nodes)
{
string strName = DomUtil.GetAttr(node, "name");
string strType = DomUtil.GetAttr(node, "type");
BiblioDbProperty property = new BiblioDbProperty();
this.AuthorityDbProperties.Add(property);
property.DbName = DomUtil.GetAttr(node, "name");
property.Syntax = DomUtil.GetAttr(node, "syntax");
property.Usage = DomUtil.GetAttr(node, "usage");
}
}
*/
// MessageBox.Show(this, Convert.ToString(lRet) + " : " + strError);
return 0;
}
/// <summary>
/// 表示当前全部数据库信息的 XmlDocument 对象
/// </summary>
public XmlDocument AllDatabaseDom = null;
// 获取全部数据库定义
public int GetAllDatabaseInfo(LibraryChannel channel,
out string strError)
{
strError = "";
long lRet = 0;
this.AllDatabaseDom = null;
lRet = channel.ManageDatabase(
null,
"getinfo",
"",
"",
"",
out string strValue,
out strError);
if (lRet == -1)
{
if (channel.ErrorCode == ErrorCode.AccessDenied)
{
}
strError = "针对服务器 " + channel.Url + " 获得全部数据库定义过程发生错误:" + strError;
return -1;
}
XmlDocument dom = new XmlDocument();
try
{
dom.LoadXml(strValue);
}
catch (Exception ex)
{
strError = "XML装入DOM时出错: " + ex.Message;
return -1;
}
this.AllDatabaseDom = dom;
return 0;
}
#if NO
// 记忆书目库的分类号 style 列表
int MemoryClassFromStyles(XmlElement root,
out string strError)
{
strError = "";
int nRet = GetClassFromStyles(out List<BiblioDbFromInfo> styles,
out strError);
if (nRet == -1)
return -1;
if (styles.Count == 0)
{
strError = "书目库尚未配置分类号检索点";
return 0;
}
XmlElement container = root.SelectSingleNode("classStyles") as XmlElement;
if (container == null)
{
container = root.OwnerDocument.CreateElement("classStyles");
root.AppendChild(container);
}
else
container.RemoveAll();
foreach (BiblioDbFromInfo info in styles)
{
XmlElement style_element = root.OwnerDocument.CreateElement("style");
container.AppendChild(style_element);
style_element.SetAttribute("style", info.Style);
style_element.SetAttribute("caption", info.Caption);
}
return 1;
}
// 获得所有分类号检索途径 style
internal int GetClassFromStyles(
out List<BiblioDbFromInfo> styles,
out string strError)
{
strError = "";
styles = new List<BiblioDbFromInfo>();
foreach (BiblioDbFromInfo info in this.BiblioDbFromInfos)
{
if (StringUtil.IsInList("__class", info.Style) == true)
{
string strStyle = GetPureStyle(info.Style);
if (string.IsNullOrEmpty(strStyle) == true)
{
strError = "检索途径 " + info.Caption + " 的 style 值 '" + info.Style + "' 其中应该有至少一个不带 '_' 前缀的子串";
return -1;
}
BiblioDbFromInfo style = new BiblioDbFromInfo();
style.Caption = info.Caption;
style.Style = strStyle;
styles.Add(style);
}
}
return 0;
}
// 从计划文件中获得所有分类号检索途径 style
internal int GetClassFromStyles(
XmlElement root,
out List<string> styles,
out string strError)
{
strError = "";
styles = new List<string>();
XmlNodeList nodes = root.SelectNodes("classStyles/style");
foreach (XmlElement element in nodes)
{
styles.Add(element.GetAttribute("style"));
}
return 0;
}
// 获得不是 _ 和 __ 打头的 style 值
static string GetPureStyle(string strText)
{
List<string> results = new List<string>();
string[] parts = strText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
{
if (s[0] == '_')
continue;
results.Add(s);
}
return StringUtil.MakePathList(results);
}
#endif
#endregion
// 获得全部数据库定义
public static int GetAllDatabaseInfo(
LibraryChannel channel,
out XmlDocument dom,
out string strError)
{
strError = "";
long lRet = 0;
dom = null;
lRet = channel.ManageDatabase(
null,
"getinfo",
"",
"",
"",
out string strValue,
out strError);
if (lRet == -1)
{
if (channel.ErrorCode == ErrorCode.AccessDenied)
{
}
strError = "针对服务器 " + channel.Url + " 获得全部数据库定义过程发生错误:" + strError;
return -1;
}
dom = new XmlDocument();
try
{
dom.LoadXml(strValue);
}
catch (Exception ex)
{
strError = "XML装入DOM时出错: " + ex.Message;
return -1;
}
return 0;
}
static List<string> GetBiblioDbNames(XmlDocument database_dom)
{
List<string> results = new List<string>();
XmlNodeList nodes = database_dom.DocumentElement.SelectNodes("database[@type='biblio']");
foreach (XmlElement node in nodes)
{
string strName = node.GetAttribute("name");
if (string.IsNullOrEmpty(strName) == false)
results.Add(strName);
}
return results;
}
static List<string> GetItemDbNames(XmlDocument database_dom)
{
List<string> results = new List<string>();
XmlNodeList nodes = database_dom.DocumentElement.SelectNodes("database[@type='biblio']");
foreach (XmlElement node in nodes)
{
string strName = node.GetAttribute("name");
string strType = node.GetAttribute("type");
string itemDbName = node.GetAttribute("entityDbName");
string syntax = node.GetAttribute("syntax");
string issueDbName = node.GetAttribute("issueDbName");
string orderDbName = node.GetAttribute("orderDbName");
string commentDbName = node.GetAttribute("commentDbName");
string role = node.GetAttribute("role");
if (string.IsNullOrEmpty(itemDbName) == false)
results.Add(itemDbName);
#if NO
bool bValue = true;
nRet = DomUtil.GetBooleanParam(node,
"inCirculation",
true,
out bValue,
out strError);
property.InCirculation = bValue;
#endif
}
return results;
}
string GetReaderDbLibraryCode(string strReaderDbName)
{
XmlNodeList nodes = this.AllDatabaseDom.DocumentElement.SelectNodes("database[@type='reader']");
foreach (XmlElement node in nodes)
{
string dbName = node.GetAttribute("name");
string libraryCode = node.GetAttribute("libraryCode");
if (dbName == strReaderDbName)
return libraryCode;
}
return null;
}
static List<string> GetReaderDbNames(XmlDocument database_dom)
{
List<string> results = new List<string>();
XmlNodeList nodes = database_dom.DocumentElement.SelectNodes("database[@type='reader']");
foreach (XmlElement node in nodes)
{
string dbName = node.GetAttribute("name");
string libraryCode = node.GetAttribute("libraryCode");
#if NO
bool bValue = true;
nRet = DomUtil.GetBooleanParam(node,
"inCirculation",
true,
out bValue,
out strError);
property.InCirculation = bValue;
#endif
if (string.IsNullOrEmpty(dbName) == false)
results.Add(dbName);
}
return results;
}
// 本地库的版本号
// 0.01 (2014/4/30) 第一个版本
// 0.02 (2014/5/6) item 表 增加了两个 index: item_itemrecpath_index 和 item_biliorecpath_index
// 0.03 (2014/5/29) item 表增加了 borrower borrowtime borrowperiod returningtime 等字段
// 0.04 (2014/6/2) breakpoint 文件根元素下增加了 classStyles 元素
// 0.05 (2014/6/12) item 表增加了 price unit 列; operlogamerce 表的 price 列分开为 price 和 unit 列
// 0.06 (2014/6/16) operlogxxx 表中增加了 subno 字段
// 0.07 (2014/6/19) operlogitem 表增加了 itembarcode 字段
// 0.08 (2014/11/6) reader 表增加了 state 字段
// 0.09 (2015/7/14) 增加了 operlogpassgate 和 operloggetres 表
// 0.10 (2016/5/5) 给每个 operlogxxx 表增加了 librarycode 字段
// 0.11 (2016/12/8) 以前版本 operlogamerce 中 action 为 undo 的行,price 字段内容都为空,会导致 472 报表中统计出来的实收金额偏大,这个版本修正了这个 bug
static string _local_version = "0.11";
public delegate void Delegate_showMessage(string text);
// TODO: 最好把第一次初始化本地 sql 表的动作也纳入 XML 文件中,这样做单项任务的时候,就不会毁掉其他的表
// 创建批处理计划
// 根元素的 state 属性, 值为 first 表示正在进行首次创建,尚未完成; daily 表示已经创建完,进入每日同步阶段
// parameters:
// strTypeList 类型列表。为 * user item reader biblio operlog accesslog 的组合
public int BuildFirstPlan(string strTypeList,
LibraryChannel channel,
Delegate_showMessage func_showMessage,
out XmlDocument task_dom,
out string strError)
{
strError = "";
long lRet = 0;
int nRet = 0;
task_dom = new XmlDocument();
task_dom.LoadXml("<root />");
// 开始处理时的日期
string strEndDate = DateTimeUtil.DateTimeToString8(DateTime.Now);
task_dom.DocumentElement.SetAttribute("version", _local_version);
task_dom.DocumentElement.SetAttribute("state", "first"); // 表示首次创建尚未完成
// 记载首次创建的结束时间点
task_dom.DocumentElement.SetAttribute("end_date", strEndDate);
// *** 创建用户表
if (strTypeList == "*"
|| StringUtil.IsInList("user", strTypeList) == true)
{
XmlNode node = task_dom.CreateElement("user");
task_dom.DocumentElement.AppendChild(node);
}
// *** 创建 item 表
if (strTypeList == "*"
|| StringUtil.IsInList("item", strTypeList) == true)
{
// 获得全部实体库名
List<string> item_dbnames = GetItemDbNames(this.AllDatabaseDom);
// 获得每个实体库的尺寸
foreach (string strItemDbName in item_dbnames)
{
func_showMessage?.Invoke("正在计划任务 检索 " + strItemDbName + " ...");
// 此处检索仅获得命中数即可
lRet = channel.SearchItem(null,
strItemDbName,
"", //
-1,
"__id",
"left",
"zh",
null, // strResultSetName
"", // strSearchStyle
"", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
out strError);
if (lRet == -1)
return -1;
XmlElement node = task_dom.CreateElement("database");
task_dom.DocumentElement.AppendChild(node);
node.SetAttribute("name", strItemDbName);
node.SetAttribute("type", "item");
node.SetAttribute("count", lRet.ToString());
}
}
// *** 创建 reader 表
if (strTypeList == "*"
|| StringUtil.IsInList("reader", strTypeList) == true)
{
// 获得全部读者库名
List<string> reader_dbnames = GetReaderDbNames(this.AllDatabaseDom);
//
foreach (string strReaderDbName in reader_dbnames)
{
func_showMessage?.Invoke("正在计划任务 检索 " + strReaderDbName + " ...");
// 此处检索仅获得命中数即可
lRet = channel.SearchReader(null,
strReaderDbName,
"", //
-1,
"__id",
"left",
"zh",
null, // strResultSetName
"", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
out strError);
if (lRet == -1)
return -1;
XmlElement node = task_dom.CreateElement("database");
task_dom.DocumentElement.AppendChild(node);
node.SetAttribute("name", strReaderDbName);
node.SetAttribute("type", "reader");
node.SetAttribute("count", lRet.ToString());
}
}
// *** 创建 biblio 表
// *** 创建 class 表
if (strTypeList == "*"
|| StringUtil.IsInList("biblio", strTypeList) == true)
{
// 获得全部书目库名
List<string> biblio_dbnames = GetBiblioDbNames(this.AllDatabaseDom);
#if NO
// 获得所有分类号检索途径 style
List<string> styles = new List<string>();
nRet = GetClassFromStyles(out styles,
out strError);
if (nRet == -1)
return -1;
#endif
#if NO
// 记忆书目库的分类号 style 列表
nRet = MemoryClassFromStyles(task_dom.DocumentElement,
out strError);
if (nRet == -1)
return -1;
if (nRet == 0)
{
/*
DialogResult result = DialogResult.No;
string strText = strError;
this.Invoke((Action)(() =>
{
result = MessageBox.Show(this,
strText + "\r\n\r\n建议先中断处理,配置好书目库的分类号检索点再重新创建本地存储。如果此时继续处理,则会无法同步分类号信息,以后也无法创建和分类号有关的报表。\r\n\r\n是否继续处理?",
"ReportForm",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
}));
if (result == System.Windows.Forms.DialogResult.No)
return -1; //
*/
return -1;
}
// 从计划文件中获得所有分类号检索途径 style
List<string> styles = new List<string>();
nRet = GetClassFromStyles(
task_dom.DocumentElement,
out styles,
out strError);
if (nRet == -1)
return -1;
#endif
//
foreach (string strBiblioDbName in biblio_dbnames)
{
func_showMessage?.Invoke("正在计划任务 检索 " + strBiblioDbName + " ...");
string strQueryXml = "";
// 此处检索仅获得命中数即可
lRet = channel.SearchBiblio(null,
strBiblioDbName,
"", //
-1,
"recid", // "__id",
"left",
"zh",
null, // strResultSetName
"", // strSearchStyle
"", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
"",
out strQueryXml,
out strError);
if (lRet == -1)
return -1;
XmlElement node = task_dom.CreateElement("database");
task_dom.DocumentElement.AppendChild(node);
node.SetAttribute("name", strBiblioDbName);
node.SetAttribute("type", "biblio");
node.SetAttribute("count", lRet.ToString());
#if NO
foreach (string strStyle in styles)
{
func_showMessage?.Invoke("正在计划任务 检索 " + strBiblioDbName + " " + strStyle + " ...");
// 此处检索仅获得命中数即可
lRet = channel.SearchBiblio(null,
strBiblioDbName,
"", //
-1,
strStyle, // "__id",
"left", // this.textBox_queryWord.Text == "" ? "left" : "exact", // 原来为left 2007/10/18 changed
"zh",
null, // strResultSetName
"", // strSearchStyle
"keyid", //strOutputStyle, // (bOutputKeyCount == true ? "keycount" : ""),
"",
out strQueryXml,
out strError);
if (lRet == -1)
{
if (channel.ErrorCode == ErrorCode.FromNotFound)
continue;
return -1;
}
string strClassTableName = "class_" + strStyle;
XmlElement class_node = task_dom.CreateElement("class");
node.AppendChild(class_node);
class_node.SetAttribute("from_style", strStyle);
class_node.SetAttribute("class_table_name", strClassTableName);
class_node.SetAttribute("count", lRet.ToString());
}
#endif
}
}
// *** 创建日志表
if (strTypeList == "*"
|| StringUtil.IsInList("operlog", strTypeList) == true)
{
// return:
// -1 出错
// 0 没有找到
// 1 找到
nRet = GetFirstOperLogDate(
channel,
LogType.OperLog | LogType.AccessLog,
out string strFirstDate,
out strError);
if (nRet == -1)
{
strError = "获得第一个操作日志文件日期时出错: " + strError;
return -1;
}
// 获得日志文件中记录的总数
// parameters:
// strDate 日志文件的日期,8 字符
// return:
// -2 此类型的日志在 dp2library 端尚未启用
// -1 出错
// 0 日志文件不存在,或者记录数为 0
// >0 记录数
long lCount = OperLogLoader.GetOperLogCount(
null,
channel,
strEndDate,
LogType.OperLog,
out strError);
if (lCount < 0)
return -1;
task_dom.DocumentElement.SetAttribute("index", lCount.ToString());
if (nRet == 1)
{
// 记载第一个日志文件日期
task_dom.DocumentElement.SetAttribute(
"first_operlog_date",
strFirstDate);
/*
Program.MainForm.AppInfo.SetString(GetReportSection(),
"daily_report_end_date",
strFirstDate);
Program.MainForm.AppInfo.Save(); // 为防止程序中途崩溃丢失记忆,这里预先保存一下
*/
XmlElement node = task_dom.CreateElement("operlog");
task_dom.DocumentElement.AppendChild(node);
node.SetAttribute("start_date", strFirstDate); // "20060101"
node.SetAttribute("end_date", strEndDate + ":0-" + (lCount - 1).ToString());
}
}
// *** 创建访问日志表
if (strTypeList == "*"
|| StringUtil.IsInList("accesslog", strTypeList) == true)
{
// return:
// -1 出错
// 0 没有找到
// 1 找到
nRet = GetFirstOperLogDate(
channel,
LogType.AccessLog,
out string strFirstDate,
out strError);
if (nRet == -1)
{
strError = "获得第一个访问日志文件日期时出错: " + strError;
return -1;
}
// 获得日志文件中记录的总数
// parameters:
// strDate 日志文件的日期,8 字符
// return:
// -2 此类型的日志在 dp2library 端尚未启用
// -1 出错
// 0 日志文件不存在,或者记录数为 0
// >0 记录数
long lCount = OperLogLoader.GetOperLogCount(
null,
channel,
strEndDate,
LogType.AccessLog,
out strError);
if (lCount == -1)
return -1;
if (nRet == 1 && lCount >= 0)
{
// 记载第一个访问日志文件日期
task_dom.DocumentElement.SetAttribute(
"first_accesslog_date",
strFirstDate);
XmlElement node = task_dom.CreateElement("accesslog");
task_dom.DocumentElement.AppendChild(node);
node.SetAttribute("start_date", strFirstDate); // "20060101"
node.SetAttribute("end_date", strEndDate + ":0-" + (lCount - 1).ToString());
}
}
return 0;
}
// 获得第一个(实有的)日志文件日期
// return:
// -1 出错
// 0 没有找到
// 1 找到
int GetFirstOperLogDate(
LibraryChannel channel,
LogType logType,
out string strFirstDate,
out string strError)
{
strFirstDate = "";
strError = "";
DigitalPlatform.LibraryClient.localhost.OperLogInfo[] records = null;
List<string> dates = new List<string>();
List<string> styles = new List<string>();
if ((logType & LogType.OperLog) != 0)
styles.Add("getfilenames");
if ((logType & LogType.AccessLog) != 0)
styles.Add("getfilenames,accessLog");