Subversion Repository Public Repository

ChrisCompleteCodeTrunk

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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.OleDb;
using DocuWare.Platform.ServerClient;

namespace PremierMigration
{
    public class Program
    {
        public static Dictionary<string, string> TableCabinetMatch { get; set; }

        /*
public static Dictionary<string, string> TableCabinetMatch = new Dictionary<string, string>()
{
{"ACCIDENT", "Accident"},
{"ACCOUNTI", "Accounting"},
{"ACCOUNTS", "Accounts Payable"},
{"AR", "AR"},
{"AR_PAY", "ARPAY"},
{"BROKERCO", "BROKERCONTRACTS"},
{"CARGO", "CARGOCLAIMS"},
{"CHTEXPT", "CHTEXPT"},
{"CHTMAN", "CHTQCMMANIFESTS"},
{"CHTOUT", "CHTQCMOUT"},
{"CHTQCM", "CHTQCM"},
{"CONTRACT", "CONTRACTS"},
{"CORPORAT", "CORPORATE"},
{"CORRESPO", "CORRESPONDENCE"},
{"DRIVEQUA", "DRIVEQUAL"},
{"EV_AR", "EV ACCT REC"},
{"EV_PR", "EVPAYROLL"},
{"EV_SAFE", "EV_SAFETY"},
{"EVACCT", "EVANSVILLE ACCT RECEIVABLE"},
{"EXEC_DOC", "EXEC_DOCS"},
{"HR", "HR"},
{"HRINS", "HRINS"},
{"I9", "I9"},
{"MAIN_WO", "MAIN_WO"},
{"MAINT", "MAINT"},
{"MEDICALR", "MEDICAL RECORDS"},
{"MIS_VEND", "MIS_VENDORS"},
{"OO_TERM", "OWNEROPERATOR_TERM"},
{"OSD", "OSD"},
{"OUTBOUND", "OUTBOUNDQCM"},
{"PAYROLL", "PAYROLL"},
{"PNI", "PNI"},
{"PROGTRUC", "PROGTRUCK"},
{"PRTAXES", "PRTAXES"},
{"QCMMAN", "QCMMANIFESTS"},
{"QCMOUT", "QCMOUTBOUND"},
{"RESUMES", "RESUMES"},
{"SAFETY", "SAFETY"},
{"SHIPDOCS", "SHIPPING"},
{"TARIFF", "TARIFF ITEM"},
{"TARRIFFS", "TARRIFFS"},
{"TARRIFIT", "TARRIFITEMS"},
{"TEST", "TEST"},
{"TRAINING", "TRAINING"},
{"TRUCKS", "TRUCKS"},
{"TWIC", "TWIC"},
{"UPCOUNT", "UPCONTAINERS"},
{"UPLTL", "UPLTL" },
{"UPQCM", "UPQCM"},
{"VENDCERT", "VENDOR INS CERTS"},
{"VIR", "VIR"},
{"WKMNCOMP", "WORKMANS COMP"},
{"YARDAPPS", "YARDAPPS"}
};
*/

        static void Main(string[] args)
        {
            LoadTableMappings();
            CommandLineParams commandLineParams = new CommandLineParams();
            CommandLine.Parser.Default.ParseArgumentsStrict(args, commandLineParams);
            DirectoryInfo diImageRootPath = null;
            DirectoryInfo diExportPath = null;
            try
            {
                diImageRootPath = new DirectoryInfo(commandLineParams.ImagePathRoot);
                diExportPath = new DirectoryInfo(commandLineParams.ExportPath);
            }
            catch
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("The path specificed in the -p argument does not exist. Please specify the correct image root path.");
                Console.WriteLine("--- or ---");
                Console.WriteLine("The path specified in the -e argument does not exist and/or could not be created. Please specify the correct path or make sure you have sufficient privileges to create a directory.");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                return;
            }
            if (!diImageRootPath.Exists)
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("The path specificed in the -p argument : \"" + diImageRootPath.FullName + "\"\n\nDoes not exist. Please specify the correct image root path.");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                return;
            }
            if (!diExportPath.Exists)
            {
                try
                {
                    diExportPath.Create();
                }
                catch
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("The path specified in the -e argument : \"" + diExportPath.FullName + "\"\n\nDoes not exist and/or could not be created. Please specify the correct path or make sure you have sufficient privileges to create a directory.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    return;
                }
            }

            if (diImageRootPath.Exists && diExportPath.Exists)
            {
                if (!IsSqlConnectionValid())
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unable to connect to the SQL server, please check your app.config for the correct values.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    return;
                }
                if (!IsDocuwareServiceConnectionValid())
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unable to connect to the DOCUWARE server, please check your app.config for the correct values.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    return;
                }
                if (!IsCabinetValid(commandLineParams.ImagePathRoot, commandLineParams.CabinetName))
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("The specified cabinet does not exist.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    return;
                }
                Guid exportBatchId = CreateExportBatch(commandLineParams.CabinetName);
                if (exportBatchId == Guid.Empty)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unable to create Export Log.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    return;
                }
                // whew, everything is ready to go, all we have to do is check to see if the cabinet exists before trying to export
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("-------------------------------------\n");
                Console.WriteLine("Image root path exists!");
                Console.WriteLine("Export path exists!");
                Console.WriteLine("Sql connection is valid!");
                Console.WriteLine("Docuware service connection is valid!");
                Console.WriteLine("Cabinet exists!");
                Console.WriteLine("Export batch created!\n");
                Console.WriteLine("-------------------------------------");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                // all the logic exists here.
                MigrationBuilder migrationBuilder = new MigrationBuilder(commandLineParams, exportBatchId);
                migrationBuilder.Run();
            }
            else
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Either the image root path doesn't exist or you do not have permission to create directories for the pdf export.");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                return;
            }
        }

        static void LoadTableMappings()
        {
            TableCabinetMatch = (ConfigurationManager.GetSection("tableMapping") as System.Collections.Hashtable)
                             .Cast<System.Collections.DictionaryEntry>()
                             .ToDictionary(n => n.Key.ToString(), n => n.Value.ToString());
        }

        static Guid CreateExportBatch(String cabinet)
        {
            Guid ExportBatchId = Guid.NewGuid();
            OleDbConnection oleDbConnection = GetNewOleDbConnection();
            OleDbCommand oleDbCommand = new OleDbCommand("INSERT INTO [ExportLog].[dbo].[ExportBatch] ([Id], [CabinetName]) VALUES (?, ?);", oleDbConnection);
            oleDbCommand.CommandType = System.Data.CommandType.Text;
            oleDbCommand.CommandText = "INSERT INTO [ExportLog].[dbo].[ExportBatch] ([Id], [CabinetName]) VALUES (?, ?);";
            oleDbCommand.Parameters.AddWithValue("@Id", ExportBatchId);
            oleDbCommand.Parameters.AddWithValue("@CabinetName", cabinet);
            int resultCount = oleDbCommand.ExecuteNonQuery();
            if (resultCount != 1)
                ExportBatchId = Guid.Empty;
            oleDbConnection.Close();
            oleDbConnection.Dispose();
            return ExportBatchId;
        }

        static string GetConnectionString()
        {
            String result = String.Empty;
            result = String.Format(
                "Provider=sqloledb;Data Source={0};Initial Catalog={1};User Id={2};Password={3};Connect Timeout=1200;Timeout=1200",
                new object[]
                {
                    ConfigurationManager.AppSettings["SQL_SERVER"].ToString(),
                    "DOCUWARE",
                    ConfigurationManager.AppSettings["SQL_UNAME"].ToString(),
                    ConfigurationManager.AppSettings["SQL_PASS"].ToString()
                }
            );
            return result;
        }

        static Uri GetDocuwareServiceConnectionUri()
        {
            Uri result = null;
            result = new Uri(
                String.Format(
                    "http://{0}/docuware/platform",
                    new object[]
                    {
                        ConfigurationManager.AppSettings["DW_SERVER"].ToString()
                    }
                )
            );
            return result;
        }

        static Boolean IsSqlConnectionValid()
        {
            Boolean result = false;
            OleDbConnection oleDbConnection = new OleDbConnection(GetConnectionString());
            try
            {
                oleDbConnection.Open();
                if (oleDbConnection.State == System.Data.ConnectionState.Open)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch
            {
                result = false;
            }
            try
            {
                oleDbConnection.Close();
                oleDbConnection.Dispose();
            }
            catch { }
            return result;
        }

        static Boolean IsDocuwareServiceConnectionValid()
        {
            Boolean result = false;
            try
            {
                ServiceConnection serviceConnection = ServiceConnection.Create(
                    GetDocuwareServiceConnectionUri(),
                    ConfigurationManager.AppSettings["DW_UNAME"].ToString(),
                    ConfigurationManager.AppSettings["DW_PASS"].ToString(),
                    userAgent: new System.Net.Http.Headers.ProductInfoHeaderValue[]
                    {
                        new System.Net.Http.Headers.ProductInfoHeaderValue("Premier+Migration+Application", "1.0")
                    }
                );

                serviceConnection.Disconnect();
                result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }

        public static OleDbConnection GetNewOleDbConnection()
        {
            OleDbConnection result = new OleDbConnection(GetConnectionString());
            result.Open();
            return result;
        }

        public static ServiceConnection GetNewServiceConnection()
        {
            ServiceConnection serviceConnection = 
                ServiceConnection.Create(
                    GetDocuwareServiceConnectionUri(),
                    ConfigurationManager.AppSettings["DW_UNAME"].ToString(),
                    ConfigurationManager.AppSettings["DW_PASS"].ToString(),
                    userAgent: new System.Net.Http.Headers.ProductInfoHeaderValue[]
                    {
                        new System.Net.Http.Headers.ProductInfoHeaderValue("Premier+Migration+Application", "1.0")
                    }
                );
            serviceConnection.HttpClient.Timeout = new System.TimeSpan(0, 20, 0);
            return serviceConnection;
        }

        static Boolean IsCabinetValid(String imageRootPath, String cabinetName)
        {
            Boolean result = false;
            String cabinetPath = Path.Combine(imageRootPath, cabinetName.ToUpper()) + ".001";
            DirectoryInfo diCabinetPath = null;
            try
            {
                diCabinetPath = new DirectoryInfo(cabinetPath);
                if (diCabinetPath.Exists) result = true; else result = false;
            }
            catch
            {
                result = false;
            }
            return result;
        }

    }
}

Commits for ChrisCompleteCodeTrunk/PremierMigration/PremierMigration/Program.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000