-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
251 lines (202 loc) · 8.84 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using MarcNet;
using System.Text.RegularExpressions;
namespace testMarc01
{
class Program
{
static ArrayList update856(ArrayList oldRec, ArrayList newRec)
{
ArrayList retUpdate856 = new ArrayList();
ArrayList retUpdate8561 = new ArrayList();
int UrlField = 0;
int AllField = 0;
int ZField = 0;
int pos = 0;
for (int j = 0; j < newRec.Count; j++)
{
retUpdate856.Add(newRec[j]);
}
for(int j = 0; j < oldRec.Count; j++)
{
MARCField oldField = (MARCField)oldRec[j];
string old3field = oldField.getSubField("3");
if (old3field == null)
{
retUpdate856.Add(oldRec[j]);
}
}
int Count = oldRec.Count + newRec.Count;
for(int i=0; i<oldRec.Count; i++)
{
MARCField oldField = (MARCField)oldRec[i];
string oldUfield = oldField.getSubField("u");
string oldZfield = oldField.getSubField("z");
for (int j = 0; j < newRec.Count; j++)
{
MARCField newField = (MARCField)newRec[j];
string newUfield = newField.getSubField("u");
string newZfield = newField.getSubField("z");
// compare $u field
if (newUfield.CompareTo(oldUfield) == 0)
{
// compare $z field
if (newZfield.CompareTo(oldZfield) == 0)
{
retUpdate856.Remove(oldField);
AllField++;
}
else
{
retUpdate856.Remove(oldField);
UrlField++;
}
}
else
{
if (newZfield.CompareTo(oldZfield) == 0)
{
retUpdate856.Remove(oldField);
ZField++;
}
}
}
}
return retUpdate856;
}
static string compare(ArrayList oldRec, ArrayList newRec)
{
StringBuilder str = new StringBuilder();
int UrlField = 0;
int AllField = 0;
int ZField = 0;
for (int i = 0; i < oldRec.Count; i++)
{
MARCField oldField = (MARCField)oldRec[i];
string oldUfield = oldField.getSubField("u");
string oldZfield = oldField.getSubField("z");
for (int j = 0; j < newRec.Count; j++)
{
MARCField newField = (MARCField)newRec[j];
string newUfield = newField.getSubField("u");
string newZfield = newField.getSubField("z");
if (newUfield.CompareTo(oldUfield) == 0)
{
//str.Append("old:" + (i + 1).ToString() + "<-> new:" + (j + 1).ToString() + "==> $u ");
if (newZfield.CompareTo(oldZfield) == 0)
{
//str.Append("old:" + (i + 1).ToString() + "<-> new:" + (j + 1).ToString() + "==> $z");
AllField++;
}
else
{
UrlField++;
}
}
else
{
if (newZfield.CompareTo(oldZfield) == 0)
{
//str.Append("old:" + (i + 1).ToString() + "<-> new:" + (j + 1).ToString() + "==> $z");
ZField++;
}
}
}
}
str.Append("$u field," + UrlField.ToString());
str.Append(",All," + AllField.ToString());
str.Append(",$z field," + ZField.ToString());
str.Append(",Diff," + (oldRec.Count - newRec.Count).ToString());
str.Append("\r\n");
return str.ToString();
}
static void Main(string[] args)
{
BatchCat.UpdateBibReturnCode retCode;
Hashtable fromEBZ = new Hashtable();
string filename1 = "n:\\495833.bib";
Voyager.myEbzRecords myEbzRecs = new Voyager.myEbzRecords(filename1, 0);
ArrayList ebzlist = myEbzRecs.ebzList;
Voyager.MyVoyagerRecords myVoyRec = new Voyager.MyVoyagerRecords();
StringBuilder myResultStr = new StringBuilder();
for (int i = 0; i < ebzlist.Count; i++)
{
retCode = BatchCat.UpdateBibReturnCode.ubUnknownError;
Console.WriteLine("{0} -- {1}", i, ebzlist[i].ToString());
myVoyRec.setVoyagerRecord(ebzlist[i].ToString());
ArrayList voy856old = myVoyRec.retrieveOld856();
ArrayList ebz856_1 = myEbzRecs.getEbz856(ebzlist[i].ToString());
ArrayList ebz856New = myEbzRecs.generateNew856(ebz856_1);
string compareResult = compare(voy856old, ebz856New);
ArrayList ebz856Update = update856(voy856old, ebz856New);
myResultStr.Append("\r\n================== "+ (i+1).ToString());
myResultStr.Append("\t");
myResultStr.Append(myVoyRec.BibID.ToString()+"\t");
myResultStr.Append("\t");
myResultStr.Append("From inukshuk: \t");
myResultStr.Append(ebzlist[i].ToString()+"\t");
myResultStr.Append(voy856old.Count.ToString());
myResultStr.Append("\t");
myResultStr.Append(ebz856New.Count.ToString());
myResultStr.Append("\r\n");
myResultStr.Append(compareResult);
for(int j = 0; j < voy856old.Count; j ++)
{
MarcNet.MARCField tempMarcField = (MarcNet.MARCField)voy856old[j];
myResultStr.Append( (j+1).ToString() + " :"+ tempMarcField.asFormatted() );
myResultStr.Append( "\r\n");
}
myResultStr.Append("From Ebsco: \r\n");
for (int j = 0; j < ebz856New.Count; j++)
{
MarcNet.MARCField tempMarcField = (MarcNet.MARCField)ebz856New[j];
myResultStr.Append((j + 1).ToString() + " :" + tempMarcField.asFormatted());
myResultStr.Append("\r\n");
}
myResultStr.Append("\r\n");
myResultStr.Append("From Jason: \r\n");
for (int j = 0; j < ebz856Update.Count; j++)
{
MarcNet.MARCField tempMarcField = (MarcNet.MARCField)ebz856Update[j];
myResultStr.Append((j + 1).ToString() + " :" + tempMarcField.asFormatted());
myResultStr.Append("\r\n");
}
myResultStr.Append("\r\n");
//DBConnected first, get bib record, then update
if (myVoyRec.DbConnected)
{
if (voy856old.Count > 0)
{
retCode = myVoyRec.update856(ebz856Update);
}
}
else
{
if (myVoyRec.DbConnect())
{
if (voy856old.Count > 0)
{
retCode = myVoyRec.update856(ebz856Update);
}
}
}
myResultStr.Append("Update: " + retCode.ToString() + "\t\r\n");
//fromEBZ.Add(ebzlist[i].ToString(), ebz856New);
}
string f1 = "c:\\New.mrc";
FileStream fs1;
fs1 = new FileStream(f1, FileMode.Create, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.Write(myResultStr);
sw1.Close();
fs1.Close();
}
void getBibRecord(long bib_ID)
{
}
}
}