2. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 11/5/2018 10:29:46 AM Central Standard 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.

2.1 Files compared

# Location File Last Modified
1 CRM_PE_OCT.zip\Integrations\Medallia\Medallia.VEFT\Processors RetrieveFromS3Processor.cs Thu Aug 30 05:11:04 2018 UTC
2 CRM_PE_OCT.zip\Integrations\Medallia\Medallia.VEFT\Processors RetrieveFromS3Processor.cs Mon Nov 5 02:25:34 2018 UTC

2.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 822
Changed 1 12
Inserted 0 0
Removed 0 0

2.3 Comparison options

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

2.4 Active regular expressions

No regular expressions were active.

2.5 Comparison detail

  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. Configurat ion;
  9   using Amaz on;
  10   using Amaz on.S3;
  11   using Amaz on.S3.Mode l;
  12   using VRMR est.WebApi ;
  13   using Syst em.Collect ions.Gener ic;
  14  
  15   namespace  Medallia.V EFT.Proces sors
  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 stat ic string  onPremiseV IMTDACStri ng = Medal liaSecurit yConfigura tion.Curre nt.DAC_URI ;
  24           pr ivate stat ic WebServ iceDetails  _OnPremDA Cwsd = nul l;
  25           pr ivate stat ic Uri _on PremDACUri  = null;
  26           pr ivate int  _retry = 0 ;
  27           pr ivate stri ng uname =  MedalliaS ecurityCon figuration .Current.D AC_Uname;
  28           pr ivate stri ng pass =  MedalliaSe curityConf iguration. Current.DA C_Pass;
  29           Re trieveFrom S3Response  response  = new Retr ieveFromS3 Response() ;
  30  
  31           // /Deprecate d: these l ines to be  removed o nce Config  settings  are valida ted
  32           // private st ring _buck etName = " inbound.va .ugw1-atla s-prod.us- gov-west-1 .medallia" ;
  33             //private  static str ing onPrem iseVIMTDAC String = " https:// URL /VINEXT";  //Producti on
  34             //private  static str ing onPrem iseVIMTDAC String = " https:// URL /INT/VEFT/ VINEXT"; / /Nonproduc tion
  35             //private  string una me = " AI "; //Produ ction
  36             //private  string pas s = "
A I "; //Produ ction
  37             //private  string una me = " A I
"; //Nonpr oduction
  38             //private  string pas s = "
A I "; //Nonpr oduction
  39  
  40           pu blic IMess ageBase Ex ecute(Retr ieveFromS3 Request re quest)
  41           {
  42                #region  initialize
  43                response .MessageId  = request .MessageId ;
  44                response .Exception Occurred =  false;
  45                response .Exception Message =  "";
  46                response .FailureDe tails = ne w List<Fai lureDetail >();
  47                var prog ressString  = new Str ingBuilder ();
  48                progress String.App end("top o f processo r.\n");
  49                _logBuff er = strin g.Empty;
  50  
  51                string r oot = Meda lliaSecuri tyConfigur ation.Curr ent.FilePa th;
  52                //if (on PremiseVIM TDACString .IndexOf(" veft.prod" ) != -1)
  53                //    ro ot = "D:\\ WWWRoot\\I netpub\\VE FT\\VINEXT \\";
  54                //else {  root = "D :\\InetPub \\WWWRoot\ \NonProd\\ INT\\VEFT\ \ViNEXT\\" ; }
  55  
  56                if (requ est == nul l)
  57                {
  58                    resp onse.Excep tionMessag e = "Calle d with no  message";
  59                    resp onse.Excep tionOccurr ed = true;
  60                    retu rn respons e;
  61                }
  62  
  63                _onPremD ACUri = ne w Uri(onPr emiseVIMTD ACString);
  64                _OnPremD ACwsd = ne w WebServi ceDetails( )
  65                {
  66                    Targ etURL = on PremiseVIM TDACString ,
  67                    WSUs erName = u name,
  68                    Pass word = pas s
  69                };
  70                #endregi on
  71                #region  pull CSV
  72                var s3Co nfig = new  AmazonS3C onfig
  73                {
  74                    Serv iceURL = M edalliaSec urityConfi guration.C urrent.Ser vice_URI,
  75                    //Se rviceURL =  "https:// s3-fips-us -gov-west- 1.amazonaw s.com",
  76                    Regi onEndpoint  = RegionE ndpoint.US GovCloudWe st1
  77                };
  78                //using  (_client =  new Amazo nS3Client( "AKIAKYKWO YKEIURPP4O Q", "2rfT2 PnRRyuZa+b L3nqs5d+hf ftlHupcg9P PsSur"))
  79                using (_ client = n ew AmazonS 3Client(Me dalliaSecu rityConfig uration.Cu rrent.S3_K ey, Medall iaSecurity Configurat ion.Curren t.S3_Secre t, s3Confi g))
  80                {
  81                    try
  82                    {
  83                         progressSt ring.Appen d("client  instantiat ed.\n");
  84  
  85                         ListObject sRequest l istObjects  = new Lis tObjectsRe quest()
  86                         {
  87                             Bucket Name = _bu cketName
  88                         };
  89  
  90                         ListObject sResponse  listRespon se = _clie nt.ListObj ects(listO bjects);
  91                         if (listRe sponse !=  null && li stResponse .S3Objects .Count > 0 )
  92                         {
  93                             foreac h (var obj  in listRe sponse.S3O bjects)
  94                             {
  95                                 // 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
  96                                 // if (obj.Ke y != null  && obj.Key .IndexOf(" va_CREATE_ INTERACTIO N_EXPORT")  != -1) // Nonproduct ion
  97                                 if  (obj.Key  != null &&  obj.Key.I ndexOf(Med alliaSecur ityConfigu ration.Cur rent.FileM atch) != - 1)
  98                                 {
  99                                      _key.Add (obj.Key);
  100                                 }
  101                             }
  102                         }
  103                         else
  104                         {
  105                             Logger .Instance. Warn("NO E XPORT FILE  FOUND IN  S3: Aborti ng retriev al.");
  106                             return  response;
  107                         }
  108                         if(_key ==  null || _ key.Count  == 0)
  109                         {
  110                             Logger .Instance. Warn("NO E XPORT FILE  FOUND IN  S3: Aborti ng retriev al.");
  111                             return  response;
  112                         }
  113                         List<strin g> written  = new Lis t<string>( );
  114                         List<strin g> deleted  = new Lis t<string>( );
  115                         foreach (v ar key in  _key)
  116                         {                          
  117                             #regio n pull doc s
  118                             try
  119                             {
  120                                 Ge tObjectReq uest pull  = new GetO bjectReque st()
  121                                 {
  122                                      BucketNa me = _buck etName,
  123                                      Key = ke y,
  124                                      ServerSi deEncrypti onCustomer Method = S erverSideE ncryptionC ustomerMet hod.None
  125                                 };
  126                                 Lo gger.Insta nce.Debug( "getting d oc");
  127                                 pr ogressStri ng.Append( "Getting o bject.\n") ;
  128                                 bo ol write;
  129                                 us ing (GetOb jectRespon se get = _ client.Get Object(pul l))
  130                                 {
  131                                      progress String.App end("Writi ng object. \n");
  132                                      Logger.I nstance.De bug($"writ ing to fil e: {root}{ key}.csv") ;
  133                                      write =  tryWriteFi le(root, k ey + ".csv ", get);
  134                                 }
  135                                 if  (write)
  136                                 {
  137                                      written. Add(key);
  138                                      Logger.I nstance.De bug("added  to writte n");
  139                                 }
  140                             }
  141                             catch  (AmazonS3E xception e x)
  142                             {
  143                                 re sponse.Fai lureDetail s.Add(new  FailureDet ail()
  144                                 {
  145                                      Reason =  FailureRe ason.Other Exception,
  146                                      Details  = $"Except ion while  trying to  retrieve I nteraction s from S3  ({_key.Ind exOf(key)  + 1}/{(_ke y.Count)}) : {ex.Mess age}"
  147                                 }) ;
  148                             }
  149                             #endre gion 
  150                         }
  151                         if (writte n != null  && written .Count > 0 )
  152                         {
  153                             #regio n deletefr omS3
  154                             foreac h (var key  in writte n)
  155                             {
  156                                 tr y
  157                                 {
  158                                      DeleteOb jectReques t deleteRe quest = ne w DeleteOb jectReques t()
  159                                      {
  160                                          Buck etName = _ bucketName ,
  161                                          Key  = key
  162                                      };
  163                                      Logger.I nstance.De bug("delet ing from s 3");
  164                                      _client. DeleteObje ct(deleteR equest);
  165                                      deleted. Add(key);
  166                                 }
  167                                 ca tch (Amazo nS3Excepti on ex)
  168                                 {
  169                                      response .FailureDe tails.Add( new Failur eDetail()
  170                                      {
  171                                          Reas on = Failu reReason.O therExcept ion,
  172                                          Deta ils = $"Ex ception wh ile trying  to delete  Interacti ons from S 3 ({writte n.IndexOf( key) + 1}/ {(written. Count)}):  {ex.Messag e}"
  173                                      });
  174                                 }
  175                             }
  176                         }
  177                         #endregion
  178                         if (delete d != null  && deleted .Count > 0 )
  179                         {
  180                             foreac h (var key  in delete d)
  181                             {
  182                                 Lo gger.Insta nce.Debug( "getting f ile");
  183                                 st ring getSt ring = try GetFile(ro ot, key +  ".csv");
  184                                 if  (getStrin g != null)
  185                                 {
  186                                      Logger.I nstance.De bug("got f ile");
  187                                      getStrin g = getStr ing.Replac e("^", "{c arrot}");  //insulate  against u nexpected  character
  188                                      getStrin g = getStr ing.Replac e("\n", "^ ");
  189                                      string[]  rows = ge tString.Sp lit('^');
  190  
  191                                      try
  192                                      {
  193                                          for  (int i = 1 ; i < rows .Length -  1; i++)
  194                                          {
  195                                               string thi sRow = row s[i];
  196                                               string[] i nteraction  = thisRow .Split('|' );
  197                                               #endregion
  198                                               #region cr eate inter action
  199  
  200                                               var newInt eraction =  new Creat eInteracti onRequest( )
  201                                               {
  202                                                   Messag eLogging =  new Messa geLogging( )
  203                                                   {
  204                                                       Ig noreState  = false,
  205                                                       Ma xRetry = - 1,
  206                                                       Me ssageName  = "CreateI nteraction Request",
  207                                                       Me ssageType  = "LOB",
  208                                                       Or ganization Name = "FT P",
  209                                                       Pa rentMessag eName = "R etrieveFro mS3Process or"
  210                                                   },
  211                                                   Organi zationName  = request .Organizat ionName,
  212                                                   Contac tFirstName  = interac tion[2],
  213                                                   Contac tLastName  = interact ion[3],
  214                                                   DateOf Contact =  interactio n[1],
  215                                                   Survey ID = inter action[0],
  216                                                   LastFo ur = inter action[4],
  217                                                   Callba ckNumber =  interacti on[6],
  218                                                   Survey Link = int eraction[1 3],
  219                                                   Contac tEmail = i nteraction [7],
  220                                                   DateOf Birth = in teraction[ 5],
  221                                                   Feedba ckType = i nteraction [8],
  222                                                   Experi enceScore  = interact ion[9],
  223                                                   Experi enceCommen ts = inter action[10] ,
  224                                                   Statio nID = inte raction[14 ],
  225                                                   AlertT ype = inte raction[15 ],
  226                                                   Survey Group = in teraction[ 16]
  227                                               };
  228                                               var result  = WebApiU tility.Sen dReceive<C reateInter actionResp onse>(_onP remDACUri,  "CreateIn teractionR equest", n ewInteract ion, null,  _OnPremDA Cwsd);
  229                                          }
  230                                      }
  231                                      #endregi on
  232                                      #region  CreateInte raction Fa ilureLogic
  233                                      //TODO:  Add more s pecific ca tches
  234                                      catch (E xception e x)
  235                                      {
  236                                          resp onse.Failu reDetails. Add(new Fa ilureDetai l()
  237                                          {
  238                                               Reason = F ailureReas on.Unexpec tedExcepti on,
  239                                               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}"
  240                                          });
  241                                      }
  242                                 }
  243                                 el se Logger. Instance.E rror($"Fil e Not Foun d: {key.Re place(":",  "_")}.csv ");
  244                                 #e ndregion
  245                             }
  246                         }
  247                         #region de lete local ly
  248                         foreach (v ar key in  written)
  249                         {
  250                             //dele te local c svs
  251                             tryDel eteFile(ro ot, key +  ".csv");
  252                         }
  253                         #endregion
  254                    }
  255                    #reg ion catche s
  256                    catc h (AmazonS 3Exception  amazonS3E xception)
  257                    {
  258                         if (amazon S3Exceptio n.ErrorCod e != null  &&
  259                             (amazo nS3Excepti on.ErrorCo de.Equals( "InvalidAc cessKeyId" ) ||
  260                             amazon S3Exceptio n.ErrorCod e.Equals(" InvalidSec urity")))
  261                         {
  262                             respon se.Failure Details.Ad d(new Fail ureDetail( )
  263                             {
  264                                 Re ason = Fai lureReason .SecurityE xception,
  265                                 De tails = $" Security E xception w hile tryin g to Retri eve from S 3: {amazon S3Exceptio n.Message} "
  266                             });
  267                         }
  268                         else
  269                         {
  270                             respon se.Failure Details.Ad d(new Fail ureDetail( )
  271                             {
  272                                 Re ason = Fai lureReason .OtherExce ption,
  273                                 De tails = $" Exception  while tryi ng to Retr ieve from  S3: {amazo nS3Excepti on.Message }"
  274                             });
  275                             if (am azonS3Exce ption.Inne rException  != null)
  276                                 re sponse.Fai lureDetail s[-1].Deta ils += "\n " + $"Inne r Exceptio n: {amazon S3Exceptio n.InnerExc eption}";
  277                         }
  278                         response.E xceptionOc curred = t rue;
  279                         response.E xceptionMe ssage = am azonS3Exce ption.Mess age;
  280                         return res ponse;
  281                    }
  282                    catc h (Excepti on ex)
  283                    {
  284                         response.F ailureDeta ils.Add(ne w FailureD etail()
  285                         {
  286                             Reason  = Failure Reason.Une xpectedExc eption,
  287                             Detail s = $"Unex pected Exc eption whi le trying  to Retriev e from S3:  {ex.Messa ge}"
  288                         });
  289                         response.E xceptionOc curred = t rue;
  290                         response.E xceptionMe ssage = ex .Message;
  291                         return res ponse;
  292                    }
  293                    #end region
  294  
  295                    retu rn respons e;
  296                }
  297           }
  298  
  299           pr ivate void  tryDelete File(strin g root, st ring fileN ame)
  300           {
  301                try
  302                {
  303                    file Name = fil eName.Repl ace(":", " _");
  304                    File .Delete(ro ot + fileN ame);
  305                    _ret ry = 0;
  306                }
  307                catch (F ileNotFoun dException )
  308                {
  309                    resp onse.Failu reDetails. Add(new Fa ilureDetai l()
  310                    {
  311                         Reason = F ailureReas on.OtherEx ception,
  312                         Details =  "File Not  Found Exce ption: Una ble to del ete temp i mport file "
  313                    });
  314                    resp onse.Excep tionOccurr ed = true;
  315                    resp onse.Excep tionMessag e = "File  Not Found  Exception:  Unable to  delete te mp import  file";
  316                }
  317                catch (E xception e x)
  318                {
  319                    _ret ry++;
  320                    if ( _retry <=  10)
  321                    {
  322                         Thread.Sle ep(1000);
  323                         tryDeleteF ile(root,  fileName);
  324                    }
  325                    else
  326                    {
  327                         response.F ailureDeta ils.Add(ne w FailureD etail()
  328                         {
  329                             Reason  = Failure Reason.Une xpectedExc eption,
  330                             Detail s = $"Unkn own except ion during  retrieve  from S3 wh ile trying  to delete  locally:  {ex.Messag e}"
  331                         });
  332                         response.E xceptionOc curred = t rue;
  333                         response.E xceptionMe ssage = $" Unexpected  exception  while try ing to del ete locall y: {ex.Mes sage}";
  334                    }
  335                }
  336           }
  337  
  338           pr ivate bool  tryWriteF ile(string  root, str ing fileNa me, GetObj ectRespons e get)
  339           {
  340                try
  341                {
  342                    file Name = fil eName.Repl ace(":","_ ");
  343                    get. WriteRespo nseStreamT oFile(root  + fileNam e);
  344                    _ret ry = 0;
  345                    retu rn true;
  346                }
  347                catch (E xception e x)
  348                {
  349                    _ret ry++;
  350                    if ( _retry <=  10)
  351                    {
  352                         Thread.Sle ep(1000);
  353                         fileName =  fileName. Replace(": ", "_");
  354                         tryWriteFi le(root, f ileName, g et);
  355                    }
  356                    else
  357                    {
  358                         Logger.Ins tance.Erro r($"Unable  to write  {fileName}  to locati on {root}" );
  359                         response.F ailureDeta ils.Add(ne w FailureD etail()
  360                         {
  361                             Reason  = Failure Reason.Une xpectedExc eption,
  362                             Detail s = $"Unkn own except ion while  trying to  write Inte raction im ports: {ex .Message}"
  363                         });
  364                         response.E xceptionOc curred = t rue;
  365                         response.E xceptionMe ssage = $" Unexpected  exception  while try ing to wri te Interac tion impor ts: {ex.Me ssage}";
  366                         throw new  Exception( response.E xceptionMe ssage);
  367                    }
  368                    retu rn false;
  369                }
  370           }
  371  
  372           pr ivate stri ng tryGetF ile(string  root, str ing fileNa me)
  373           {
  374  
  375                try
  376                {
  377                    file Name = fil eName.Repl ace(":", " _");
  378                    stri ng getStri ng = File. ReadAllTex t(root + f ileName);
  379                    _ret ry = 0;
  380                    retu rn getStri ng;
  381                }
  382                catch (F ileNotFoun dException )
  383                {
  384                    resp onse.Failu reDetails. Add(new Fa ilureDetai l()
  385                    {
  386                         Reason = F ailureReas on.OtherEx ception,
  387                         Details =  "File Not  Found Exce ption: Una ble to fin d Pending  Medallia i mport"
  388                    });
  389                    resp onse.Excep tionOccurr ed = true;
  390                    resp onse.Excep tionMessag e = "File  Not Found  Exception:  Unable to  find Pend ing Medall ia import" ;
  391                    retu rn null;
  392                }
  393                catch (E xception e x)
  394                {
  395                    _ret ry++;
  396                    if ( _retry <=  10)
  397                    {
  398                         Thread.Sle ep(1000);
  399                         var result  = tryGetF ile(root,  fileName);
  400                         return res ult;
  401                    }
  402                    else
  403                    {
  404                         response.F ailureDeta ils.Add(ne w FailureD etail()
  405                         {
  406                             Reason  = Failure Reason.Une xpectedExc eption,
  407                             Detail s = $"Unkn own except ion while  trying to  read pendi ng medalli a import:  {ex.Messag e}"
  408                         });
  409                         response.E xceptionOc curred = t rue;
  410                         response.E xceptionMe ssage = $" Unexpected  exception  while try ing to rea d pending  medallia i mport: {ex .Message}" ;
  411                         return nul l;
  412                    }
  413                }
  414           }
  415  
  416       }
  417   }