-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathAppDatabase.cs
9979 lines (8725 loc) · 402 KB
/
AppDatabase.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.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Diagnostics;
using Ionic.Zip;
using DigitalPlatform.rms.Client;
using DigitalPlatform.Xml;
using DigitalPlatform.IO;
using DigitalPlatform.Text;
using DigitalPlatform.LibraryServer.Common;
using DigitalPlatform.rms.Client.rmsws_localhost;
using System.Xml.Linq;
namespace DigitalPlatform.LibraryServer
{
/// <summary>
/// 本部分是和数据库管理有关的代码
/// </summary>
public partial class LibraryApplication
{
// 管理数据库
// parameters:
// strLibraryCodeList 当前用户的管辖分馆代码列表
// strAction 动作。getinfo create delete change initialize backup refresh
// return:
// -1 出错
// 0 没有找到
// 1 成功
public int ManageDatabase(
SessionInfo sessioninfo,
RmsChannelCollection Channels,
string strLibraryCodeList,
string strAction,
string strDatabaseNames,
string strDatabaseInfo,
string strStyle,
out string strOutputInfo,
out string strError)
{
strOutputInfo = "";
strError = "";
// 列出数据库名
if (strAction == "getinfo")
{
return GetDatabaseInfo(
Channels,
strLibraryCodeList,
strDatabaseNames,
strStyle,
out strOutputInfo,
out strError);
}
// 创建数据库
if (strAction == "create")
{
return CreateDatabase(
sessioninfo,
Channels,
strLibraryCodeList,
// strDatabaseNames,
strDatabaseInfo,
false,
strStyle,
out strOutputInfo,
out strError);
}
// 重新创建数据库
if (strAction == "recreate")
{
return CreateDatabase(
sessioninfo,
Channels,
strLibraryCodeList,
// strDatabaseNames,
strDatabaseInfo,
true,
strStyle,
out strOutputInfo,
out strError);
}
// 删除数据库
if (strAction == "delete")
{
return DeleteDatabase(
sessioninfo,
Channels,
strLibraryCodeList,
strDatabaseNames,
strStyle,
out strOutputInfo,
out strError);
}
if (strAction == "initialize")
{
return InitializeDatabase(
sessioninfo,
Channels,
strLibraryCodeList,
strDatabaseNames,
strStyle,
out strOutputInfo,
out strError);
}
// 2008/11/16
if (strAction == "refresh")
{
return RefreshDatabaseDefs(
sessioninfo,
Channels,
strLibraryCodeList,
strDatabaseNames,
strDatabaseInfo,
strStyle,
out strOutputInfo,
out strError);
}
// 修改数据库
if (strAction == "change")
{
return ChangeDatabase(
sessioninfo,
Channels,
strLibraryCodeList,
strDatabaseNames,
strDatabaseInfo,
strStyle,
out strOutputInfo,
out strError);
}
strError = "未知的strAction值 '" + strAction + "'";
return -1;
}
// 获得一个数据库的全部配置文件
int GetConfigFiles(RmsChannel channel,
string strDbName,
string strLogFileName,
out string strError)
{
strError = "";
string strTempDir = "";
if (string.IsNullOrEmpty(strLogFileName) == false)
{
strTempDir = Path.Combine(this.TempDir, "~" + Guid.NewGuid().ToString());
// return:
// false 已经存在
// true 刚刚新创建
// exception:
// 可能会抛出异常 System.IO.DirectoryNotFoundException (未能找到路径“...”的一部分)
PathUtil.TryCreateDir(strTempDir);
}
try
{
DirLoader loader = new DirLoader(channel,
null,
strDbName + "/cfgs");
foreach (ResInfoItem item in loader)
{
string strTargetFilePath = Path.Combine(strTempDir, strDbName, "cfgs\\" + item.Name);
PathUtil.TryCreateDir(Path.GetDirectoryName(strTargetFilePath));
using (Stream exist_stream = File.Create(strTargetFilePath))
{
string strPath = strDbName + "/cfgs/" + item.Name;
string strStyle = "content,data,metadata,timestamp,outputpath";
byte[] timestamp = null;
string strOutputPath = "";
string strMetaData = "";
long lRet = channel.GetRes(
strPath, // item.Name,
exist_stream,
null, // stop,
strStyle,
null, // byte [] input_timestamp,
out strMetaData,
out timestamp,
out strOutputPath,
out strError);
if (lRet == -1)
{
// 配置文件不存在,怎么返回错误码的?
if (channel.IsNotFound())
continue;
return -1;
}
#if NO
exist_stream.Seek(0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader(exist_stream, Encoding.UTF8))
{
strExistContent = ConvertCrLf(sr.ReadToEnd());
}
#endif
}
}
if (string.IsNullOrEmpty(strTempDir) == false)
{
int nRet = CompressDirectory(
strTempDir,
strTempDir,
strLogFileName,
Encoding.UTF8,
true,
out strError);
if (nRet == -1)
return -1;
}
return 0;
}
finally
{
if (string.IsNullOrEmpty(strTempDir) == false)
PathUtil.DeleteDirectory(strTempDir);
}
}
// 如果数据库不存在会当作出错-1来报错
int InitializeDatabase(RmsChannel channel,
string strDbName,
string strLogFileName,
out string strError)
{
strError = "";
// 获得一个数据库的全部配置文件
if (string.IsNullOrEmpty(strLogFileName) == false)
{
int nRet = GetConfigFiles(channel,
strDbName,
strLogFileName,
out strError);
if (nRet == -1)
return -1;
}
// 初始化书目库
long lRet = channel.DoInitialDB(strDbName, out strError);
return (int)lRet;
}
// 删除一个数据库,并删除library.xml中相关OPAC检索库定义
// 如果数据库不存在会当作出错-1来报错
int DeleteDatabase(RmsChannel channel,
string strDbName,
string strLogFileName,
out string strError)
{
strError = "";
int nRet = 0;
// 获得一个数据库的全部配置文件
if (string.IsNullOrEmpty(strLogFileName) == false)
{
nRet = GetConfigFiles(channel,
strDbName,
strLogFileName,
out strError);
if (nRet == -1)
return -1;
}
long lRet = channel.DoDeleteDB(strDbName, out strError);
if (lRet == -1)
{
if (channel.IsNotFound() == false)
return -1;
}
// 删除一个数据库在OPAC可检索库中的定义
// return:
// -1 error
// 0 not change
// 1 changed
nRet = RemoveOpacDatabaseDef(
channel.Container,
strDbName,
out strError);
if (nRet == -1)
{
this.Changed = true;
return -1;
}
return 0;
}
#if NO
// 包装后的版本
int ChangeDbName(
RmsChannel channel,
string strOldDbName,
string strNewDbName,
out string strError)
{
return ChangeDbName(
channel,
strOldDbName,
strNewDbName,
() => { },
out strError);
}
#endif
// parameters:
// change_complte 数据名修改成功后的收尾工作
int ChangeDbName(
RmsChannel channel,
string strOldDbName,
string strNewDbName,
Action change_complete,
out string strError)
{
strError = "";
// TODO: 要对 strNewDbName 进行查重,看看是不是已经有同名的数据库存在了
// 另外 DoSetDBInfo() API 是否负责查重?
List<string[]> log_names = new List<string[]>();
string[] one = new string[2];
one[0] = strNewDbName;
one[1] = "zh";
log_names.Add(one);
// 修改数据库信息
// parameters:
// logicNames 逻辑库名。ArrayList。每个元素为一个string[2]类型。其中第一个字符串为名字,第二个为语言代码
// return:
// -1 出错
// 0 成功(基于WebService接口CreateDb的返回值)
long lRet = channel.DoSetDBInfo(
strOldDbName,
log_names,
null, // string strType,
null, // string strSqlDbName,
null, // string strKeysDef,
null, // string strBrowseDef,
out strError);
if (lRet == -1)
return -1;
// 数据名修改成功后的收尾工作
change_complete();
// 修改一个数据库在OPAC可检索库中的定义的名字
// return:
// -1 error
// 0 not change
// 1 changed
int nRet = RenameOpacDatabaseDef(
channel.Container,
strOldDbName,
strNewDbName,
out strError);
if (nRet == -1)
return -1;
return 0;
}
class ChangeInfo
{
public string OldDbName { get; set; }
public string NewDbName { get; set; }
public string DbType { get; set; }
public string ChangeStyle { get; set; }
}
// 修改数据库
// parameters:
// strStyle changeOut/changeIn 改出/改入数据库名字
// 改出的意思是,请求 dp2kernel 修改内核数据库名字,然后从 library.xml 清除这个数据库的痕迹。请求前,dp2kernel 中要检查源数据库名已经存在(并且 library.xml 中也有相应的配置元素内容),若目标数据库名已经存在,要先删除这个数据库
// 改入,则是请求 dp2kernel 修改内核数据库名字,然后在 library.xml 相关位置设置好这个新名字。请求前,dp2kernel 中的源数据库名应该存在;若目标数据库名已经存在,则要先删除这个数据库,确保改名可以成功
// return:
// -1 出错
// 0 没有找到
// 1 成功
int ChangeDatabase(
SessionInfo sessioninfo,
RmsChannelCollection Channels,
string strLibraryCodeList,
string strDatabaseNames,
string strDatabaseInfo,
string strStyle,
out string strOutputInfo,
out string strError)
{
strOutputInfo = "";
strError = "";
int nRet = 0;
// long lRet = 0;
bool bDbNameChanged = false;
XmlDocument dom = new XmlDocument();
try
{
dom.LoadXml(strDatabaseInfo);
}
catch (Exception ex)
{
strError = "strDatabaseInfo内容装入XMLDOM时出错: " + ex.Message;
return -1;
}
// 核对strDatabaseNames中包含的数据库名数目是否和dom中的<database>元素数相等
string[] names = strDatabaseNames.Split(new char[] { ',' });
XmlNodeList nodes = dom.DocumentElement.SelectNodes("database");
if (names.Length != nodes.Count)
{
strError = "strDatabaseNames 参数中包含的数据库名个数 " + names.Length.ToString() + " 和 strDatabaseInfo 参数中包含的 <database> 元素数 " + nodes.Count.ToString() + " 不等";
return -1;
}
List<XmlElement> database_nodes = new List<XmlElement>(); // 已经创建的数据库的定义节点
RmsChannel channel = Channels.GetChannel(this.WsUrl);
for (int i = 0; i < names.Length; i++)
{
string strName = names[i].Trim();
if (String.IsNullOrEmpty(strName) == true)
{
strError = "strDatabaseNames 参数中不能包含空的名字";
return -1;
}
// 来自strDatabaseInfo
XmlElement request_node = nodes[i] as XmlElement; // nodeNewDatabase
#region biblio
// 修改书目库名、或者书目库从属的其他数据库名
if (this.IsBiblioDbName(strName) == true)
{
// 获得相关配置小节
XmlNode nodeDatabase = this.LibraryCfgDom.DocumentElement.SelectSingleNode("itemdbgroup/database[@biblioDbName='" + strName + "']");
if (nodeDatabase == null)
{
strError = "配置DOM中名字为 '" + strName + "' 的书目库(biblioDbName属性)相关<database>元素没有找到";
return 0;
}
if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
{
strError = $"{GetCurrentUserName(sessioninfo)}不是全局用户,不允许修改书目库定义";
return -1;
}
// TODO: 如何描述修改细节信息?是每个下级库一套?还是要集中描述?
/*
* <database>元素中的name/entityDbName/orderDbName/issueDbName
* 传递了改名请求。如果属性值为空,不表明要删除数据库,而是该属性无效。
* 实际上这里不响应删除数据库的动作,只能改名
* 将来可以改造为响应删除数据库的请求,那么,只要属性具备,就有请求。如果不想请求,则不要包含那个属性
* */
{
// 书目库名
string strOldBiblioDbName = strName;
// 来自strDatabaseInfo
string strNewBiblioDbName = DomUtil.GetAttr(request_node,
"name");
// 如果strNewBiblioDbName为空,表示不想改变名字
if (String.IsNullOrEmpty(strNewBiblioDbName) == false
&& strOldBiblioDbName != strNewBiblioDbName)
{
if (String.IsNullOrEmpty(strOldBiblioDbName) == true
&& String.IsNullOrEmpty(strNewBiblioDbName) == false)
{
strError = "要创建书目库 '" + strNewBiblioDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldBiblioDbName,
strNewBiblioDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "biblioDbName", strNewBiblioDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "biblioDbName", strNewBiblioDbName);
this.Changed = true;
#endif
}
}
{
// 实体库名
string strOldEntityDbName = DomUtil.GetAttr(nodeDatabase,
"name");
// 来自strDatabaseInfo
string strNewEntityDbName = DomUtil.GetAttr(request_node,
"entityDbName");
if (String.IsNullOrEmpty(strNewEntityDbName) == false
&& strOldEntityDbName != strNewEntityDbName)
{
if (String.IsNullOrEmpty(strOldEntityDbName) == true
&& String.IsNullOrEmpty(strNewEntityDbName) == false)
{
strError = "要创建实体库 '" + strNewEntityDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldEntityDbName,
strNewEntityDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "name", strNewEntityDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "name", strNewEntityDbName);
this.Changed = true;
#endif
}
}
{
// 订购库名
string strOldOrderDbName = DomUtil.GetAttr(nodeDatabase,
"orderDbName");
// 来自strDatabaseInfo
string strNewOrderDbName = DomUtil.GetAttr(request_node,
"orderDbName");
if (String.IsNullOrEmpty(strNewOrderDbName) == false
&& strOldOrderDbName != strNewOrderDbName)
{
if (String.IsNullOrEmpty(strOldOrderDbName) == true
&& String.IsNullOrEmpty(strNewOrderDbName) == false)
{
strError = "要创建订购库 '" + strNewOrderDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldOrderDbName,
strNewOrderDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "orderDbName", strNewOrderDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "orderDbName", strNewOrderDbName);
this.Changed = true;
#endif
}
}
{
// 期库名
string strOldIssueDbName = DomUtil.GetAttr(nodeDatabase,
"issueDbName");
// 来自strDatabaseInfo
string strNewIssueDbName = DomUtil.GetAttr(request_node,
"issueDbName");
if (String.IsNullOrEmpty(strNewIssueDbName) == false
&& strOldIssueDbName != strNewIssueDbName)
{
if (String.IsNullOrEmpty(strOldIssueDbName) == true
&& String.IsNullOrEmpty(strNewIssueDbName) == false)
{
strError = "要创建期库 '" + strNewIssueDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldIssueDbName,
strNewIssueDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "issueDbName", strNewIssueDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "issueDbName", strNewIssueDbName);
this.Changed = true;
#endif
}
}
{
// 评注库名
string strOldCommentDbName = DomUtil.GetAttr(nodeDatabase,
"commentDbName");
// 来自strDatabaseInfo
string strNewCommentDbName = DomUtil.GetAttr(request_node,
"commentDbName");
if (String.IsNullOrEmpty(strNewCommentDbName) == false
&& strOldCommentDbName != strNewCommentDbName)
{
if (String.IsNullOrEmpty(strOldCommentDbName) == true
&& String.IsNullOrEmpty(strNewCommentDbName) == false)
{
strError = "要创建评注库 '" + strNewCommentDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldCommentDbName,
strNewCommentDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "commentDbName", strNewCommentDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "commentDbName", strNewCommentDbName);
this.Changed = true;
#endif
}
}
// 是否参与流通
if (DomUtil.HasAttr(request_node, "inCirculation") == true)
{
string strOldInCirculation = DomUtil.GetAttr(nodeDatabase,
"inCirculation");
if (String.IsNullOrEmpty(strOldInCirculation) == true)
strOldInCirculation = "true";
string strNewInCirculation = DomUtil.GetAttr(request_node,
"inCirculation");
if (String.IsNullOrEmpty(strNewInCirculation) == true)
strNewInCirculation = "true";
if (strOldInCirculation != strNewInCirculation)
{
DomUtil.SetAttr(nodeDatabase, "inCirculation",
strNewInCirculation);
this.Changed = true;
}
}
// 角色
// TODO: 是否要进行检查?
if (DomUtil.HasAttr(request_node, "role") == true)
{
string strOldRole = DomUtil.GetAttr(nodeDatabase,
"role");
string strNewRole = DomUtil.GetAttr(request_node,
"role");
if (strOldRole != strNewRole)
{
DomUtil.SetAttr(nodeDatabase, "role",
strNewRole);
this.Changed = true;
}
}
// 2012/4/30
// 联合编目特性
if (DomUtil.HasAttr(request_node, "unionCatalogStyle") == true)
{
string strOldUnionCatalogStyle = DomUtil.GetAttr(nodeDatabase,
"unionCatalogStyle");
string strNewUnionCatalogStyle = DomUtil.GetAttr(request_node,
"unionCatalogStyle");
if (strOldUnionCatalogStyle != strNewUnionCatalogStyle)
{
DomUtil.SetAttr(nodeDatabase, "unionCatalogStyle",
strNewUnionCatalogStyle);
this.Changed = true;
}
}
// 复制
if (DomUtil.HasAttr(request_node, "replication") == true)
{
string strOldReplication = DomUtil.GetAttr(nodeDatabase,
"replication");
string strNewReplication = DomUtil.GetAttr(request_node,
"replication");
if (strOldReplication != strNewReplication)
{
DomUtil.SetAttr(nodeDatabase, "replication",
strNewReplication);
this.Changed = true;
}
}
// <itemdbgroup>内容更新,刷新配套的内存结构
nRet = this.LoadItemDbGroupParam(this.LibraryCfgDom,
out strError);
if (nRet == -1)
{
this.WriteErrorLog(strError);
return -1;
}
this.Changed = true;
// request_node.SetAttribute("oldName", strName);
database_nodes.Add(request_node);
goto CONTINUE;
} // end of if 书目库名
#endregion
#region entity/order/issue/comment 单独的数据库
// 单独修改实体库名
// 能修改是否参与流通
if (this.IsItemDbName(strName) == true)
{
// 修改一个书目库下属数据库的名字
// 也会自动修改 library.xml 中相关元素
// parameters:
// strLibraryCodeList 当前用户所管辖的分馆代码列表
// bDbNameChanged 如果数据库发生了删除或者修改名字的情况,此参数会被设置为 true。否则其值不会发生改变
// return:
// -1 出错
// 0 指定的(源)数据库不存在
// 1 成功修改
nRet = ChangeBiblioChildDbName(
channel,
strLibraryCodeList,
strName,
request_node,
strStyle,
ref bDbNameChanged,
out strError);
if (nRet == -1)
goto ERROR1;
if (nRet == 0)
return 0;
#if NO
// 获得相关配置小节
XmlNode nodeDatabase = this.LibraryCfgDom.DocumentElement.SelectSingleNode("itemdbgroup/database[@name='" + strName + "']");
if (nodeDatabase == null)
{
strError = "配置DOM中名字为 '" + strName + "' 的实体库(name属性)相关<database>元素没有找到";
return 0;
}
if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
{
strError = "当前用户不是全局用户,不允许修改实体库定义";
return -1;
}
// 实体库名
string strOldEntityDbName = DomUtil.GetAttr(nodeDatabase,
"name");
// 来自strDatabaseInfo
string strNewEntityDbName = DomUtil.GetAttr(nodeNewDatabase,
"name");
if (strOldEntityDbName != strNewEntityDbName)
{
if (String.IsNullOrEmpty(strOldEntityDbName) == true
&& String.IsNullOrEmpty(strNewEntityDbName) == false)
{
strError = "要创建实体库 '" + strNewEntityDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
if (String.IsNullOrEmpty(strOldEntityDbName) == false
&& String.IsNullOrEmpty(strNewEntityDbName) == true)
{
strError = "要删除实体库 '" + strNewEntityDbName + "',请使用delete功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldEntityDbName,
strNewEntityDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "name", strNewEntityDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
}
// 是否参与流通
{
string strOldInCirculation = DomUtil.GetAttr(nodeDatabase,
"inCirculation");
if (String.IsNullOrEmpty(strOldInCirculation) == true)
strOldInCirculation = "true";
string strNewInCirculation = DomUtil.GetAttr(nodeNewDatabase,
"inCirculation");
if (String.IsNullOrEmpty(strNewInCirculation) == true)
strNewInCirculation = "true";
if (strOldInCirculation != strNewInCirculation)
{
DomUtil.SetAttr(nodeDatabase, "inCirculation",
strNewInCirculation);
this.Changed = true;
}
}
// <itemdbgroup>内容更新,刷新配套的内存结构
nRet = this.LoadItemDbGroupParam(this.LibraryCfgDom,
out strError);
if (nRet == -1)
{
this.WriteErrorLog(strError);
return -1;
}
this.Changed = true;
#endif
database_nodes.Add(request_node);
goto CONTINUE;
}
#endregion
#if NO
#region order
// 单独修改订购库名
if (this.IsOrderDbName(strName) == true)
{
// 获得相关配置小节
XmlNode nodeDatabase = this.LibraryCfgDom.DocumentElement.SelectSingleNode("itemdbgroup/database[@orderDbName='" + strName + "']");
if (nodeDatabase == null)
{
strError = "配置DOM中名字为 '" + strName + "' 的订购库(orderDbName属性)相关<database>元素没有找到";
return 0;
}
if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
{
strError = "当前用户不是全局用户,不允许修改订购库定义";
return -1;
}
// 来自LibraryCfgDom
string strOldOrderDbName = DomUtil.GetAttr(nodeDatabase,
"orderDbName");
// 来自strDatabaseInfo
string strNewOrderDbName = DomUtil.GetAttr(nodeNewDatabase,
"name");
if (strOldOrderDbName != strNewOrderDbName)
{
if (String.IsNullOrEmpty(strOldOrderDbName) == true
&& String.IsNullOrEmpty(strNewOrderDbName) == false)
{
strError = "要创建订购库 '" + strNewOrderDbName + "',请使用create功能,而不能使用change功能";
goto ERROR1;
}
if (String.IsNullOrEmpty(strOldOrderDbName) == false
&& String.IsNullOrEmpty(strNewOrderDbName) == true)
{
strError = "要删除订购库 '" + strNewOrderDbName + "',请使用delete功能,而不能使用change功能";
goto ERROR1;
}
nRet = ChangeDbName(
channel,
strOldOrderDbName,
strNewOrderDbName,
() =>
{
DomUtil.SetAttr(nodeDatabase, "orderDbName", strNewOrderDbName);
bDbNameChanged = true;
this.Changed = true;
},
out strError);
if (nRet == -1)
goto ERROR1;
#if NO
bDbNameChanged = true;
DomUtil.SetAttr(nodeDatabase, "orderDbName", strNewOrderDbName);
this.Changed = true;
#endif
}
// <itemdbgroup>内容更新,刷新配套的内存结构
nRet = this.LoadItemDbGroupParam(this.LibraryCfgDom,
out strError);
if (nRet == -1)
{
this.WriteErrorLog(strError);
return -1;
}
this.Changed = true;
continue;
}
#endregion
#region issue
// 单独修改期库名
if (this.IsIssueDbName(strName) == true)
{
// 获得相关配置小节
XmlNode nodeDatabase = this.LibraryCfgDom.DocumentElement.SelectSingleNode("itemdbgroup/database[@issueDbName='" + strName + "']");
if (nodeDatabase == null)
{
strError = "配置DOM中名字为 '" + strName + "' 的期库(issueDbName属性)相关<database>元素没有找到";
return 0;
}
if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
{
strError = "当前用户不是全局用户,不允许修改期库定义";
return -1;
}
// 来自LibraryCfgDom
string strOldIssueDbName = DomUtil.GetAttr(nodeDatabase,
"issueDbName");
// 来自strDatabaseInfo
string strNewIssueDbName = DomUtil.GetAttr(nodeNewDatabase,
"name"); // 2012/4/30 changed
if (strOldIssueDbName != strNewIssueDbName)
{
if (String.IsNullOrEmpty(strOldIssueDbName) == true
&& String.IsNullOrEmpty(strNewIssueDbName) == false)