Produced by Araxis Merge on 5/23/2019 1:17:27 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | PATS_R_SourceCode.zip\PATSRIntegrationsCRMOL\Medallia\Medallia.VEFT.WebApi\Processors | RetrieveFromS3Processor.cs | Thu Apr 25 19:02:58 2019 UTC |
2 | PATS_R_SourceCode.zip\PATSRIntegrationsCRMOL\Medallia\Medallia.VEFT.WebApi\Processors | RetrieveFromS3Processor.cs | Thu May 23 01:36:17 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 800 |
Changed | 1 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | using Syst em; | |
2 | using Syst em.IO; | |
3 | using Syst em.Text; | |
4 | using Syst em.Threadi ng; | |
5 | using VRM. Integratio n.Serviceb us.Core; | |
6 | using VRM. Integratio n.Serviceb us.Extensi ons; | |
7 | using Meda llia.VEFT. Messages; | |
8 | using Meda llia.VEFT. WebApi.Con figuration ; | |
9 | using Amaz on; | |
10 | using Amaz on.S3; | |
11 | using Amaz on.S3.Mode l; | |
12 | using Meda llia.VEFT. WebApi; | |
13 | using Syst em.Collect ions.Gener ic; | |
14 | ||
15 | namespace Medallia.V EFT.WebApi .Processor s | |
16 | { | |
17 | class RetrieveFr omS3Proces sor | |
18 | { | |
19 | pr ivate stri ng _logBuf fer { get; set; } | |
20 | st atic IAmaz onS3 _clie nt; | |
21 | pr ivate stri ng _bucket Name = Med alliaSecur ityConfigu ration.Cur rent.Bucke t_Name; | |
22 | pr ivate List <string> _ key = new List<strin g>(); | |
23 | pr ivate int _retry = 0 ; | |
24 | Re trieveFrom S3Response response = new Retr ieveFromS3 Response() ; | |
25 | ||
26 | // /Deprecate d: these l ines to be removed o nce Config settings are valida ted | |
27 | // private st ring _buck etName = " inbound.va .ugw1-atla s-prod.us- gov-west-1 .medallia" ; | |
28 | //private static str ing onPrem iseVIMTDAC String = " https:// DNS . URL /VINEXT"; //Producti on | |
29 | //private static str ing onPrem iseVIMTDAC String = " https:// DNS . URL /INT/VEFT/ VINEXT"; / /Nonproduc tion | |
30 | // private st ring uname = "VEFTPR OutBound"; //Product ion | |
31 | // private st ring pass = "PAHWVv2 vUoyGlWtpv Fpm!@"; // Production | |
32 | // private st ring uname = "VEFTNP VOICEInbou nd"; //Non production | |
33 | // private st ring pass = "PAHWVv2 vUoyGlWtpv Fpm"; //No nproductio n | |
34 | ||
35 | pu blic IMess ageBase Ex ecute(Retr ieveFromS3 Request re quest) | |
36 | { | |
37 | try | |
38 | { | |
39 | ||
40 | #reg ion initia lize | |
41 | resp onse.Messa geId = req uest.Messa geId; | |
42 | resp onse.Excep tionOccurr ed = false ; | |
43 | resp onse.Excep tionMessag e = ""; | |
44 | resp onse.Failu reDetails = new List <FailureDe tail>(); | |
45 | var progressSt ring = new StringBui lder(); | |
46 | prog ressString .Append("t op of proc essor.\n") ; | |
47 | _log Buffer = s tring.Empt y; | |
48 | ||
49 | stri ng root = MedalliaSe curityConf iguration. Current.Fi lePath; | |
50 | Syst em.IO.Dire ctory.Crea teDirector y(root); | |
51 | if ( request == null) | |
52 | { | |
53 | response.E xceptionMe ssage = "C alled with no messag e"; | |
54 | response.E xceptionOc curred = t rue; | |
55 | return res ponse; | |
56 | } | |
57 | #end region | |
58 | #reg ion pull C SV | |
59 | var s3Config = new Amazo nS3Config | |
60 | { | |
61 | ServiceURL = Medalli aSecurityC onfigurati on.Current .Service_U RI, | |
62 | //ServiceU RL = "http s://s3-fip s-us-gov-w est-1.amaz onaws.com" , | |
63 | RegionEndp oint = Reg ionEndpoin t.USGovClo udWest1 | |
64 | }; | |
65 | //us ing (_clie nt = new A mazonS3Cli ent("AKIAK YKWOYKEIUR PP4OQ", "2 rfT2PnRRyu Za+bL3nqs5 d+hfftlHup cg9PPsSur" )) | |
66 | usin g (_client = new Ama zonS3Clien t(Medallia SecurityCo nfiguratio n.Current. S3_Key, Me dalliaSecu rityConfig uration.Cu rrent.S3_S ecret, s3C onfig)) | |
67 | { | |
68 | progressSt ring.Appen d("client instantiat ed.\n"); | |
69 | ||
70 | ListObject sRequest l istObjects = new Lis tObjectsRe quest() | |
71 | { | |
72 | Bucket Name = _bu cketName, | |
73 | Prefix = Medalli aSecurityC onfigurati on.Current .FileMatch , | |
74 | MaxKey s = 500 | |
75 | }; | |
76 | ||
77 | ListObject sResponse listRespon se = _clie nt.ListObj ects(listO bjects); | |
78 | if (listRe sponse != null && li stResponse .S3Objects .Count > 0 ) | |
79 | { | |
80 | foreac h (var obj in listRe sponse.S3O bjects) | |
81 | { | |
82 | // if (obj.Ke y.IndexOf( "va_CREATE _INTERACTI ON_PROD_EX PORT") != -1 && Date Time.Compa re(obj.Las tModified, compareDa te) > 0) / /Productio n | |
83 | // if (obj.Ke y != null && obj.Key .IndexOf(" va_CREATE_ INTERACTIO N_EXPORT") != -1) // Nonproduct ion | |
84 | if (obj.Key != null && obj.Key.I ndexOf(Med alliaSecur ityConfigu ration.Cur rent.FileM atch) != - 1) | |
85 | { | |
86 | _key.Add (obj.Key); | |
87 | } | |
88 | } | |
89 | } | |
90 | else | |
91 | { | |
92 | Logger .Instance. Warn("NO E XPORT FILE FOUND IN S3: Aborti ng retriev al."); | |
93 | return response; | |
94 | } | |
95 | if (_key = = null || _key.Count == 0) | |
96 | { | |
97 | Logger .Instance. Warn("NO E XPORT FILE FOUND IN S3: Aborti ng retriev al."); | |
98 | return response; | |
99 | } | |
100 | List<strin g> written = new Lis t<string>( ); | |
101 | List<strin g> deleted = new Lis t<string>( ); | |
102 | foreach (v ar key in _key) | |
103 | { | |
104 | #regio n pull doc s | |
105 | try | |
106 | { | |
107 | Ge tObjectReq uest pull = new GetO bjectReque st() | |
108 | { | |
109 | BucketNa me = _buck etName, | |
110 | Key = ke y, | |
111 | ServerSi deEncrypti onCustomer Method = S erverSideE ncryptionC ustomerMet hod.None | |
112 | }; | |
113 | Lo gger.Insta nce.Debug( "getting d oc"); | |
114 | pr ogressStri ng.Append( "Getting o bject.\n") ; | |
115 | bo ol write; | |
116 | us ing (GetOb jectRespon se get = _ client.Get Object(pul l)) | |
117 | { | |
118 | progress String.App end("Writi ng object. \n"); | |
119 | Logger.I nstance.De bug($"writ ing to fil e: {root}{ key}.csv") ; | |
120 | write = tryWriteFi le(root, k ey + ".csv ", get); | |
121 | } | |
122 | if (write) | |
123 | { | |
124 | written. Add(key); | |
125 | Logger.I nstance.De bug("added to writte n"); | |
126 | } | |
127 | } | |
128 | catch (AmazonS3E xception e x) | |
129 | { | |
130 | re sponse.Fai lureDetail s.Add(new FailureDet ail() | |
131 | { | |
132 | Reason = FailureRe ason.Other Exception, | |
133 | Details = $"Except ion while trying to retrieve I nteraction s from S3 ({_key.Ind exOf(key) + 1}/{(_ke y.Count)}) : {ex.Mess age}" | |
134 | }) ; | |
135 | } | |
136 | #endre gion | |
137 | } | |
138 | if (writte n != null && written .Count > 0 ) | |
139 | { | |
140 | #regio n deletefr omS3 | |
141 | foreac h (var key in writte n) | |
142 | { | |
143 | tr y | |
144 | { | |
145 | DeleteOb jectReques t deleteRe quest = ne w DeleteOb jectReques t() | |
146 | { | |
147 | Buck etName = _ bucketName , | |
148 | Key = key | |
149 | }; | |
150 | Logger.I nstance.De bug("delet ing from s 3"); | |
151 | _client. DeleteObje ct(deleteR equest); | |
152 | deleted. Add(key); | |
153 | } | |
154 | ca tch (Amazo nS3Excepti on ex) | |
155 | { | |
156 | response .FailureDe tails.Add( new Failur eDetail() | |
157 | { | |
158 | Reas on = Failu reReason.O therExcept ion, | |
159 | Deta ils = $"Ex ception wh ile trying to delete Interacti ons from S 3 ({writte n.IndexOf( key) + 1}/ {(written. Count)}): {ex.Messag e}" | |
160 | }); | |
161 | } | |
162 | } | |
163 | } | |
164 | #endregion | |
165 | if (delete d != null && deleted .Count > 0 ) | |
166 | { | |
167 | foreac h (var key in delete d) | |
168 | { | |
169 | Lo gger.Insta nce.Debug( "getting f ile"); | |
170 | st ring getSt ring = try GetFile(ro ot, key + ".csv"); | |
171 | if (getStrin g != null) | |
172 | { | |
173 | Logger.I nstance.De bug("got f ile"); | |
174 | getStrin g = getStr ing.Replac e("^", "{c arrot}"); //insulate against u nexpected character | |
175 | getStrin g = getStr ing.Replac e("\n", "^ "); | |
176 | string[] rows = ge tString.Sp lit('^'); | |
177 | ||
178 | try | |
179 | { | |
180 | for (int i = 1 ; i < rows .Length - 1; i++) | |
181 | { | |
182 | string thi sRow = row s[i]; | |
183 | string[] i nteraction = thisRow .Split('|' ); | |
184 | #endregion | |
185 | #region cr eate inter action | |
186 | ||
187 | var newInt eraction = new Creat eInteracti onRequest( ) | |
188 | { | |
189 | Messag eLogging = new Messa geLogging( ) | |
190 | { | |
191 | Ig noreState = false, | |
192 | Ma xRetry = - 1, | |
193 | Me ssageName = "CreateI nteraction Request", | |
194 | Me ssageType = "LOB", | |
195 | Or ganization Name = req uest.Organ izationNam e, | |
196 | Pa rentMessag eName = "R etrieveFro mS3Process or" | |
197 | }, | |
198 | Organi zationName = request .Organizat ionName, | |
199 | Contac tFirstName = interac tion[2], | |
200 | Contac tLastName = interact ion[3], | |
201 | DateOf Contact = interactio n[1], | |
202 | Survey ID = inter action[0], | |
203 | LastFo ur = inter action[4], | |
204 | Callba ckNumber = interacti on[6], | |
205 | Survey Link = int eraction[1 3], | |
206 | Contac tEmail = i nteraction [7], | |
207 | DateOf Birth = in teraction[ 5], | |
208 | Feedba ckType = i nteraction [8], | |
209 | Experi enceScore = interact ion[9], | |
210 | Experi enceCommen ts = inter action[10] , | |
211 | Statio nID = inte raction[14 ], | |
212 | AlertT ype = inte raction[15 ], | |
213 | Survey Group = in teraction[ 16] | |
214 | }; | |
215 | CreateInte ractionPro cessor pro cessor = n ew CreateI nteraction Processor( ); | |
216 | var result = process or.Execute (newIntera ction); | |
217 | } | |
218 | } | |
219 | #endregi on | |
220 | #region CreateInte raction Fa ilureLogic | |
221 | //TODO: Add more s pecific ca tches | |
222 | catch (E xception e x) | |
223 | { | |
224 | resp onse.Failu reDetails. Add(new Fa ilureDetai l() | |
225 | { | |
226 | Reason = F ailureReas on.Unexpec tedExcepti on, | |
227 | Details = $"Unexpect ed Excepti on while t rying to C reate Inte raction in CRM ({del eted.Index Of(key) + 1}/{(delet ed.Count)} ): {ex.Mes sage}" | |
228 | }); | |
229 | } | |
230 | } | |
231 | el se Logger. Instance.E rror($"Fil e Not Foun d: {key.Re place(":", "_")}.csv "); | |
232 | #e ndregion | |
233 | } | |
234 | } | |
235 | #region de lete local ly | |
236 | foreach (v ar key in written) | |
237 | { | |
238 | //dele te local c svs | |
239 | tryDel eteFile(ro ot, key + ".csv"); | |
240 | } | |
241 | #endregion | |
242 | } | |
243 | } | |
244 | catch (A mazonS3Exc eption ama zonS3Excep tion) | |
245 | { | |
246 | if ( amazonS3Ex ception.Er rorCode != null && | |
247 | (amazonS3E xception.E rrorCode.E quals("Inv alidAccess KeyId") || | |
248 | amazonS3Ex ception.Er rorCode.Eq uals("Inva lidSecurit y"))) | |
249 | { | |
250 | response.F ailureDeta ils.Add(ne w FailureD etail() | |
251 | { | |
252 | Reason = Failure Reason.Sec urityExcep tion, | |
253 | Detail s = $"Secu rity Excep tion while trying to Retrieve from S3: { amazonS3Ex ception.Me ssage}" | |
254 | }); | |
255 | } | |
256 | else | |
257 | { | |
258 | response.F ailureDeta ils.Add(ne w FailureD etail() | |
259 | { | |
260 | Reason = Failure Reason.Oth erExceptio n, | |
261 | Detail s = $"Exce ption whil e trying t o Retrieve from S3: {amazonS3E xception.M essage}" | |
262 | }); | |
263 | if (amazon S3Exceptio n.InnerExc eption != null) | |
264 | respon se.Failure Details[-1 ].Details += "\n" + $"Inner Ex ception: { amazonS3Ex ception.In nerExcepti on}"; | |
265 | } | |
266 | resp onse.Excep tionOccurr ed = true; | |
267 | resp onse.Excep tionMessag e = amazon S3Exceptio n.Message; | |
268 | retu rn respons e; | |
269 | } | |
270 | catch (E xception e x) | |
271 | { | |
272 | resp onse.Failu reDetails. Add(new Fa ilureDetai l() | |
273 | { | |
274 | Reason = F ailureReas on.Unexpec tedExcepti on, | |
275 | Details = $"Unexpect ed Excepti on while t rying to R etrieve fr om S3: {ex .Message}" | |
276 | }); | |
277 | resp onse.Excep tionOccurr ed = true; | |
278 | resp onse.Excep tionMessag e = ex.Mes sage; | |
279 | retu rn respons e; | |
280 | } | |
281 | return r esponse; | |
282 | } | |
283 | ||
284 | pr ivate void tryDelete File(strin g root, st ring fileN ame) | |
285 | { | |
286 | try | |
287 | { | |
288 | file Name = fil eName.Repl ace(":", " _"); | |
289 | File .Delete(ro ot + fileN ame); | |
290 | _ret ry = 0; | |
291 | } | |
292 | catch (F ileNotFoun dException ) | |
293 | { | |
294 | resp onse.Failu reDetails. Add(new Fa ilureDetai l() | |
295 | { | |
296 | Reason = F ailureReas on.OtherEx ception, | |
297 | Details = "File Not Found Exce ption: Una ble to del ete temp i mport file " | |
298 | }); | |
299 | resp onse.Excep tionOccurr ed = true; | |
300 | resp onse.Excep tionMessag e = "File Not Found Exception: Unable to delete te mp import file"; | |
301 | } | |
302 | catch (E xception e x) | |
303 | { | |
304 | _ret ry++; | |
305 | if ( _retry <= 10) | |
306 | { | |
307 | Thread.Sle ep(1000); | |
308 | tryDeleteF ile(root, fileName); | |
309 | } | |
310 | else | |
311 | { | |
312 | response.F ailureDeta ils.Add(ne w FailureD etail() | |
313 | { | |
314 | Reason = Failure Reason.Une xpectedExc eption, | |
315 | Detail s = $"Unkn own except ion during retrieve from S3 wh ile trying to delete locally: {ex.Messag e}" | |
316 | }); | |
317 | response.E xceptionOc curred = t rue; | |
318 | response.E xceptionMe ssage = $" Unexpected exception while try ing to del ete locall y: {ex.Mes sage}"; | |
319 | } | |
320 | } | |
321 | } | |
322 | ||
323 | pr ivate bool tryWriteF ile(string root, str ing fileNa me, GetObj ectRespons e get) | |
324 | { | |
325 | try | |
326 | { | |
327 | file Name = fil eName.Repl ace(":","_ "); | |
328 | get. WriteRespo nseStreamT oFile(root + fileNam e); | |
329 | _ret ry = 0; | |
330 | retu rn true; | |
331 | } | |
332 | catch (E xception e x) | |
333 | { | |
334 | _ret ry++; | |
335 | if ( _retry <= 10) | |
336 | { | |
337 | Thread.Sle ep(1000); | |
338 | fileName = fileName. Replace(": ", "_"); | |
339 | tryWriteFi le(root, f ileName, g et); | |
340 | } | |
341 | else | |
342 | { | |
343 | Logger.Ins tance.Erro r($"Unable to write {fileName} to locati on {root}" ); | |
344 | response.F ailureDeta ils.Add(ne w FailureD etail() | |
345 | { | |
346 | Reason = Failure Reason.Une xpectedExc eption, | |
347 | Detail s = $"Unkn own except ion while trying to write Inte raction im ports: {ex .Message}" | |
348 | }); | |
349 | response.E xceptionOc curred = t rue; | |
350 | response.E xceptionMe ssage = $" Unexpected exception while try ing to wri te Interac tion impor ts: {ex.Me ssage}"; | |
351 | throw new Exception( response.E xceptionMe ssage); | |
352 | } | |
353 | retu rn false; | |
354 | } | |
355 | } | |
356 | ||
357 | pr ivate stri ng tryGetF ile(string root, str ing fileNa me) | |
358 | { | |
359 | ||
360 | try | |
361 | { | |
362 | file Name = fil eName.Repl ace(":", " _"); | |
363 | stri ng getStri ng = File. ReadAllTex t(root + f ileName); | |
364 | _ret ry = 0; | |
365 | retu rn getStri ng; | |
366 | } | |
367 | catch (F ileNotFoun dException ) | |
368 | { | |
369 | resp onse.Failu reDetails. Add(new Fa ilureDetai l() | |
370 | { | |
371 | Reason = F ailureReas on.OtherEx ception, | |
372 | Details = "File Not Found Exce ption: Una ble to fin d Pending Medallia i mport" | |
373 | }); | |
374 | resp onse.Excep tionOccurr ed = true; | |
375 | resp onse.Excep tionMessag e = "File Not Found Exception: Unable to find Pend ing Medall ia import" ; | |
376 | retu rn null; | |
377 | } | |
378 | catch (E xception e x) | |
379 | { | |
380 | _ret ry++; | |
381 | if ( _retry <= 10) | |
382 | { | |
383 | Thread.Sle ep(1000); | |
384 | var result = tryGetF ile(root, fileName); | |
385 | return res ult; | |
386 | } | |
387 | else | |
388 | { | |
389 | response.F ailureDeta ils.Add(ne w FailureD etail() | |
390 | { | |
391 | Reason = Failure Reason.Une xpectedExc eption, | |
392 | Detail s = $"Unkn own except ion while trying to read pendi ng medalli a import: {ex.Messag e}" | |
393 | }); | |
394 | response.E xceptionOc curred = t rue; | |
395 | response.E xceptionMe ssage = $" Unexpected exception while try ing to rea d pending medallia i mport: {ex .Message}" ; | |
396 | return nul l; | |
397 | } | |
398 | } | |
399 | } | |
400 | ||
401 | } | |
402 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.