Skip to content

Commit d064218

Browse files
committed
Added Some Method And Doc
1 parent 5d93912 commit d064218

File tree

5 files changed

+199
-9
lines changed

5 files changed

+199
-9
lines changed

MessageParser.NET/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.1")]
36-
[assembly: AssemblyFileVersion("1.0.0.1")]
35+
[assembly: AssemblyVersion("1.0.0.3")]
36+
[assembly: AssemblyFileVersion("1.0.0.3")]

MessageParser.NET/Tools/ExcelParser.cs

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MessageParser.NET.Tools
55
public class ExcelParser
66
{
77
private System.IO.FileInfo ExcelFile;
8-
private ExcelPackage excel;
8+
public ExcelPackage excel;
99
public ExcelParser(string excelPath)
1010
{
1111
ExcelFile = new System.IO.FileInfo(excelPath);
@@ -17,33 +17,64 @@ public ExcelParser(byte[] buf)
1717
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
1818
excel = new ExcelPackage(ms);
1919
}
20+
21+
/// <summary>
22+
/// Get All Sheets
23+
/// </summary>
24+
/// <returns></returns>
2025
public ExcelWorksheets GetWorksheets()
2126
{
2227
return excel.Workbook.Worksheets;
2328
}
2429

30+
/// <summary>
31+
/// Get Count Of Rows For Specified Sheet
32+
/// </summary>
33+
/// <param name="worksheetIndex">Index Of Sheet</param>
34+
/// <returns></returns>
2535
public int GetWorksheetRowCount(int worksheetIndex)
2636
{
2737
ExcelWorksheet worksheet = excel.Workbook.Worksheets[worksheetIndex];
2838
return worksheet.Dimension.End.Row;
2939
}
40+
41+
/// <summary>
42+
/// Get Count Of Columns For Specified Sheet
43+
/// </summary>
44+
/// <param name="worksheetIndex">Index Of Sheet</param>
45+
/// <returns></returns>
3046
public int GetWorksheetColumnCount(int worksheetIndex)
3147
{
3248
ExcelWorksheet worksheet = excel.Workbook.Worksheets[worksheetIndex];
3349
return worksheet.Dimension.End.Column;
3450
}
3551

52+
/// <summary>
53+
/// Assign Specified Sheet
54+
/// </summary>
55+
/// <param name="worksheetIndex">Index Of Sheet</param>
56+
/// <returns></returns>
3657
public ExcelWorksheet GetWorksheet(int worksheetIndex)
3758
{
3859
return excel.Workbook.Worksheets[worksheetIndex];
3960
}
4061

62+
/// <summary>
63+
/// Create New Sheet In Current WorkBook
64+
/// </summary>
65+
/// <param name="name">Sheet Name</param>
66+
/// <returns></returns>
4167
public ExcelWorksheet CreateNewSheet(string name)
4268
{
4369
var sheet = excel.Workbook.Worksheets.Add(name);
4470
return sheet;
4571
}
4672

73+
/// <summary>
74+
///
75+
/// </summary>
76+
/// <param name="workSheet">Index Of Sheet</param>
77+
/// <param name="columnName">Column Name</param>
4778
public void AddColumn(ExcelWorksheet workSheet, string columnName)
4879
{
4980
int columnLengh = 0;
@@ -56,6 +87,11 @@ public void AddColumn(ExcelWorksheet workSheet, string columnName)
5687
// excel.Save();
5788
}
5889

90+
/// <summary>
91+
/// Add Columns Array To Specified Sheet
92+
/// </summary>
93+
/// <param name="workSheet">Index Of Sheet</param>
94+
/// <param name="columnsNames">Columns Name</param>
5995
public void AddRangeColumn(ExcelWorksheet workSheet, string[] columnsNames)
6096
{
6197
int columnLengh = 0;
@@ -70,6 +106,42 @@ public void AddRangeColumn(ExcelWorksheet workSheet, string[] columnsNames)
70106
// excel.Save();
71107
}
72108

109+
/// <summary>
110+
/// Add Rows Array To Specified Column
111+
/// </summary>
112+
/// <param name="workSheet">Index Of Sheet</param>
113+
/// <param name="columnName">Column Name</param>
114+
/// <param name="rows">Rows Value</param>
115+
public void AddRangeRows(ExcelWorksheet workSheet, string columnName, string[] rows)
116+
{
117+
int columnLengh = 0;
118+
int rowsLengh = 0;
119+
if (workSheet.Dimension != null)
120+
{
121+
columnLengh = workSheet.Dimension.End.Column;
122+
rowsLengh = workSheet.Dimension.End.Row;
123+
}
124+
else
125+
return;
126+
127+
128+
int colIndex = ColumnIndex(workSheet, columnName);
129+
130+
for (int i = 0; i < rows.Length; i++)
131+
{
132+
columnLengh++;
133+
workSheet.Cells[rowsLengh + i + 1, colIndex].Value = rows[i];
134+
}
135+
136+
// excel.Save();
137+
}
138+
139+
/// <summary>
140+
/// Add Value To Specified Column
141+
/// </summary>
142+
/// <param name="worksheet">Index Of Sheet</param>
143+
/// <param name="column">Column Index</param>
144+
/// <param name="value"></param>
73145
public void AddData(ExcelWorksheet worksheet, int column, string value)
74146
{
75147
int rowLengh = 0;
@@ -82,6 +154,12 @@ public void AddData(ExcelWorksheet worksheet, int column, string value)
82154
worksheet.Cells[rowLengh, column].Value = value;
83155
}
84156

157+
/// <summary>
158+
/// Add Value To Specified Column
159+
/// </summary>
160+
/// <param name="worksheet">Index Of Sheet</param>
161+
/// <param name="columnName">Column Name</param>
162+
/// <param name="value"></param>
85163
public void AddData(ExcelWorksheet worksheet, string columnName, string value)
86164
{
87165
int column = 1;
@@ -92,18 +170,34 @@ public void AddData(ExcelWorksheet worksheet, string columnName, string value)
92170
rowLengh = worksheet.Dimension.End.Row;
93171
var columnLengh = worksheet.Dimension.End.Column;
94172

173+
column = ColumnIndex(worksheet, columnName);
174+
}
175+
176+
rowLengh++;
177+
worksheet.Cells[rowLengh, column].Value = value;
178+
}
179+
180+
/// <summary>
181+
/// Get Column Index With Name
182+
/// </summary>
183+
/// <param name="worksheet">Index Of Sheet</param>
184+
/// <param name="columnName">Column Name</param>
185+
/// <returns></returns>
186+
public int ColumnIndex(ExcelWorksheet worksheet, string columnName)
187+
{
188+
if (worksheet.Dimension != null)
189+
{
190+
var columnLengh = worksheet.Dimension.End.Column;
191+
95192
for (int i = 1; i <= columnLengh; i++)
96193
{
97194
if (((string)worksheet.Cells[1, i].Value) == columnName)
98195
{
99-
column = i;
100-
break;
196+
return i;
101197
}
102198
}
103199
}
104-
105-
rowLengh++;
106-
worksheet.Cells[rowLengh, column].Value = value;
200+
return -1;
107201
}
108202

109203
public void Save()

MessageParser.NET/Tools/ISO8583.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ public ISO8583()
350350
DEFixLen[98] = -25; DEFixLen[101] = -17; DEFixLen[128] = -16;
351351

352352
}
353+
354+
/// <summary>
355+
/// Build Iso8583 Message
356+
/// </summary>
357+
/// <param name="DE">Elements Array</param>
358+
/// <param name="MTI">MTI Code</param>
359+
/// <returns>Iso8583 Message</returns>
353360
public string Build(string[] DE, string MTI)
354361
{
355362
string newISO = MTI;
@@ -414,6 +421,12 @@ public string Build(string[] DE, string MTI)
414421

415422

416423
}
424+
425+
/// <summary>
426+
/// Parse Iso8583
427+
/// </summary>
428+
/// <param name="ISOmsg">Iso8583 Message</param>
429+
/// <returns>Elements Array</returns>
417430
public string[] Parse(string ISOmsg)
418431
{
419432
string[] DE = new string[130];

MessageParser.NET/Tools/JsonTools.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ namespace MessageParser.NET.Tools
99
{
1010
public class JsonTools
1111
{
12+
/// <summary>
13+
/// Deserialize Json To Specified Object
14+
/// </summary>
15+
/// <typeparam name="T">Object Type</typeparam>
16+
/// <param name="json">Json Message</param>
17+
/// <returns>Json Message</returns>
1218
public static T Deserialize<T>(string json)
1319
{
1420
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(json)))
@@ -18,6 +24,12 @@ public static T Deserialize<T>(string json)
1824
}
1925
}
2026

27+
/// <summary>
28+
/// Serialize Specified Object To Json
29+
/// </summary>
30+
/// <typeparam name="T">Object Tyoe</typeparam>
31+
/// <param name="obj">Object</param>
32+
/// <returns>Json Message</returns>
2133
public static string Serialize<T>(T obj)
2234
{
2335
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());

MessageParser.NET/Tools/XmlParser.cs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ namespace MessageParser.NET.Tools
66
{
77
public class XmlParser
88
{
9+
/// <summary>
10+
/// Get Specified Attribute Value
11+
/// </summary>
12+
/// <param name="xmlString">Xml Text</param>
13+
/// <param name="element">Element Name</param>
14+
/// <param name="attribute">Attribute Name</param>
15+
/// <returns></returns>
916
public string GetAttributeValue(string xmlString, string element, string attribute)
1017
{
1118
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString)))
@@ -16,6 +23,12 @@ public string GetAttributeValue(string xmlString, string element, string attribu
1623
}
1724
}
1825

26+
/// <summary>
27+
/// Get Specified Element Content
28+
/// </summary>
29+
/// <param name="xmlString">Xml Text</param>
30+
/// <param name="element">Element Name</param>
31+
/// <returns></returns>
1932
public string GetElementContent(string xmlString, string element)
2033
{
2134
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString)))
@@ -25,6 +38,11 @@ public string GetElementContent(string xmlString, string element)
2538
}
2639
}
2740

41+
/// <summary>
42+
/// Get All Elements In Xml Text
43+
/// </summary>
44+
/// <param name="xmlString">Xml Text</param>
45+
/// <returns></returns>
2846
public string[] GetAllElements(string xmlString)
2947
{
3048
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString)))
@@ -40,6 +58,12 @@ public string[] GetAllElements(string xmlString)
4058
return output.ToArray();
4159
}
4260
}
61+
62+
/// <summary>
63+
/// Get All Text In Xml Text
64+
/// </summary>
65+
/// <param name="xmlString">Xml Text</param>
66+
/// <returns></returns>
4367
public string[] GetAllText(string xmlString)
4468
{
4569
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString)))
@@ -67,6 +91,15 @@ public string[] GetAllText(string xmlString)
6791
// }
6892
//}
6993

94+
/// <summary>
95+
/// Set Attribute Value In A Node With The Specified Parent
96+
/// </summary>
97+
/// <param name="xmlString">Xml Text</param>
98+
/// <param name="parent">Parent Name</param>
99+
/// <param name="element">Element Name</param>
100+
/// <param name="attributeName">Attribute Name</param>
101+
/// <param name="value">Attribute Value</param>
102+
/// <returns></returns>
70103
public string SetAttribute(string xmlString, string parent, string element, string attributeName, string value)
71104
{
72105
using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(xmlString)))
@@ -97,6 +130,16 @@ public string SetAttribute(string xmlString, string parent, string element, stri
97130
}
98131
}
99132

133+
/// <summary>
134+
/// Set Attribute Value In A Node
135+
/// </summary>
136+
/// <param name="xmlString">Xml Text</param>
137+
/// <param name="element">Element Name</param>
138+
/// <param name="attributeName">Attribute Name</param>
139+
/// <param name="value">Attribute Value</param>
140+
/// <param name="allElements">Wethere Set ALL Attribute Value With Specified Name Or Only First Attribute
141+
/// :True Set All Attribute Value With Specified Name In Xml Text. :False Set Only First Attribute With Specified Name In Xml Text</param>
142+
/// <returns></returns>
100143
public string SetAttribute(string xmlString, string element, string attributeName, string value, bool allElements)
101144
{
102145
StringBuilder output = new StringBuilder();
@@ -154,6 +197,17 @@ public string SetAttribute(string xmlString, string element, string attributeNam
154197
return output.ToString();
155198
}
156199

200+
/// <summary>
201+
/// Set Attribute Value In A Node
202+
/// </summary>
203+
/// <param name="xmlString">Xml Text</param>
204+
/// <param name="element">Element Name</param>
205+
/// <param name="attributeName">Attribute Name</param>
206+
/// <param name="value">Attribute Value</param>
207+
/// <param name="allElements">Wethere Set ALL Attribute Value With Specified Name Or Only First Attribute
208+
/// True Set All Attribute Value With Specified Name In Xml Text.
209+
/// False Set Only First Attribute With Specified Name In Xml Text</param>
210+
/// <returns></returns>
157211
public string SetAttribute(XmlReader reader, string element, string attributeName, string value, bool allElements)
158212
{
159213
StringBuilder output = new StringBuilder();
@@ -210,6 +264,12 @@ public string SetAttribute(XmlReader reader, string element, string attributeNam
210264
return output.ToString();
211265
}
212266

267+
/// <summary>
268+
/// Check Wethere Exsist This Attribute Name In Xml Text.
269+
/// </summary>
270+
/// <param name="reader"></param>
271+
/// <param name="attributeName"></param>
272+
/// <returns></returns>
213273
public bool ISExsistAttribute(XmlReader reader, string attributeName)
214274
{
215275
if (reader.HasAttributes)
@@ -224,7 +284,13 @@ public bool ISExsistAttribute(XmlReader reader, string attributeName)
224284
return false;
225285
}
226286

227-
287+
/// <summary>
288+
/// Update Specified Attribute Value
289+
/// </summary>
290+
/// <param name="reader"></param>
291+
/// <param name="writer"></param>
292+
/// <param name="attributeName"></param>
293+
/// <param name="value"></param>
228294
public void UpdateAttribute(XmlReader reader, XmlWriter writer, string attributeName, string value)
229295
{
230296
bool flag = false;
@@ -247,6 +313,11 @@ public void UpdateAttribute(XmlReader reader, XmlWriter writer, string attribute
247313
writer.WriteAttributeString(null, attributeName, null, value);
248314
}
249315

316+
/// <summary>
317+
/// Get SubTree
318+
/// </summary>
319+
/// <param name="xmlString"></param>
320+
/// <returns></returns>
250321
public string xmlSubTree(string xmlString)
251322
{
252323
StringBuilder output = new StringBuilder();

0 commit comments

Comments
 (0)