744. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/18/2018 2:02:15 PM Central 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.

744.1 Files compared

# Location File Last Modified
1 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\DotNet\VixInstallerSolution2013.root\VixInstallerSolution2013\VixInstallerBusiness TomcatFacade.cs Thu Oct 11 13:30:13 2018 UTC
2 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\DotNet\VixInstallerSolution2013.root\VixInstallerSolution2013\VixInstallerBusiness TomcatFacade.cs Wed Oct 17 17:58:52 2018 UTC

744.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 5 2086
Changed 4 14
Inserted 0 0
Removed 0 0

744.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

744.4 Active regular expressions

No regular expressions were active.

744.5 Comparison detail

  1   using Syst em;
  2   using Syst em.Collect ions.Gener ic;
  3   using Syst em.Text;
  4   using Syst em.IO;
  5   using Micr osoft.Win3 2;
  6   using Syst em.Diagnos tics;
  7   using Syst em.Xml;
  8   using Syst em.Runtime .InteropSe rvices;
  9   using log4 net;
  10   using Syst em.Threadi ng;
  11   using Syst em.Securit y.AccessCo ntrol;
  12   using Syst em.Securit y.Principa l;
  13  
  14   namespace  gov.va.med .imaging.e xchange.Vi xInstaller .business
  15   {
  16  
  17       public  static cl ass Tomcat Facade
  18       {
  19           // / <summary >
  20           // / Retrieve  a logger  for this c lass.
  21           // / </summar y>
  22           // / <returns >A logger  as a ILog  interface. </returns>
  23           pr ivate stat ic ILog Lo gger()
  24           {
  25                return L ogManager. GetLogger( typeof(Tom catFacade) .Name);
  26           }
  27  
  28           [S tructLayou t(LayoutKi nd.Sequent ial, CharS et = CharS et.Auto)]
  29           pr ivate clas s MEMORYST ATUSEX
  30           {
  31                public u int dwLeng th;
  32                public u int dwMemo ryLoad;
  33                public u long ullTo talPhys;
  34                public u long ullAv ailPhys;
  35                public u long ullTo talPageFil e;
  36                public u long ullAv ailPageFil e;
  37                public u long ullTo talVirtual ;
  38                public u long ullAv ailVirtual ;
  39                public u long ullAv ailExtende dVirtual;
  40                public M EMORYSTATU SEX()
  41                {
  42                    this .dwLength  = (uint)Ma rshal.Size Of(typeof( MEMORYSTAT USEX));
  43                }
  44           }
  45  
  46           [r eturn: Mar shalAs(Unm anagedType .Bool)]
  47           [D llImport(" kernel32.d ll", CharS et = CharS et.Auto, S etLastErro r = true)]
  48           st atic exter n bool Glo balMemoryS tatusEx([I n, Out] ME MORYSTATUS EX lpBuffe r);
  49  
  50           pr ivate stat ic readonl y String T OMCAT_SERV ICE_ACCOUN T_NAME = " apachetomc at";
  51           pr ivate stat ic readonl y String T OMCAT_ADMI N_ACCOUNT_ NAME = "ad min";
  52           pr ivate stat ic readonl y String T OMCAT_CONF IGURATION_ FOLDER = " conf";
  53           pr ivate stat ic readonl y String T OMCAT_EXEC UTABLE_FOL DER = "bin ";
  54           pr ivate stat ic readonl y String T OMCAT_LIB_ FOLDER = " lib";
  55           pr ivate stat ic readonl y String T OMCAT_LOG_ FOLDER = " logs";
  56           pr ivate stat ic readonl y String T OMCAT_LOG_ FOLDER_ENC RYPTED = @ "logs\secu re";
  57           pr ivate stat ic readonl y String T OMCAT_WEBA PP_FOLDER  = "webapps ";
  58           pr ivate stat ic readonl y String T OMCAT_AXIS 2_WEBAPP_F OLDER = @" webapps\ax is2\WEB-IN F\services ";
  59           pr ivate stat ic readonl y String T OMCAT_USER S_FILENAME  = @"tomca t-users.xm l";
  60  
  61           #r egion prop erties
  62           pr ivate stat ic string  _TomcatSer viceAccoun tName = TO MCAT_SERVI CE_ACCOUNT _NAME; 
  63           pu blic stati c string T omcatServi ceAccountN ame {
  64                get { re turn _Tomc atServiceA ccountName ; }
  65                set { _T omcatServi ceAccountN ame = valu e; }
  66           }
  67  
  68           pr ivate stat ic string  _ServiceAc countUsern ame =  TOM CAT_SERVIC E_ACCOUNT_ NAME;
  69           pu blic stati c string S erviceAcco untUsernam e {
  70                get { re turn _Serv iceAccount Username;  }
  71                set { _S erviceAcco untUsernam e = value;  }
  72           }
  73           
  74           pu blic stati c string T omcatAdmin AccountNam e { get {  return TOM CAT_ADMIN_ ACCOUNT_NA ME; } }
  75           pu blic stati c VixManif est Manife st { get;  set; }
  76           pu blic stati c string T omcatConfi gurationFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_C ONFIGURATI ON_FOLDER) ; } }
  77           pu blic stati c string T omcatExecu tableFolde r { get {  return Pat h.Combine( TomcatFaca de.TomcatI nstallatio nFolder, T OMCAT_EXEC UTABLE_FOL DER); } }
  78           pu blic stati c string T omcatLibFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_L IB_FOLDER) ; } }
  79           pu blic stati c string T omcatLogFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_L OG_FOLDER) ; } }
  80           pu blic stati c string T omcatLogFo lderEncryp ted { get  { return P ath.Combin e(TomcatFa cade.Tomca tInstallat ionFolder,  TOMCAT_LO G_FOLDER_E NCRYPTED);  } }
  81           pu blic stati c string T omcatWebAp plicationF older { ge t { return  Path.Comb ine(Tomcat Facade.Tom catInstall ationFolde r, TOMCAT_ WEBAPP_FOL DER); } }
  82           pu blic stati c string T omcatAxis2 WebApplica tionFolder  { get { r eturn Path .Combine(T omcatFacad e.TomcatIn stallation Folder, TO MCAT_AXIS2 _WEBAPP_FO LDER); } }
  83           pu blic stati c string A ctiveTomca tVersion {  get { ret urn Manife st.ActiveT omcatPrere quisite.Ve rsion; } }
  84           pu blic stati c string I nstallerFi lespec { g et { retur n Manifest .ActiveTom catPrerequ isite.Inst allerFiles pec; } }
  85  
  86           // / <summary >
  87           // / Gets the  Tomcat Wi ndows serv ice name.
  88           // / </summar y>
  89           pu blic stati c string T omcatServi ceName
  90           {
  91                get
  92                {
  93                    stri ng service Name = nul l;
  94                    Debu g.Assert(T omcatFacad e.IsTomcat Installed( ) == true) ;
  95                    stri ng key = n ull;
  96                    Regi stryView r egView = R egistryVie w.Registry 64;
  97                    if ( BusinessFa cade.Is64B itOperatin gSystem())
  98                    {
  99                         // Procrun  key will  be install ed under W ow6432Node  key - eve n if Tomca t 6.0.35 i s installe d natively
  100                         key = @"SO FTWARE\Wow 6432Node\A pache Soft ware Found ation\Proc run 2.0";
  101                    }
  102                    else
  103                    {
  104                         key = @"SO FTWARE\Apa che Softwa re Foundat ion\Procru n 2.0";
  105                    }
  106                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  107                    {
  108                         using (Reg istryKey p rocrun = r egKey.Open SubKey(key , true))
  109                         {
  110                             Debug. Assert(pro crun != nu ll);
  111                             Debug. Assert(pro crun.SubKe yCount > 0 );
  112                             string [] subkeys  = procrun .GetSubKey Names();
  113                             foreac h(string s ubkey in s ubkeys)
  114                             {
  115                                 if  (subkey.T oLower().S tartsWith( "tomcat"))
  116                                 {
  117                                      serviceN ame = subk ey;
  118                                 }
  119                             }
  120                             //serv iceName =  subkeys[0] ;
  121                         }
  122                         return ser viceName;
  123                    }
  124                }
  125           }
  126  
  127           // / <summary >
  128           // / Gets the  tomcat in stallation  folder.
  129           // / </summar y>
  130           pu blic stati c string T omcatInsta llationFol der
  131           {
  132                get
  133                {
  134                    stri ng install ationFolde r = GetTom catInstall ationFolde r(@"SOFTWA RE\Apache  Software F oundation\ Tomcat");
  135                    Logg er().Info( "Installat ion Folder  outside o f IF State ment: " +  installati onFolder);
  136                    if ( installati onFolder = = null)
  137                    {
  138                         Debug.Asse rt(Busines sFacade.Is 64BitOpera tingSystem () == true );
  139                         installati onFolder =  GetTomcat Installati onFolder(@ "SOFTWARE\ Wow6432Nod e\Apache S oftware Fo undation\T omcat");
  140                         Logger().I nfo("Insta llation Fo lder insid e of IF St atement: "  + install ationFolde r);
  141                    }
  142                    retu rn install ationFolde r;
  143                }
  144           }
  145  
  146           // / <summary >
  147           // / Gets the  installed  deprecate d tomcat v ersion.
  148           // / </summar y>
  149           // / <remarks >Can retur n null.</r emarks>
  150           pu blic stati c string D eprecatedT omcatVersi on
  151           {
  152                get
  153                {
  154                    Tomc atPrerequi site prere quisite =  GetInstall edDeprecat edTomcatPr erequsite( );
  155                    retu rn prerequ isite == n ull ? null  : prerequ isite.Vers ion;
  156                }
  157           }
  158  
  159           // / <summary >
  160           // / Gets the  installed  tomcat ve rsion as a  string.
  161           // / </summar y>
  162           // / <remarks >Could ret urn null i f Tomcat i s not inst alled.</re marks>
  163           pu blic stati c string I nstalledTo mcatVersio n
  164           {
  165                get
  166                {
  167                    stri ng install edVersion  = GetInsta lledTomcat Version(@" SOFTWARE\A pache Soft ware Found ation\Tomc at");
  168                    if ( installedV ersion ==  null)
  169                    {
  170                         Debug.Asse rt(Busines sFacade.Is 64BitOpera tingSystem () == true );
  171                         installedV ersion = G etInstalle dTomcatVer sion(@"SOF TWARE\Wow6 432Node\Ap ache Softw are Founda tion\Tomca t");
  172                    }
  173                    retu rn install edVersion;
  174                }
  175           }
  176  
  177           #e ndregion
  178  
  179           #r egion publ ic methods
  180  
  181  
  182           // / <summary >
  183           // / Disables  the tomca t monitor  (tomcat6w. exe) from  running wh en logging  in under  the user c redentials  where Tom cat was in stalled.
  184           // / </summar y>
  185           // / <remarks >On Window s 2008 sys tems with  UAC cranke d up, an e rror dialo g is being  displayed  because t he tomcat  monitor ne eds to be  started as  Administr ator. Also  note
  186           // / that thi s method i s tied to  Tomcat 6.< /remarks>
  187           pu blic stati c void Dis ableTomcat Monitor()
  188           {
  189                string k ey = @"Sof tware\Micr osoft\Wind ows\Curren tVersion\R un";
  190                Registry View regVi ew = Regis tryView.Re gistry64;
  191                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Cur rentUser,  regView))
  192                {
  193                    usin g (Registr yKey run =  regKey.Op enSubKey(k ey, true))
  194                    {
  195                         if (run !=  null)
  196                         {
  197                             if (ru n.GetValue ("ApacheTo mcatMonito r6.0_Tomca t6") != nu ll)
  198                             {
  199                                 ru n.DeleteVa lue("Apach eTomcatMon itor6.0_To mcat6");
  200                             }
  201                         }
  202                    }
  203                }
  204           }
  205  
  206           // / <summary >
  207           // / Check to  see if an y version  of Tomcat  is install ed without  caring if  the curre nt install ation is a ctive or d eprecated.
  208           // / </summar y>
  209           // / <returns ><c>true</ c> if Tomc at is inst alled; oth erwise <c> false</c>< /returns>
  210           pu blic stati c bool IsT omcatInsta lled()
  211           {
  212                Logger() .Info("Ent ered IsTom catInstall ed() metho d.");
  213                // strat egy change  - check f or existan ce of the  "Procrun 2 .0" subkey  since som etime afte r Tomcat 6 .0.20 ther e was an a dditional  level of
  214                // subke y added un der the To mcat subke y which co mplicates  testing fo r installa tion.
  215                // The i nherient a ssumption  is that  T omcat will  be instal led using  the window s service  installer  which inst alls Procr un. - DKB  10/5/2011
  216                bool isI nstalled =  false;
  217                string k ey = null;
  218                Registry View regVi ew = Regis tryView.Re gistry64;
  219                if (Busi nessFacade .Is64BitOp eratingSys tem())
  220                {
  221                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.35 is in stalled na tively
  222                    // T ODO: This  must be ch ecked for  each versi on of Tomc at that we  support
  223                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n";
  224                }
  225                else
  226                {
  227                    key  = @"SOFTWA RE\Apache  Software F oundation" ;
  228                }
  229                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  230                {
  231                    usin g (Registr yKey apach e = regKey .OpenSubKe y(key, tru e))
  232                    {
  233                         if (apache  != null)
  234                         {
  235                             if (ap ache.SubKe yCount > 0 ) // Tomca t key hang s around a fter an un install
  236                             {
  237                                 st ring[] sub keys = apa che.GetSub KeyNames() ;
  238                                 fo reach (str ing subkey  in subkey s)
  239                                 {
  240                                      if (subk ey.ToLower ().StartsW ith("procr un"))
  241                                      {
  242                                          stri ng procrun Key = key  + @"\" + s ubkey;
  243  
  244                                          usin g (Registr yKey procr un = regKe y.OpenSubK ey(procrun Key, true) )
  245                                          {
  246                                               if (procru n != null)
  247                                               {
  248                                                   if (pr ocrun.SubK eyCount >  0)
  249                                                   {
  250                                                       st ring[] pro crunSubkey s = procru n.GetSubKe yNames();
  251                                                       fo reach (str ing procru nSubkey in  procrunSu bkeys)
  252                                                       {
  253                                                            if (proc runSubkey. ToLower(). StartsWith ("tomcat") )
  254                                                            {
  255                                                                isIn stalled =  true;
  256                                                                brea k;
  257                                                            }
  258                                                       }
  259                                                   }
  260                                               }
  261                                          }
  262                                      }
  263                                 }
  264                             }
  265                         }
  266                    }
  267                }
  268  
  269                Logger() .Info("Tom cat is ins talled: "  + isInstal led);
  270                return i sInstalled ;
  271           }
  272  
  273           // / <summary >
  274           // / Disable  stdout log ging for T omcat
  275           // / </summar y>
  276           pu blic stati c void Dis ableStdOut Logging()
  277           {
  278                string k ey = null;
  279                Registry View regVi ew = Regis tryView.Re gistry64;
  280                if (Busi nessFacade .Is64BitOp eratingSys tem())
  281                {
  282                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  283                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Log";
  284                }
  285                else
  286                {
  287                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Log";
  288                }
  289  
  290                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  291                {
  292                    usin g (Registr yKey tomca t = regKey .OpenSubKe y(key, tru e))
  293                    {
  294                         if (tomcat  != null)
  295                         {
  296                             tomcat .DeleteVal ue("StdOut put", fals e);
  297                             tomcat .DeleteVal ue("StdErr or", false );
  298                         }
  299                    }
  300                }
  301           }
  302  
  303           // / <summary >
  304           // / Returns  true if th e Tomcat s ervice is  installed
  305           // / </summar y>
  306           // / <returns ><c>true</ c>if Tomca t service  is install ed; otherw ise <c>fal se</c>.</r eturns>
  307           // / <remarks >Used to c heck to se e if Tomca t was unin stalled su cessfully. </remarks>
  308           pu blic stati c bool IsD eprecatedT omcatServi ceInstalle d()
  309           {
  310                bool isI nstalled =  false;
  311                foreach  (TomcatPre requisite  prerequisi te in Mani fest.Depre catedTomca tPrerequis ites)
  312                {
  313                    if ( ServiceUti lities.IsN onDriverSe rviceInsta lled(prere quisite.Se rviceName)  == true)
  314                    {
  315                         isInstalle d = true;
  316                         break;
  317                    }
  318                }
  319                return i sInstalled ;
  320           }
  321  
  322           // / <summary >
  323           // / Determin es if the  required v ersion (as  indicated  by the ac tive prere quisite en try in the  manifest)  of Apache  Tomcat is  installed .
  324           // / </summar y>
  325           // / <returns ><c>true</ c> if the  required v ersion Apa che Tomcat  is instal led; other wise <c>fa lse</c>.</ returns>
  326           pu blic stati c bool IsA ctiveTomca tVersionIn stalled()
  327           {
  328                Logger() .Info("Ent ered IsAct iveTomcatV ersionInst alled() me thod.");
  329                bool isI nstalled =  false;
  330  
  331                if (Tomc atFacade.I sTomcatIns talled())
  332                {
  333                    if ( IsPrerequi siteInstal led(Manife st.ActiveT omcatPrere quisite))
  334                    {
  335                         isInstalle d = true;
  336                    }
  337                }
  338                Logger() .Info("Tom cat is ins talled: "  + isInstal led);
  339                return i sInstalled ;
  340           }
  341  
  342           // / <summary >
  343           // / Determin es if a de precated v ersion (as  indicated  by the de precated p rerequisit e entry in  the manif est) of Ap ache Tomca t is insta lled.
  344           // / </summar y>
  345           // / <returns ><c>true</ c> if the  deprecated  version A pache Tomc at is inst alled; oth erwise <c> false</c>. </returns>
  346           pu blic stati c bool IsD eprecatedT omcatVersi onInstalle d()
  347           {
  348                bool isI nstalled =  false;
  349  
  350                if (Tomc atFacade.I sTomcatIns talled())
  351                {
  352                    if ( GetInstall edDeprecat edTomcatPr erequsite( ) != null)
  353                    {
  354                         isInstalle d = true;
  355                    }
  356                }
  357                return i sInstalled ;
  358           }
  359  
  360           // / <summary >
  361           // / Gets the  tomcat wo rking fold er.
  362           // / </summar y>
  363           // / <param n ame="siteN umber">The  site numb er that is  part of t he owrking  folder na ming patte rn.</param >
  364           // / <returns >The fully  qualified  working f older.</re turns>
  365           pu blic stati c string G etTomcatWo rkFolder(s tring site Number)
  366           {
  367                String w orkPath =  @"work\Cat alina\" +  siteNumber  + ".med.v a.gov";
  368                return P ath.Combin e(TomcatFa cade.Tomca tInstallat ionFolder,  workPath) ;
  369           }
  370  
  371           // / <summary >
  372           // / Parses t he existin g tomcat a dmin passw ord out of  tomcat-us ers.xml.
  373           // / </summar y>
  374           // / <returns >tomcat ad min passwo rd</return s>
  375           pu blic stati c string G etExisting TomcatAdmi nPassword( )
  376           {
  377                string t omcatAdmin Password =  null;
  378                String t omcatUsers Path = Pat h.Combine( TomcatFaca de.TomcatC onfigurati onFolder,  TOMCAT_USE RS_FILENAM E);
  379                if (File .Exists(to mcatUsersP ath))
  380                {
  381                    XmlD ocument us ers = new  XmlDocumen t();
  382                    user s.Load(tom catUsersPa th);
  383                      XmlNode ad min = user s.SelectSi ngleNode(" tomcat-use rs/user[@u sername=' AI ']");
  384                    if ( admin == n ull)
  385                    {
  386                          admin = us ers.Select SingleNode ("tomcat-u sers/user[ @name=' AI ']"); // b ug in prev ious versi ons - wrot e name att ribute ins tead of us ername
  387                    }
  388                    Debu g.Assert(a dmin != nu ll);
  389                    tomc atAdminPas sword = ad min.Attrib utes["pass word"].Val ue.Trim();
  390                    Debu g.Assert(t omcatAdmin Password ! = null);
  391                }
  392                return t omcatAdmin Password;
  393           }
  394  
  395           // / <summary >
  396           // / Creates  the Apache  Tomcat co nfiguratio n file tha t defines  users and  roles. As  part of th is process
  397           // / creates  a user spe cified acc ount using  the passe d credenti als which  will have  the admin  and manage r roles.
  398           // / </summar y>
  399           // / <param n ame="usern ame">The u sername th at will be  given the  admin and  manager r oles.</par am>
  400           // / <param n ame="passw ord">The p assword as sociated w ith the us ername.</p aram>
  401           pu blic stati c void Con figureTomc atUsers(IV ixConfigur ationParam eters conf ig)
  402           {
  403                StringBu ilder sb =  new Strin gBuilder() ;
  404                sb.Appen dLine("<to mcat-users >");
  405                sb.Appen dLine("\t< role rolen ame=\"clin ical-displ ay-user\"/ >");
  406                sb.Appen dLine("\t< role rolen ame=\"admi nistrator\ "/>");
  407                sb.Appen dLine("\t< role rolen ame=\"deve loper\"/>" );
  408                sb.Appen dLine("\t< role rolen ame=\"tomc at\"/>");
  409                sb.Appen dLine("\t< role rolen ame=\"mana ger\"/>");
  410                sb.Appen dLine("\t< role rolen ame=\"peer -vixs\"/>" );
  411                sb.Appen dLine("\t< role rolen ame=\"admi n\"/>");
  412                sb.Appen dLine("\t< role rolen ame=\"vist a-user\"/> ");
  413                sb.Appen dLine("\t< role rolen ame=\"test er\"/>");
  414                  sb.AppendL ine("\t<us er  V s ID                         V s ID                    roles=\"cl inical-dis play-user, vista-user \"/>");
  415                  sb.AppendL ine("\t<us er  V s ID                    V s ID                       roles=\"ad ministrato r,tester\" />");
  416                  sb.AppendL ine("\t<us er  V s ID                  V s ID                  roles=\"pe er-vixs\"/ >");
  417                  sb.AppendL ine("\t<us er  V s ID                     V s ID                      roles=\"cl inical-dis play-user\ "/>");
  418                string p w = config .TomcatAdm inPassword ;
  419                if (pw = = null)
  420                {
  421                    pw =  config.Si teAbbrevia tion.Trim( ) + "x14y2 ";
  422                }
  423                  sb.AppendF ormat("\t< user  V s ID                 V s ID                 roles=\"ad min,manage r\" />", T OMCAT_ADMI N_ACCOUNT_ NAME, pw);
  424                sb.Appen d(Environm ent.NewLin e);
  425                sb.Appen dLine("</t omcat-user s>");
  426  
  427                String t omcatUsers Path = Pat h.Combine( TomcatFaca de.TomcatC onfigurati onFolder,  TOMCAT_USE RS_FILENAM E);
  428                using (T extWriter  tw = new S treamWrite r(tomcatUs ersPath))
  429                {
  430                    tw.W rite(sb.To String());
  431                }
  432           }
  433  
  434           // / <summary >
  435           // / Perform  the servic e setup th at would o rdinarily  be done us ing tomcat 5w.exe. 
  436           // / Currentl y this set s memory o ptions for  the JVM,  and config ures servi ce failure  actions
  437           // / </summar y>
  438           pu blic stati c void Con figureTomc atService( IVixConfig urationPar ameters co nfig)
  439           {
  440                Configur eTomcatJvm Memory(con fig);
  441                // if ru nning on a  HAC node  then do no t configur e recovery  options f or the Tom cat servic e.
  442                if (Clus terFacade. IsServerCl usterNode( ) == false )
  443                {
  444                    Serv iceUtiliti es.SetServ iceFailure Actions(To mcatFacade .TomcatSer viceName);
  445                }
  446           }
  447  
  448           // / <summary >
  449           // / Set Tomc at JVM mem ory usage
  450           // / </summar y>
  451           // / <remarks >This meth od makes d ecisions b ased on th e allowed  process si ze on the  operating  system.</r emarks>
  452           pu blic stati c void Con figureTomc atJvmMemor y(IVixConf igurationP arameters  config)
  453           {
  454                ulong to talPhysica lMemory =  GetPhysica lMemorySiz eInBytes() ;
  455  
  456                int jvmM emoryInMb  = (int)(to talPhysica lMemory /  (1024 * 10 24 * 4));  // convert  to MB the n take 25%  for JVM u se
  457                if (jvmM emoryInMb  > 1024 &&  Manifest.C urrentNati veInstalla tion == Na tiveType.x 86)
  458                {
  459                    jvmM emoryInMb  = 1024; //  dont exce ed this fo r 32 bit p rocess so  that suffi cient nati ve windows  memory ex ists for A ware and L B
  460                }
  461  
  462                string k ey = null;
  463                Registry View regVi ew = Regis tryView.Re gistry64;
  464                if (Busi nessFacade .Is64BitOp eratingSys tem())
  465                {
  466                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  467                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Java" ;
  468                }
  469                else
  470                {
  471                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Java";
  472                }
  473                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  474                {
  475                    usin g (Registr yKey java  = regKey.O penSubKey( key, true) )
  476                    {
  477                         java.SetVa lue("JvmMs ", jvmMemo ryInMb, Re gistryValu eKind.DWor d);
  478                         java.SetVa lue("JvmMx ", jvmMemo ryInMb, Re gistryValu eKind.DWor d);
  479                         java.SetVa lue("JvmSs ", 0, Regi stryValueK ind.DWord) ;
  480                    }
  481                }
  482           }
  483  
  484           // / <summary >
  485           // / Creates  and/or enc rypts the  secure log  sub direc tory
  486           // / </summar y>
  487           // / <param n ame="confi g"></param >
  488           // //public s tatic void  Configure TomcatEncr yptedLogFo lder(IVixC onfigurati onParamete rs config)
  489           // //{
  490           // //    Dire ctoryInfo  encryptedL ogDir = ne w Director yInfo(Tomc atLogFolde rEncrypted );
  491           // //    if ( !encrypted LogDir.Exi sts)
  492           // //    {
  493           // //         encryptedL ogDir.Crea te();
  494           // //         // recreat e the Dire ctoryInfo  object bec ause the o ld one has  cached da ta before  the dir wa s created
  495           // //         encryptedL ogDir = ne w Director yInfo(Tomc atLogFolde rEncrypted );
  496           // //    }
  497           // //    // c heck if en crypted fl ag is set
  498           // //    if ( (encrypted LogDir.Att ributes &  FileAttrib utes.Encry pted) == 0 ) // bitwi se AND to  check if t he Encrype d flag is  set
  499           // //    {
  500           // //         // encrypt ed flag no t set, so  set it
  501           // //         // Setting  the Direc toryInfo.A ttributes  to add the  encryptio n flag doe sn't work
  502           // //         // Instead  use the F ileInfo.En crypt meth od (Direct oryInfo do es not hav e an Encry pt method)
  503           // //         try
  504           // //         {
  505           // //             FileIn fo encrypt edLogDirFi le = new F ileInfo(To mcatLogFol derEncrypt ed);
  506           // //             encryp tedLogDirF ile.Encryp t();
  507           // //         }
  508           // //         catch (Exc eption ex)
  509           // //         {
  510           // //             Logger ().Error(e x.Message) ;
  511           // //             Logger ().Error(" Error encr ypting " +  TomcatLog FolderEncr ypted + ".  Install p roceding c an continu e.");
  512           // //         }
  513           // //    }
  514           // //}
  515  
  516           // / <summary >
  517           // / Fixup th e Procrun  service to  point to  the JVM sp ecified in  the manif est.
  518           // / </summar y>
  519           pu blic stati c void Fix upTomcatSe rviceJvm()
  520           {
  521                string k ey = null;
  522                Registry View regVi ew = Regis tryView.Re gistry64;
  523  
  524                string t omcatServi ceName = T omcatFacad e.TomcatSe rviceName;
  525                Logger() .Info("Tom catService name: " +  tomcatServ iceName);
  526  
  527                if (Busi nessFacade .Is64BitOp eratingSys tem())
  528                {
  529                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  530                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + to mcatServic eName + @" \Parameter s\Java";
  531                }
  532                else
  533                {
  534                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + tomc atServiceN ame + @"\P arameters\ Java";
  535                }
  536  
  537                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  538                {
  539                    usin g (Registr yKey java  = regKey.O penSubKey( key, true) )
  540                    {
  541                         string jvm  = (string )java.GetV alue("Jvm" , null);
  542                         string jav aPath = Ja vaFacade.G etActiveJa vaPath(Jav aFacade.Is ActiveJreI nstalled() );
  543                        
  544                         //Debug.As sert(jvm ! = null);
  545  
  546                         if ((jvm = = null) ||  (!jvm.ToU pper().Con tains(java Path.ToUpp er())))
  547                         {
  548                             jvm =  Path.Combi ne(javaPat h, @"bin\s erver\jvm. dll");
  549                             java.S etValue("J vm", jvm,  RegistryVa lueKind.St ring);
  550                         }
  551                    }
  552                }
  553           }
  554  
  555           // / <summary >
  556           // / Uninstal l the curr ent deprec ated insta llation of  Tomcat as  specifed  by the man ifest
  557           // / </summar y>
  558           pu blic stati c void Uni nstallDepr ecatedTomc at()
  559           {
  560                TomcatPr erequisite  prerequis ite = GetI nstalledDe precatedTo mcatPrereq usite();
  561                if (prer equisite ! = null)
  562                {
  563                    stri ng tomcatI nstallFold er = Tomca tFacade.To mcatInstal lationFold er; // get  the insta ll folder  before the  registry  key this c omes from  is wiped o ut - eithe r by unreg ister or u ninstall
  564  
  565                    if ( prerequisi te.Unregis terFilenam e != null)
  566                    {
  567                         Unregister Tomcat(pre requisite,  tomcatIns tallFolder );
  568                    }
  569  
  570                    Unin stallTomca t(prerequi site, tomc atInstallF older);
  571  
  572                    if ( prerequisi te.DeleteU ninstaller RegistryKe y != null)
  573                    {
  574                         Registry.L ocalMachin e.DeleteSu bKey(prere quisite.De leteUninst allerRegis tryKey, fa lse); // r aise no ex ception if  the subke y does not  exist
  575                    }
  576  
  577                    //   BT 5/22/20 17 Delete  remnant le ft by the  tomcat uni nstaller
  578                    Logg er().Info( "TomcatReg istryKey:  " + prereq uisite.Tom catRegistr yKey);
  579                    if ( prerequisi te.TomcatR egistryKey  != null)
  580                    {
  581                         Registry.L ocalMachin e.DeleteSu bKeyTree(p rerequisit e.TomcatRe gistryKey,  true); //  raise no  exception  if the sub key does n ot exist
  582                    }
  583  
  584                    if ( prerequisi te.DeleteS tartMenuFo lder != nu ll)
  585                    {
  586                         try
  587                         {
  588                             if (Di rectory.Ex ists(prere quisite.De leteStartM enuFolder) )
  589                             {
  590                                 Di rectory.De lete(prere quisite.De leteStartM enuFolder,  true); //  recurse
  591                             }
  592                         }
  593                         catch (Exc eption ex)
  594                         {
  595                             Logger ().Info("E xception w hile delet ing Tomcat  Start Men u Group: "  + ex.Mess age);
  596                         }
  597                    }
  598                }
  599           }
  600  
  601           pu blic stati c bool Che ckAndFixTo mcatUserAc cess()
  602           {
  603                if (!Tom catFacade. TestTomcat UserAccess (TOMCAT_SE RVICE_ACCO UNT_NAME))
  604                {
  605                    Logg er().Info( "Corrupted  TomcatUse rAccess -  deleting u ser and un installing  tomcat");
  606                    if ( TomcatFaca de.DeleteT omcatUser( TOMCAT_SER VICE_ACCOU NT_NAME))
  607                    {
  608                         Logger().I nfo("Check AndFixTomc atUserAcce ss - user  deleted su ccessfully  or doesn' t exist");
  609  
  610                         TomcatFaca de.Uninsta llCurrentT omcat();
  611  
  612                         if (!JavaF acade.Unin stallCurre ntJre())
  613                         {
  614                             Logger ().Info("U nable to u ninstall j ava progra mmatically , please r emove java  and tomca t manually  and reins tall");
  615                             return  false;
  616                         }
  617  
  618                         string vix config = V ixFacade.G etVixConfi gurationDi rectory();
  619  
  620                         if (vixcon fig == nul l)
  621                             vixcon fig = @"c: \vixconfig ";
  622  
  623                         VixConfigu rationPara meters con fig = VixC onfigurati onParamete rs.FromXml (vixconfig );
  624                         if (config  != null)
  625                             VixFac ade.Delete LocalCache Regions(co nfig);
  626  
  627                         return tru e;
  628                    }
  629                    else
  630                    {
  631                         Logger().I nfo("Unabl e to delet e apacheto mcat user.  Delete ap achetomcat  user and  uninstall  java and t omcat manu ally");
  632                         return fal se;
  633                    }
  634                }
  635                else
  636                {
  637                    retu rn true;
  638                }
  639           }
  640  
  641           pu blic stati c bool Tes tTomcatUse rAccess(st ring user)
  642           {
  643                //Nothin g is insta lled - goo d to go, i nstaller w ill create  user and  install to mcat
  644                if (!Acc essContolU tilities.I sUserExist (user) &&  !IsTomcatI nstalled() )  return  true;
  645  
  646                //it's c orrupted i f tomcat s erver is i nstalled b ut no tomc at user
  647                if (!Acc essContolU tilities.I sUserExist (user)) re turn false ;
  648  
  649                //Check  if user ha s write ac cess to th e tomcat l og folder
  650                string t omcatLogsF older = To mcatFacade .TomcatIns tallationF older + "\ \logs"; //  get the i nstall fol der before  the regis try key th is comes f rom is wip ed out - e ither by u nregister  or uninsta ll
  651                if (!IsU serTomcatD irectoryAc cessContro l(user, to mcatLogsFo lder)) ret urn false;
  652  
  653                return t rue;
  654           }
  655  
  656           pr ivate stat ic bool Is UserTomcat DirectoryA ccessContr ol(string  user, stri ng tomcatL ogsFolder)
  657           {
  658                Director yInfo di =  new Direc toryInfo(t omcatLogsF older);
  659                Director ySecurity  acl = di.G etAccessCo ntrol(Acce ssControlS ections.Al l);
  660                Authoriz ationRuleC ollection  rules = ac l.GetAcces sRules(tru e, true, t ypeof(NTAc count));
  661  
  662                //Go thr ough the r ules retur ned from t he Directo rySecurity
  663                foreach  (Authoriza tionRule r ule in rul es)
  664                {
  665                    //If  we find o ne that ma tches the  identity w e are look ing for
  666                    if ( rule.Ident ityReferen ce.Value.E quals(user , StringCo mparison.C urrentCult ureIgnoreC ase))
  667                    {
  668                         var filesy stemAccess Rule = (Fi leSystemAc cessRule)r ule;
  669  
  670                         //Cast to  a FileSyst emAccessRu le to chec k for acce ss rights
  671                         if ((files ystemAcces sRule.File SystemRigh ts & FileS ystemRight s.WriteDat a) > 0 &&  filesystem AccessRule .AccessCon trolType ! = AccessCo ntrolType. Deny)
  672                         {
  673                             return  true;
  674                         }
  675                    }
  676                }
  677  
  678                return f alse;
  679           }
  680  
  681  
  682           pu blic stati c bool Del eteTomcatU ser(string  user)
  683           {
  684                if (!Acc essContolU tilities.I sUserExist (user)) re turn true;
  685  
  686                return A ccessConto lUtilities .DeleteUse rAccount(u ser);
  687           }
  688  
  689           // / <summary >
  690           // / Uninstal l the curr ent instal lation of  Tomcat as  specifed b y the mani fest
  691           // / </summar y>
  692           pu blic stati c bool Uni nstallCurr entTomcat( )
  693           {
  694                bool res ult = fals e;
  695                TomcatPr erequisite  prerequis ite = Mani fest.Activ eTomcatPre requisite;
  696  
  697                if (prer equisite ! = null)
  698                {
  699                    stri ng tomcatI nstallFold er = Tomca tFacade.To mcatInstal lationFold er; // get  the insta ll folder  before the  registry  key this c omes from  is wiped o ut - eithe r by unreg ister or u ninstall
  700  
  701                    try
  702                    {
  703                         //Unregist er tomcat  service
  704                         if (prereq uisite.Unr egisterFil ename != n ull)
  705                         {
  706                             Unregi sterTomcat (prerequis ite, tomca tInstallFo lder);
  707                         }
  708  
  709                    }
  710                    catc h (Excepti on e)
  711                    {
  712                         Logger().I nfo("Excep tion while  unregiste ring Tomca t service.  Exception : " + e.Me ssage);
  713                    }
  714  
  715                    try
  716                    {
  717  
  718                         UninstallT omcat(prer equisite,  tomcatInst allFolder) ;
  719                         result = t rue;
  720                    }
  721                    catc h (Excepti on ex)
  722                    {
  723                         Logger().I nfo("Excep tion while  installin g Tomcat.  Exception:  " + ex.Me ssage);
  724                         return fal se;
  725                    }
  726                }
  727  
  728                return r esult;
  729           }
  730  
  731  
  732           #e ndregion
  733  
  734           #r egion priv ate method s
  735  
  736  
  737           // / <summary >
  738           // / Uninstal ls Apache  Tomcat.
  739           // / </summar y>
  740           // / <param n ame="prere quisite">T he prerequ isite whic h hold Tom cat uninst all inform ation.</pa ram>
  741           // / <remarks ></remarks >
  742           pr ivate stat ic void Un installTom cat(Tomcat Prerequisi te prerequ isite, str ing tomcat InstallFol der)
  743           {
  744                string u ninstaller Filename =  prerequis ite.UnInst allerFilen ame;
  745                string u ninstaller Filespec =  Path.Comb ine(tomcat InstallFol der, unins tallerFile name);
  746  
  747                System.D iagnostics .Process e xternalPro cess = new  System.Di agnostics. Process();
  748                external Process.St artInfo.Fi leName = u ninstaller Filespec;
  749                external Process.St artInfo.Ar guments =  prerequisi te.UnInsta llerArgume nts;
  750                external Process.St artInfo.Us eShellExec ute = fals e;
  751                external Process.St artInfo.Cr eateNoWind ow = true;
  752                external Process.St art();
  753                do
  754                {
  755                    Thre ad.Sleep(5 00);
  756                    exte rnalProces s.Refresh( );
  757                } while  (!external Process.Ha sExited);
  758                Thread.S leep(3000) ; // Allow  windows t o complete  any file  deletes
  759                // unfor tunately e ven throug h the proc ess is rep orted as h aving exit ed, window s is still  catching  up on the  file delet es
  760                // this  can cause  errors in  the direct ory delete  operation
  761                do
  762                {
  763                    try
  764                    {
  765                         Directory. Delete(tom catInstall Folder, tr ue);
  766                    }
  767                    catc h (System. IO.IOExcep tion) { ;  }
  768                }
  769                while (D irectory.E xists(tomc atInstallF older));
  770           }
  771  
  772           pr ivate stat ic void Un registerTo mcat(Tomca tPrerequis ite prereq uisite, st ring tomca tInstallFo lder)
  773           {
  774                if (prer equisite.U nregisterF ilename !=  null && p rerequisit e.Unregist erArgument s != null)
  775                {
  776                    stri ng unregis terFilenam e = prereq uisite.Unr egisterFil ename;
  777                    stri ng unregis terFilespe c = Path.C ombine(tom catInstall Folder, un registerFi lename);
  778  
  779                    Syst em.Diagnos tics.Proce ss externa lProcess =  new Syste m.Diagnost ics.Proces s();
  780                    exte rnalProces s.StartInf o.FileName  = unregis terFilespe c;
  781                    exte rnalProces s.StartInf o.Argument s = prereq uisite.Unr egisterArg uments;
  782                    exte rnalProces s.StartInf o.UseShell Execute =  false;
  783                    exte rnalProces s.StartInf o.CreateNo Window = t rue;
  784                    exte rnalProces s.Start();
  785                    do
  786                    {
  787                         Thread.Sle ep(500);
  788                         externalPr ocess.Refr esh();
  789                    } wh ile (!exte rnalProces s.HasExite d);
  790                    Logg er().Info( "Manually  unregister ed Tomcat  service: "  + prerequ isite.Unre gisterArgu ments);
  791                }
  792           }
  793  
  794           // / <summary >
  795           // / Gets the  ammount o f physical  memory in stalled in  bytes.
  796           // / </summar y>
  797           // / <returns >The ammou nt of phys ical memor y installe d in bytes </returns>
  798           pu blic stati c ulong Ge tPhysicalM emorySizeI nBytes()
  799           {
  800                ulong ph ysicalMemo ry = 0;
  801                MEMORYST ATUSEX mem stat = new  MEMORYSTA TUSEX();
  802                try
  803                {
  804                    if ( GlobalMemo ryStatusEx (memstat))
  805                    {
  806                         physicalMe mory = mem stat.ullTo talPhys;
  807                    }
  808                }
  809                catch (E xception e x)
  810                {
  811                    Logg er().Error ("Error ma king kerne l32 Global MemoryStat usEx call" );
  812                    Logg er().Error (ex.Messag e);
  813                }
  814  
  815                if (phys icalMemory  == 0)
  816                {
  817                    stri ng errmsg  = "Install er was not  able to d etermine t he amount  of physica l memory i n the syst em.";
  818                    Logg er().Error (errmsg);  // should  never happ en
  819                    thro w new Exce ption(errm sg);
  820                }
  821  
  822                return p hysicalMem ory;
  823           }
  824  
  825           // / <summary >
  826           // / Gets the  installed  deprecate d Tomcat p rerequsite .
  827           // / </summar y>
  828           // / <returns >The depre cated Tomc at prerequ isite if f ound.</ret urns>
  829           // / <remarks >Can retur n null.</r emarks>
  830           pr ivate stat ic TomcatP rerequisit e GetInsta lledDeprec atedTomcat Prerequsit e()
  831           {
  832                Debug.As sert(IsTom catInstall ed() == tr ue);
  833                string i nstalledTo mcatVersio n = Instal ledTomcatV ersion;
  834                TomcatPr erequisite  tomcatPre requisite  = null;
  835                foreach  (TomcatPre requisite  prerequisi te in Mani fest.Depre catedTomca tPrerequis ites)
  836                {
  837                    if ( IsPrerequi siteInstal led(prereq uisite))
  838                    {
  839                         tomcatPrer equisite =  prerequis ite;
  840                         break;
  841                    }
  842                }
  843                return t omcatPrere quisite;
  844           }
  845  
  846           
  847           // / <summary >
  848           // / Determin es whether  version T omcat spec ified by t he provide d prerequi site is in stalled.
  849           // / </summar y>
  850           // / <param n ame="prere quisite">T he prerequ isite spec ifying the  Tomcat ve rsion to c heck for.< /param>
  851           // / <returns ><c>true</ c> if spec ified vers ion of Tom cat is ins talled; ot herwise, < c>false</c >.</return s>
  852           pr ivate stat ic bool Is Prerequisi teInstalle d(TomcatPr erequisite  prerequis ite)
  853           {
  854                bool isI nstalled =  false;
  855                string i nstalledVe rsion = nu ll;
  856                string k ey = null;
  857                Registry View regVi ew = Regis tryView.Re gistry64;
  858  
  859                if (Busi nessFacade .Is64BitOp eratingSys tem() && p rerequisit e.Native = = NativeTy pe.x86)
  860                {
  861                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Tomcat";
  862                }
  863                else //  native ins tallation  - either x 86 or x64
  864                {
  865                    key  = @"SOFTWA RE\Apache  Software F oundation\ Tomcat";
  866                }
  867                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  868                {
  869                    usin g (Registr yKey tomca t = regKey .OpenSubKe y(key, tru e))
  870                    {
  871                         if (tomcat  != null & & tomcat.S ubKeyCount  > 0)
  872                         {
  873                             string [] subkeys  = tomcat. GetSubKeyN ames(); //  try and r emain vers ion indepe ndent
  874                             Debug. Assert(sub keys.Lengt h == 1);
  875                             key +=  @"\" + su bkeys[0];
  876                             using  (RegistryK ey tomcatV ersion = r egKey.Open SubKey(key , true))
  877                             {
  878                                 ob ject o = t omcatVersi on.GetValu e("Version ");
  879                                 if  (o != nul l)
  880                                 {
  881                                      installe dVersion =  o.ToStrin g();
  882                                 }
  883                             }
  884                         }
  885                    }
  886                }
  887                // later  versions  of Tomcat  (somewhere  after 6.0 .20) moved  the locat ion of the  "Version"  value dow n a level
  888                if (inst alledVersi on == null )
  889                {
  890                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  891                    {
  892                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(key,  true))
  893                         {
  894                             if (to mcat != nu ll && tomc at.SubKeyC ount > 0)
  895                             {
  896                                 st ring[] sub keys = tom cat.GetSub KeyNames() ; // try a nd remain  version in dependent
  897                                 De bug.Assert (subkeys.L ength == 1 );
  898                                 ke y += @"\"  + subkeys[ 0];
  899                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (key, true ))
  900                                 {
  901                                      object o  = tomcatV ersion.Get Value("Ver sion");
  902                                      if (o !=  null)
  903                                      {
  904                                          inst alledVersi on = o.ToS tring();
  905                                      }
  906                                 }
  907                             }
  908                         }
  909                    }
  910                }
  911  
  912                if (inst alledVersi on != null  && instal ledVersion  == prereq uisite.Ver sion)
  913                {
  914                    isIn stalled =  true;
  915                }
  916  
  917                return i sInstalled ;
  918           }
  919  
  920           // / <summary >
  921           // / Gets the  installed  Tomcat ve rsion as a  string.
  922           // / </summar y>
  923           // / <param n ame="baseR egKey">The  registry  key as a s tring that  is used a s the star ting point  of the To mcat versi on search. </param>
  924           // / <returns >The insta lled Tomca t version  as a strin g.</return s>
  925           pr ivate stat ic string  GetInstall edTomcatVe rsion(stri ng baseReg Key)
  926           {
  927                string i nstalledVe rsion = nu ll;
  928                Registry View regVi ew = Regis tryView.Re gistry64;
  929                if (Regi stryUtilit ies.DoesRe gKeyExist( baseRegKey ) == true)
  930                {
  931                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  932                    {
  933                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(base RegKey, tr ue))
  934                         {
  935                             if (to mcat != nu ll && tomc at.SubKeyC ount > 0)
  936                             {
  937                                 st ring[] sub keys = tom cat.GetSub KeyNames() ; // try a nd remain  version in dependent
  938                                 De bug.Assert (subkeys.L ength == 1 );
  939                                 ba seRegKey + = @"\" + s ubkeys[0];
  940                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (baseRegKe y, true))
  941                                 {
  942                                      object o  = tomcatV ersion.Get Value("Ver sion");
  943                                      if (o !=  null)
  944                                      {
  945                                          inst alledVersi on = o.ToS tring();
  946                                      }
  947                                 }
  948                             }
  949                         }
  950                    }
  951                    // l ater versi ons of Tom cat (somew here after  6.0.20) m oved the l ocation of  the "Vers ion" value  down a le vel
  952                    if ( installedV ersion ==  null)
  953                    {
  954                         using (Reg istryKey r egKey = Re gistryKey. OpenBaseKe y(Registry Hive.Local Machine, r egView))
  955                         {
  956                             using  (RegistryK ey tomcat  = regKey.O penSubKey( baseRegKey , true))
  957                             {
  958                                 De bug.Assert (tomcat !=  null);
  959                                 if  (tomcat ! = null &&  tomcat.Sub KeyCount >  0)
  960                                 {
  961                                      string[]  subkeys =  tomcat.Ge tSubKeyNam es(); // t ry and rem ain versio n independ ent
  962                                      Debug.As sert(subke ys.Length  == 1);
  963                                      baseRegK ey += @"\"  + subkeys [0];
  964                                      using (R egistryKey  tomcatVer sion = reg Key.OpenSu bKey(baseR egKey, tru e))
  965                                      {
  966                                          obje ct o = tom catVersion .GetValue( "Version") ;
  967                                          if ( o != null)
  968                                          {
  969                                               installedV ersion = o .ToString( );
  970                                          }
  971                                      }
  972                                 }
  973                             }
  974                         }
  975                    }
  976                }
  977  
  978                return i nstalledVe rsion;
  979           }
  980  
  981           // / <summary >
  982           // / Gets the  Tomcat in stallation  dirspec.
  983           // / </summar y>
  984           // / <param n ame="baseR egKey">The  registry  key as a s tring that  is used a s the star ting point  of the in stallation  folder se arch.</par am>
  985           // / <returns >The Tomca t installa tion dirsp ec.</retur ns>
  986           pr ivate stat ic string  GetTomcatI nstallatio nFolder(st ring baseR egKey)
  987           {
  988                string i nstallatio nFolder =  null;
  989                Registry View regVi ew = Regis tryView.Re gistry64;
  990  
  991                if (Regi stryUtilit ies.DoesRe gKeyExist( baseRegKey ))
  992                {
  993                    Logg er().Info( "Base Regi stry Key E xist.");
  994                    Debu g.Assert(T omcatFacad e.IsTomcat Installed( ) == true) ;
  995                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  996                    {
  997                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(base RegKey, tr ue))
  998                         {
  999                             Debug. Assert(tom cat.SubKey Count > 0) ;
  1000                             string [] subkeys  = tomcat. GetSubKeyN ames(); //  try and r emain vers ion indepe ndent
  1001                             Debug. Assert(sub keys.Lengt h == 1);
  1002                             if (su bkeys.Leng th > 0)
  1003                             {
  1004                                 ba seRegKey + = @"\" + s ubkeys[0];
  1005                                 Lo gger().Inf o("Reg Key  with appe nded Subke y: " + bas eRegKey);
  1006                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (baseRegKe y, true))
  1007                                 {
  1008                                      object o  = tomcatV ersion.Get Value("Ins tallPath") ;
  1009                                      if (o !=  null)
  1010                                      {
  1011                                          inst allationFo lder = o.T oString();
  1012                                      }
  1013                                 }
  1014                             }
  1015                         }
  1016                    }
  1017                    // l ater versi ons of Tom cat (somew here after  6.0.20) m oved the l ocation of  the "Inst allPath" v alue down  a level
  1018                    if ( installati onFolder = = null)
  1019                    {
  1020                         using (Reg istryKey r egKey = Re gistryKey. OpenBaseKe y(Registry Hive.Local Machine, r egView))
  1021                         {
  1022                             using  (RegistryK ey tomcat  = regKey.O penSubKey( baseRegKey , true))
  1023                             // ope n the last  key where  we were l ooking for  InstallPa th
  1024                             {
  1025                                 if  (tomcat ! = null &&  tomcat.Sub KeyCount >  0)
  1026                                 {
  1027                                      string[]  subkeys =  tomcat.Ge tSubKeyNam es(); // t ry and rem ain versio n independ ent
  1028                                      Debug.As sert(subke ys.Length  == 1);
  1029                                      baseRegK ey += @"\"  + subkeys [0]; // lo ok one sub key deeper
  1030                                      Logger() .Info("Reg  Key with  appended S ubkey: " +  baseRegKe y);
  1031                                      using (R egistryKey  tomcatVer sion = reg Key.OpenSu bKey(baseR egKey, tru e))
  1032                                      {
  1033                                          obje ct o = tom catVersion .GetValue( "InstallPa th");
  1034                                          if ( o != null)
  1035                                          {
  1036                                               installati onFolder =  o.ToStrin g();
  1037                                          }
  1038                                      }
  1039                                 }
  1040                             }
  1041                         }
  1042                    }
  1043                }
  1044                return i nstallatio nFolder;
  1045           }
  1046  
  1047           #e ndregion
  1048  
  1049       }
  1050   }