-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJARVISFileProcessing.cs
More file actions
163 lines (146 loc) · 6.07 KB
/
Copy pathJARVISFileProcessing.cs
File metadata and controls
163 lines (146 loc) · 6.07 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Cryptography;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Access;
using System.Runtime;
namespace JARVIS4
{
/// <summary>
/// This class is purely for reading of massive text files
/// </summary>
public static class JARVISFileProcessing
{
private static string FileDirectory = @"C:\JARVIS4\UserDefinedFiles";
public static bool read_large_text_file(string file_path)
{
try
{
FileStream target_file = File.Open(file_path, FileMode.Open, FileAccess.Read, FileShare.Read);
BufferedStream target_file_buffered = new BufferedStream(target_file);
StreamReader target_file_buffered_stream = new StreamReader(target_file_buffered);
string line;
while ((line = target_file_buffered_stream.ReadLine()) != null)
{
// Do some logic here
Console.WriteLine(line);
}
return true;
}
catch (Exception e)
{
return false;
}
}
public static bool read_large_text_file(string file_path, params Func<string, bool>[] function_array)
{
try
{
FileStream target_file = File.Open(file_path, FileMode.Open, FileAccess.Read, FileShare.Read);
BufferedStream target_file_buffered = new BufferedStream(target_file);
StreamReader target_file_buffered_stream = new StreamReader(target_file_buffered);
string line;
while ((line = target_file_buffered_stream.ReadLine()) != null)
{
// Do some logic here
foreach (Func<string, bool> function in function_array)
{
function(line);
}
}
return true;
}
catch (Exception e)
{
return false;
}
}
public static bool ReadExcelFile(string file_path)
{
try
{
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}
public static StatusObject WriteExcelFile()
{
StatusObject SO = new StatusObject();
try
{
Microsoft.Office.Interop.Excel.Application oXL;
Microsoft.Office.Interop.Excel._Workbook oWB;
Microsoft.Office.Interop.Excel._Worksheet oSheet;
Microsoft.Office.Interop.Excel.Range oRng;
object misvalue = System.Reflection.Missing.Value;
//Start Excel and get Application object.
oXL = new Microsoft.Office.Interop.Excel.Application();
oXL.Visible = false;
oXL.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
//Get a new workbook.
oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(""));
oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;
//Add table headers going cell by cell.
oSheet.Cells[1, 1] = "First Name";
oSheet.Cells[1, 2] = "Last Name";
oSheet.Cells[1, 3] = "Full Name";
oSheet.Cells[1, 4] = "Salary";
//Format A1:D1 as bold, vertical alignment = center.
/*oSheet.get_Range("A1", "D1").Font.Bold = true;
oSheet.get_Range("A1", "D1").VerticalAlignment =
Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
// Create an array to multiple values at once.
string[,] saNames = new string[5, 2];
saNames[0, 0] = "John";
saNames[0, 1] = "Smith";
saNames[1, 0] = "Tom";
saNames[4, 1] = "Johnson";
//Fill A2:B6 with an array of values (First and Last Names).
oSheet.get_Range("A2", "B6").Value2 = saNames;
//Fill C2:C6 with a relative formula (=A2 & " " & B2).
oRng = oSheet.get_Range("C2", "C6");
oRng.Formula = "=A2 & \" \" & B2";
//Fill D2:D6 with a formula(=RAND()*100000) and apply format.
oRng = oSheet.get_Range("D2", "D6");
oRng.Formula = "=RAND()*100000";
oRng.NumberFormat = "$0.00";
//AutoFit columns A:D.
oRng = oSheet.get_Range("A1", "D1");
oRng.EntireColumn.AutoFit();*/
oXL.Visible = false;
oXL.UserControl = false;
Directory.CreateDirectory(FileDirectory);
oWB.SaveAs(String.Format(@"{0}\{1}.xlsx",FileDirectory,"hello"), Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing,
false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
oWB.Close();
}
catch(Exception e)
{
SO = new StatusObject(e.Message, "WriteToExcel", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
public static StatusObject CompareFileHashes(string OriginalText, string NewText)
{
StatusObject SO = new StatusObject();
try
{
MD5 hashGenerator = MD5.Create();
}
catch(Exception e)
{
SO = new StatusObject(e.Message, "FILEHASHMISMATCH", StatusObject.StatusCode.FAILURE, e.ToString());
}
return SO;
}
}
}