170. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/10/2017 1:01:48 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.

170.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\VixInstallerSolution2013.root\VixInstallerSolution2013\VixInstallerBusiness TomcatFacade.cs Thu Jun 29 17:22:28 2017 UTC
2 C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\VixInstallerSolution2013.root\VixInstallerSolution2013\VixInstallerBusiness TomcatFacade.cs Thu Jul 6 15:07:19 2017 UTC

170.2 Comparison summary

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

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

170.4 Active regular expressions

No regular expressions were active.

170.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  
  12   namespace  gov.va.med .imaging.e xchange.Vi xInstaller .business
  13   {
  14  
  15       public  static cl ass Tomcat Facade
  16       {
  17           // / <summary >
  18           // / Retrieve  a logger  for this c lass.
  19           // / </summar y>
  20           // / <returns >A logger  as a ILog  interface. </returns>
  21           pr ivate stat ic ILog Lo gger()
  22           {
  23                return L ogManager. GetLogger( typeof(Tom catFacade) .Name);
  24           }
  25           
  26           [S tructLayou t(LayoutKi nd.Sequent ial, CharS et = CharS et.Auto)]
  27           pr ivate clas s MEMORYST ATUSEX
  28           {
  29                public u int dwLeng th;
  30                public u int dwMemo ryLoad;
  31                public u long ullTo talPhys;
  32                public u long ullAv ailPhys;
  33                public u long ullTo talPageFil e;
  34                public u long ullAv ailPageFil e;
  35                public u long ullTo talVirtual ;
  36                public u long ullAv ailVirtual ;
  37                public u long ullAv ailExtende dVirtual;
  38                public M EMORYSTATU SEX()
  39                {
  40                    this .dwLength  = (uint)Ma rshal.Size Of(typeof( MEMORYSTAT USEX));
  41                }
  42           }
  43           
  44           [r eturn: Mar shalAs(Unm anagedType .Bool)]
  45           [D llImport(" kernel32.d ll", CharS et = CharS et.Auto, S etLastErro r = true)]
  46           st atic exter n bool Glo balMemoryS tatusEx([I n, Out] ME MORYSTATUS EX lpBuffe r);
  47  
  48           pr ivate stat ic readonl y String T OMCAT_SERV ICE_ACCOUN T_NAME = " apachetomc at";
  49           pr ivate stat ic readonl y String T OMCAT_ADMI N_ACCOUNT_ NAME = "ad min";
  50           pr ivate stat ic readonl y String T OMCAT_CONF IGURATION_ FOLDER = " conf";
  51           pr ivate stat ic readonl y String T OMCAT_EXEC UTABLE_FOL DER = "bin ";
  52           pr ivate stat ic readonl y String T OMCAT_LIB_ FOLDER = " lib";
  53           pr ivate stat ic readonl y String T OMCAT_LOG_ FOLDER = " logs";
  54           pr ivate stat ic readonl y String T OMCAT_LOG_ FOLDER_ENC RYPTED = @ "logs\secu re";
  55           pr ivate stat ic readonl y String T OMCAT_WEBA PP_FOLDER  = "webapps ";
  56           pr ivate stat ic readonl y String T OMCAT_AXIS 2_WEBAPP_F OLDER = @" webapps\ax is2\WEB-IN F\services ";
  57           pr ivate stat ic readonl y String T OMCAT_USER S_FILENAME  = @"tomca t-users.xm l";
  58  
  59           #r egion prop erties
  60           pu blic stati c string T omcatServi ceAccountN ame { get  { return T OMCAT_SERV ICE_ACCOUN T_NAME; }  }
  61           pu blic stati c string T omcatAdmin AccountNam e { get {  return TOM CAT_ADMIN_ ACCOUNT_NA ME; } }
  62           pu blic stati c VixManif est Manife st { get;  set; }
  63           pu blic stati c string T omcatConfi gurationFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_C ONFIGURATI ON_FOLDER) ; } }
  64           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); } }
  65           pu blic stati c string T omcatLibFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_L IB_FOLDER) ; } }
  66           pu blic stati c string T omcatLogFo lder { get  { return  Path.Combi ne(TomcatF acade.Tomc atInstalla tionFolder , TOMCAT_L OG_FOLDER) ; } }
  67           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);  } }
  68           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); } }
  69           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); } }
  70           pu blic stati c string S erviceAcco untUsernam e { get {  return TOM CAT_SERVIC E_ACCOUNT_ NAME; } }
  71           pu blic stati c string A ctiveTomca tVersion {  get { ret urn Manife st.ActiveT omcatPrere quisite.Ve rsion; } }
  72           pu blic stati c string I nstallerFi lespec { g et { retur n Manifest .ActiveTom catPrerequ isite.Inst allerFiles pec; } }
  73  
  74           // / <summary >
  75           // / Gets the  Tomcat Wi ndows serv ice name.
  76           // / </summar y>
  77           pu blic stati c string T omcatServi ceName
  78           {
  79                get
  80                {
  81                    stri ng service Name = nul l;
  82                    Debu g.Assert(T omcatFacad e.IsTomcat Installed( ) == true) ;
  83                    stri ng key = n ull;
  84                    Regi stryView r egView = R egistryVie w.Registry 64;
  85                    if ( BusinessFa cade.Is64B itOperatin gSystem())
  86                    {
  87                         // Procrun  key will  be install ed under W ow6432Node  key - eve n if Tomca t 6.0.35 i s installe d natively
  88                         key = @"SO FTWARE\Wow 6432Node\A pache Soft ware Found ation\Proc run 2.0";
  89                    }
  90                    else
  91                    {
  92                         key = @"SO FTWARE\Apa che Softwa re Foundat ion\Procru n 2.0";
  93                    }
  94                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  95                    {
  96                         using (Reg istryKey p rocrun = r egKey.Open SubKey(key , true))
  97                         {
  98                             Debug. Assert(pro crun != nu ll);
  99                             Debug. Assert(pro crun.SubKe yCount > 0 );
  100                             string [] subkeys  = procrun .GetSubKey Names();
  101                             servic eName = su bkeys[0];
  102                         }
  103                         return ser viceName;
  104                    }
  105                }
  106           }
  107  
  108           // / <summary >
  109           // / Gets the  tomcat in stallation  folder.
  110           // / </summar y>
  111           pu blic stati c string T omcatInsta llationFol der
  112           {
  113                get
  114                {
  115                    stri ng install ationFolde r = GetTom catInstall ationFolde r(@"SOFTWA RE\Apache  Software F oundation\ Tomcat");
  116                    Logg er().Info( "Installat ion Folder  outside o f IF State ment: " +  installati onFolder);
  117                    if ( installati onFolder = = null)
  118                    {
  119                         Debug.Asse rt(Busines sFacade.Is 64BitOpera tingSystem () == true );
  120                         installati onFolder =  GetTomcat Installati onFolder(@ "SOFTWARE\ Wow6432Nod e\Apache S oftware Fo undation\T omcat");
  121                         Logger().I nfo("Insta llation Fo lder insid e of IF St atement: "  + install ationFolde r);
  122                    }
  123                    retu rn install ationFolde r;                 
  124                }
  125           }
  126  
  127           // / <summary >
  128           // / Gets the  installed  deprecate d tomcat v ersion.
  129           // / </summar y>
  130           // / <remarks >Can retur n null.</r emarks>
  131           pu blic stati c string D eprecatedT omcatVersi on
  132           {
  133                get
  134                {
  135                    Tomc atPrerequi site prere quisite =  GetInstall edDeprecat edTomcatPr erequsite( );
  136                    retu rn prerequ isite == n ull ? null  : prerequ isite.Vers ion;
  137                }
  138           }
  139  
  140           // / <summary >
  141           // / Gets the  installed  tomcat ve rsion as a  string.
  142           // / </summar y>
  143           // / <remarks >Could ret urn null i f Tomcat i s not inst alled.</re marks>
  144           pu blic stati c string I nstalledTo mcatVersio n
  145           {
  146                get
  147                {
  148                    stri ng install edVersion  = GetInsta lledTomcat Version(@" SOFTWARE\A pache Soft ware Found ation\Tomc at");
  149                    if ( installedV ersion ==  null)
  150                    {
  151                         Debug.Asse rt(Busines sFacade.Is 64BitOpera tingSystem () == true );
  152                         installedV ersion = G etInstalle dTomcatVer sion(@"SOF TWARE\Wow6 432Node\Ap ache Softw are Founda tion\Tomca t");
  153                    }
  154                    retu rn install edVersion;                  
  155                }
  156           }
  157  
  158           #e ndregion
  159  
  160           #r egion publ ic methods
  161  
  162  
  163           // / <summary >
  164           // / Disables  the tomca t monitor  (tomcat6w. exe) from  running wh en logging  in under  the user c redentials  where Tom cat was in stalled.
  165           // / </summar y>
  166           // / <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
  167           // / that thi s method i s tied to  Tomcat 6.< /remarks>
  168           pu blic stati c void Dis ableTomcat Monitor()
  169           {
  170                string k ey = @"Sof tware\Micr osoft\Wind ows\Curren tVersion\R un";
  171                Registry View regVi ew = Regis tryView.Re gistry64;
  172                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Cur rentUser,  regView))
  173                {
  174                    usin g (Registr yKey run =  regKey.Op enSubKey(k ey, true))
  175                    {
  176                         if (run !=  null)
  177                         {
  178                             if (ru n.GetValue ("ApacheTo mcatMonito r6.0_Tomca t6") != nu ll)
  179                             {
  180                                 ru n.DeleteVa lue("Apach eTomcatMon itor6.0_To mcat6");
  181                             }
  182                         }
  183                    }
  184                }
  185           }
  186  
  187           // / <summary >
  188           // / 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.
  189           // / </summar y>
  190           // / <returns ><c>true</ c> if Tomc at is inst alled; oth erwise <c> false</c>< /returns>
  191           pu blic stati c bool IsT omcatInsta lled()
  192           {
  193                Logger() .Info("Ent ered IsTom catInstall ed() metho d.");
  194                // 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
  195                // subke y added un der the To mcat subke y which co mplicates  testing fo r installa tion.
  196                // 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
  197                bool isI nstalled =  false;
  198                string k ey = null;
  199                Registry View regVi ew = Regis tryView.Re gistry64;
  200                if (Busi nessFacade .Is64BitOp eratingSys tem())
  201                {
  202                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.35 is in stalled na tively
  203                    // T ODO: This  must be ch ecked for  each versi on of Tomc at that we  support
  204                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n";
  205                }
  206                else
  207                {
  208                    key  = @"SOFTWA RE\Apache  Software F oundation" ;
  209                }
  210                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  211                {
  212                    usin g (Registr yKey apach e = regKey .OpenSubKe y(key, tru e))
  213                    {
  214                         if (apache  != null)
  215                         {
  216                             if (ap ache.SubKe yCount > 0 ) // Tomca t key hang s around a fter an un install
  217                             {
  218                                 st ring[] sub keys = apa che.GetSub KeyNames() ;
  219                                 fo reach (str ing subkey  in subkey s)
  220                                 {
  221                                      if (subk ey.ToLower ().StartsW ith("procr un"))
  222                                      {
  223                                          isIn stalled =  true;
  224                                          brea k;
  225                                      }
  226                                 }
  227                             }
  228                         }
  229                    }
  230                }
  231                Logger() .Info("Tom cat is ins talled: "  + isInstal led);
  232                return i sInstalled ;
  233           }
  234  
  235           // / <summary >
  236           // / Disable  stdout log ging for T omcat
  237           // / </summar y>
  238           pu blic stati c void Dis ableStdOut Logging()
  239           {
  240                string k ey = null;
  241                Registry View regVi ew = Regis tryView.Re gistry64;
  242                if (Busi nessFacade .Is64BitOp eratingSys tem())
  243                {
  244                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  245                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Log";
  246                }
  247                else
  248                {
  249                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Log";
  250                }
  251  
  252                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  253                {
  254                    usin g (Registr yKey tomca t = regKey .OpenSubKe y(key, tru e))
  255                    {
  256                         if (tomcat  != null)
  257                         {
  258                             tomcat .DeleteVal ue("StdOut put", fals e);
  259                             tomcat .DeleteVal ue("StdErr or", false );
  260                         }
  261                    }
  262                }
  263           }
  264  
  265           // / <summary >
  266           // / Returns  true if th e Tomcat s ervice is  installed
  267           // / </summar y>
  268           // / <returns ><c>true</ c>if Tomca t service  is install ed; otherw ise <c>fal se</c>.</r eturns>
  269           // / <remarks >Used to c heck to se e if Tomca t was unin stalled su cessfully. </remarks>
  270           pu blic stati c bool IsD eprecatedT omcatServi ceInstalle d()
  271           {
  272                bool isI nstalled =  false;
  273                foreach  (TomcatPre requisite  prerequisi te in Mani fest.Depre catedTomca tPrerequis ites)
  274                {
  275                    if ( ServiceUti lities.IsN onDriverSe rviceInsta lled(prere quisite.Se rviceName)  == true)
  276                    {
  277                         isInstalle d = true;
  278                         break;
  279                    }
  280                }
  281                return i sInstalled ;
  282           }
  283  
  284           // / <summary >
  285           // / 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 .
  286           // / </summar y>
  287           // / <returns ><c>true</ c> if the  required v ersion Apa che Tomcat  is instal led; other wise <c>fa lse</c>.</ returns>
  288           pu blic stati c bool IsA ctiveTomca tVersionIn stalled()
  289           {
  290                Logger() .Info("Ent ered IsAct iveTomcatV ersionInst alled() me thod.");
  291                bool isI nstalled =  false;
  292  
  293                if (Tomc atFacade.I sTomcatIns talled())
  294                {
  295                    if ( IsPrerequi siteInstal led(Manife st.ActiveT omcatPrere quisite))
  296                    {
  297                         isInstalle d = true;
  298                    }
  299                }
  300                Logger() .Info("Tom cat is ins talled: "  + isInstal led);
  301                return i sInstalled ;
  302           }
  303  
  304           // / <summary >
  305           // / 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.
  306           // / </summar y>
  307           // / <returns ><c>true</ c> if the  deprecated  version A pache Tomc at is inst alled; oth erwise <c> false</c>. </returns>
  308           pu blic stati c bool IsD eprecatedT omcatVersi onInstalle d()
  309           {
  310                bool isI nstalled =  false;
  311  
  312                if (Tomc atFacade.I sTomcatIns talled())
  313                {
  314                    if ( GetInstall edDeprecat edTomcatPr erequsite( ) != null)
  315                    {
  316                         isInstalle d = true;
  317                    }
  318                }
  319                return i sInstalled ;
  320           }
  321  
  322           // / <summary >
  323           // / Gets the  tomcat wo rking fold er.
  324           // / </summar y>
  325           // / <param n ame="siteN umber">The  site numb er that is  part of t he owrking  folder na ming patte rn.</param >
  326           // / <returns >The fully  qualified  working f older.</re turns>
  327           pu blic stati c string G etTomcatWo rkFolder(s tring site Number)
  328           {
  329                  String wor kPath = @" work\Catal ina\" + si teNumber +  ". URL         ";
  330                return P ath.Combin e(TomcatFa cade.Tomca tInstallat ionFolder,  workPath) ;
  331           }
  332  
  333           // / <summary >
  334           // / Parses t he existin g tomcat a dmin passw ord out of  tomcat-us ers.xml.
  335           // / </summar y>
  336           // / <returns >tomcat ad min passwo rd</return s>
  337           pu blic stati c string G etExisting TomcatAdmi nPassword( )
  338           {
  339                string t omcatAdmin Password =  null;
  340                String t omcatUsers Path = Pat h.Combine( TomcatFaca de.TomcatC onfigurati onFolder,  TOMCAT_USE RS_FILENAM E);
  341                if (File .Exists(to mcatUsersP ath))
  342                {
  343                    XmlD ocument us ers = new  XmlDocumen t();
  344                    user s.Load(tom catUsersPa th);
  345                    XmlN ode admin  = users.Se lectSingle Node("tomc at-users/u ser[@usern ame='admin ']");
  346                    if ( admin == n ull)
  347                    {
  348                         admin = us ers.Select SingleNode ("tomcat-u sers/user[ @name='adm in']"); //  bug in pr evious ver sions - wr ote name a ttribute i nstead of  username
  349                    }
  350                    Debu g.Assert(a dmin != nu ll);
  351                    tomc atAdminPas sword = ad min.Attrib utes["pass word"].Val ue.Trim();
  352                    Debu g.Assert(t omcatAdmin Password ! = null);
  353                }
  354                return t omcatAdmin Password;
  355           }
  356  
  357           // / <summary >
  358           // / Creates  the Apache  Tomcat co nfiguratio n file tha t defines  users and  roles. As  part of th is process
  359           // / creates  a user spe cified acc ount using  the passe d credenti als which  will have  the admin  and manage r roles.
  360           // / </summar y>
  361           // / <param n ame="usern ame">The u sername th at will be  given the  admin and  manager r oles.</par am>
  362           // / <param n ame="passw ord">The p assword as sociated w ith the us ername.</p aram>
  363           pu blic stati c void Con figureTomc atUsers(IV ixConfigur ationParam eters conf ig)
  364           {
  365                StringBu ilder sb =  new Strin gBuilder() ;
  366                sb.Appen dLine("<to mcat-users >");
  367                sb.Appen dLine("\t< role rolen ame=\"clin ical-displ ay-user\"/ >");
  368                sb.Appen dLine("\t< role rolen ame=\"admi nistrator\ "/>");
  369                sb.Appen dLine("\t< role rolen ame=\"deve loper\"/>" );
  370                sb.Appen dLine("\t< role rolen ame=\"tomc at\"/>");
  371                sb.Appen dLine("\t< role rolen ame=\"mana ger\"/>");
  372                sb.Appen dLine("\t< role rolen ame=\"peer -vixs\"/>" );
  373                sb.Appen dLine("\t< role rolen ame=\"admi n\"/>");
  374                sb.Appen dLine("\t< role rolen ame=\"vist a-user\"/> ");
  375                sb.Appen dLine("\t< role rolen ame=\"test er\"/>");
  376                sb.Appen dLine("\t< user usern ame=\"alex delarge\"  password=\ "655321\"  roles=\"cl inical-dis play-user\ "/>");
  377                sb.Appen dLine("\t< user usern ame=\"vixl og\" passw ord=\"tach ik0ma\" ro les=\"admi nistrator, tester\"/> ");
  378                sb.Appen dLine("\t< user usern ame=\"vixs \" passwor d=\"vixs\"  roles=\"p eer-vixs\" />");
  379                sb.Appen dLine("\t< user usern ame=\"roiu ser\" pass word=\"asX Ro1o1\" ro les=\"clin ical-displ ay-user\"/ >");
  380                string p w = config .TomcatAdm inPassword ;
  381                if (pw = = null)
  382                {
  383                    pw =  config.Si teAbbrevia tion.Trim( ) + "x14y2 ";
  384                }
  385                sb.Appen dFormat("\ t<user use rname=\"{0 }\" passwo rd=\"{1}\"  roles=\"a dmin,manag er\" />",  TOMCAT_ADM IN_ACCOUNT _NAME, pw) ;
  386                sb.Appen d(Environm ent.NewLin e);
  387                sb.Appen dLine("</t omcat-user s>");
  388  
  389                String t omcatUsers Path = Pat h.Combine( TomcatFaca de.TomcatC onfigurati onFolder,  TOMCAT_USE RS_FILENAM E);
  390                using (T extWriter  tw = new S treamWrite r(tomcatUs ersPath))
  391                {
  392                    tw.W rite(sb.To String());
  393                }
  394           }
  395  
  396           // / <summary >
  397           // / Perform  the servic e setup th at would o rdinarily  be done us ing tomcat 5w.exe. 
  398           // / Currentl y this set s memory o ptions for  the JVM,  and config ures servi ce failure  actions
  399           // / </summar y>
  400           pu blic stati c void Con figureTomc atService( IVixConfig urationPar ameters co nfig)
  401           {
  402                Configur eTomcatJvm Memory(con fig);
  403                // if ru nning on a  HAC node  then do no t configur e recovery  options f or the Tom cat servic e.
  404                if (Clus terFacade. IsServerCl usterNode( ) == false )
  405                {
  406                    Serv iceUtiliti es.SetServ iceFailure Actions(To mcatFacade .TomcatSer viceName);
  407                }
  408           }
  409  
  410           // / <summary >
  411           // / Set Tomc at JVM mem ory usage
  412           // / </summar y>
  413           // / <remarks >This meth od makes d ecisions b ased on th e allowed  process si ze on the  operating  system.</r emarks>
  414           pu blic stati c void Con figureTomc atJvmMemor y(IVixConf igurationP arameters  config)
  415           {
  416                ulong to talPhysica lMemory =  GetPhysica lMemorySiz eInBytes() ;
  417  
  418                int jvmM emoryInMb  = (int)(to talPhysica lMemory /  (1024 * 10 24 * 4));  // convert  to MB the n take 25%  for JVM u se
  419                if (jvmM emoryInMb  > 1024 &&  Manifest.C urrentNati veInstalla tion == Na tiveType.x 86)
  420                {
  421                    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
  422                }
  423  
  424                string k ey = null;
  425                Registry View regVi ew = Regis tryView.Re gistry64;
  426                if (Busi nessFacade .Is64BitOp eratingSys tem())
  427                {
  428                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  429                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Java" ;
  430                }
  431                else
  432                {
  433                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Java";
  434                }
  435                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  436                {
  437                    usin g (Registr yKey java  = regKey.O penSubKey( key, true) )
  438                    {
  439                         java.SetVa lue("JvmMs ", jvmMemo ryInMb, Re gistryValu eKind.DWor d);
  440                         java.SetVa lue("JvmMx ", jvmMemo ryInMb, Re gistryValu eKind.DWor d);
  441                         java.SetVa lue("JvmSs ", 0, Regi stryValueK ind.DWord) ;
  442                    }
  443                }
  444           }
  445  
  446           // / <summary >
  447           // / Creates  and/or enc rypts the  secure log  sub direc tory
  448           // / </summar y>
  449           // / <param n ame="confi g"></param >
  450           // //public s tatic void  Configure TomcatEncr yptedLogFo lder(IVixC onfigurati onParamete rs config)
  451           // //{
  452           // //    Dire ctoryInfo  encryptedL ogDir = ne w Director yInfo(Tomc atLogFolde rEncrypted );
  453           // //    if ( !encrypted LogDir.Exi sts)
  454           // //    {
  455           // //         encryptedL ogDir.Crea te();
  456           // //         // recreat e the Dire ctoryInfo  object bec ause the o ld one has  cached da ta before  the dir wa s created
  457           // //         encryptedL ogDir = ne w Director yInfo(Tomc atLogFolde rEncrypted );
  458           // //    }
  459           // //    // c heck if en crypted fl ag is set
  460           // //    if ( (encrypted LogDir.Att ributes &  FileAttrib utes.Encry pted) == 0 ) // bitwi se AND to  check if t he Encrype d flag is  set
  461           // //    {
  462           // //         // encrypt ed flag no t set, so  set it
  463           // //         // Setting  the Direc toryInfo.A ttributes  to add the  encryptio n flag doe sn't work
  464           // //         // Instead  use the F ileInfo.En crypt meth od (Direct oryInfo do es not hav e an Encry pt method)
  465           // //         try
  466           // //         {
  467           // //             FileIn fo encrypt edLogDirFi le = new F ileInfo(To mcatLogFol derEncrypt ed);
  468           // //             encryp tedLogDirF ile.Encryp t();
  469           // //         }
  470           // //         catch (Exc eption ex)
  471           // //         {
  472           // //             Logger ().Error(e x.Message) ;
  473           // //             Logger ().Error(" Error encr ypting " +  TomcatLog FolderEncr ypted + ".  Install p roceding c an continu e.");
  474           // //         }
  475           // //    }
  476           // //}
  477  
  478           // / <summary >
  479           // / Fixup th e Procrun  service to  point to  the JVM sp ecified in  the manif est.
  480           // / </summar y>
  481           pu blic stati c void Fix upTomcatSe rviceJvm()
  482           {
  483                string k ey = null;
  484                Registry View regVi ew = Regis tryView.Re gistry64;
  485                if (Busi nessFacade .Is64BitOp eratingSys tem())
  486                {
  487                    // P rocrun key  will be i nstalled u nder Wow64 32Node key  - even if  Tomcat 6. 0.33 is in stalled na tively
  488                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Java" ;
  489                }
  490                else
  491                {
  492                    key  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Java";
  493                }
  494                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  495                {
  496                    usin g (Registr yKey java  = regKey.O penSubKey( key, true) )
  497                    {
  498                         string jvm  = (string )java.GetV alue("Jvm" , null);
  499                         string jav aPath = Ja vaFacade.G etActiveJa vaPath(Jav aFacade.Is ActiveJreI nstalled() );
  500                         Debug.Asse rt(jvm !=  null);
  501  
  502                         if (!jvm.T oUpper().C ontains(ja vaPath.ToU pper()))
  503                         {
  504                             jvm =  Path.Combi ne(javaPat h, @"bin\c lient\jvm. dll");
  505                             java.S etValue("J vm", jvm,  RegistryVa lueKind.St ring);
  506                         }
  507                    }
  508                }
  509           }
  510  
  511           // / <summary >
  512           // / Uninstal l the curr ent deprec ated insta llation of  Tomcat as  specifed  by the man ifest
  513           // / </summar y>
  514           pu blic stati c void Uni nstallDepr ecatedTomc at()
  515           {
  516                TomcatPr erequisite  prerequis ite = GetI nstalledDe precatedTo mcatPrereq usite();
  517                if (prer equisite ! = null)
  518                {
  519                    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
  520  
  521                    if ( prerequisi te.Unregis terFilenam e != null)
  522                    {
  523                         Unregister Tomcat(pre requisite,  tomcatIns tallFolder );
  524                    }
  525  
  526                    Unin stallTomca t(prerequi site, tomc atInstallF older);
  527  
  528                    if ( prerequisi te.DeleteU ninstaller RegistryKe y != null)
  529                    {
  530                         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
  531                    }
  532  
  533                    if ( prerequisi te.DeleteS tartMenuFo lder != nu ll)
  534                    {
  535                         try
  536                         {
  537                             if (Di rectory.Ex ists(prere quisite.De leteStartM enuFolder) )
  538                             {
  539                                 Di rectory.De lete(prere quisite.De leteStartM enuFolder,  true); //  recurse
  540                             }
  541                         }
  542                         catch (Exc eption ex)
  543                         {
  544                             Logger ().Info("E xception w hile delet ing Tomcat  Start Men u Group: "  + ex.Mess age);
  545                         }
  546                    }
  547                }
  548           }
  549  
  550           #e ndregion
  551  
  552           #r egion priv ate method s
  553  
  554  
  555           // / <summary >
  556           // / Uninstal ls Apache  Tomcat.
  557           // / </summar y>
  558           // / <param n ame="prere quisite">T he prerequ isite whic h hold Tom cat uninst all inform ation.</pa ram>
  559           // / <remarks ></remarks >
  560           pr ivate stat ic void Un installTom cat(Tomcat Prerequisi te prerequ isite, str ing tomcat InstallFol der)
  561           {
  562                string u ninstaller Filename =  prerequis ite.UnInst allerFilen ame;
  563                string u ninstaller Filespec =  Path.Comb ine(tomcat InstallFol der, unins tallerFile name);
  564  
  565                System.D iagnostics .Process e xternalPro cess = new  System.Di agnostics. Process();
  566                external Process.St artInfo.Fi leName = u ninstaller Filespec;
  567                external Process.St artInfo.Ar guments =  prerequisi te.UnInsta llerArgume nts;
  568                external Process.St artInfo.Us eShellExec ute = fals e;
  569                external Process.St artInfo.Cr eateNoWind ow = true;
  570                external Process.St art();
  571                do
  572                {
  573                    Thre ad.Sleep(5 00);
  574                    exte rnalProces s.Refresh( );
  575                } while  (!external Process.Ha sExited);
  576                Thread.S leep(3000) ; // Allow  windows t o complete  any file  deletes
  577                // 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
  578                // this  can cause  errors in  the direct ory delete  operation
  579                do
  580                {
  581                    try
  582                    {
  583                         Directory. Delete(tom catInstall Folder, tr ue);
  584                    }
  585                    catc h (System. IO.IOExcep tion) { ;  }
  586                }
  587                while (D irectory.E xists(tomc atInstallF older));
  588           }
  589  
  590           pr ivate stat ic void Un registerTo mcat(Tomca tPrerequis ite prereq uisite, st ring tomca tInstallFo lder)
  591           {
  592                if (prer equisite.U nregisterF ilename !=  null && p rerequisit e.Unregist erArgument s != null)
  593                {
  594                    stri ng unregis terFilenam e = prereq uisite.Unr egisterFil ename;
  595                    stri ng unregis terFilespe c = Path.C ombine(tom catInstall Folder, un registerFi lename);
  596  
  597                    Syst em.Diagnos tics.Proce ss externa lProcess =  new Syste m.Diagnost ics.Proces s();
  598                    exte rnalProces s.StartInf o.FileName  = unregis terFilespe c;
  599                    exte rnalProces s.StartInf o.Argument s = prereq uisite.Unr egisterArg uments;
  600                    exte rnalProces s.StartInf o.UseShell Execute =  false;
  601                    exte rnalProces s.StartInf o.CreateNo Window = t rue;
  602                    exte rnalProces s.Start();
  603                    do
  604                    {
  605                         Thread.Sle ep(500);
  606                         externalPr ocess.Refr esh();
  607                    } wh ile (!exte rnalProces s.HasExite d);
  608                    Logg er().Info( "Manually  unregister ed Tomcat  service: "  + prerequ isite.Unre gisterArgu ments);
  609                }
  610           }
  611  
  612           // / <summary >
  613           // / Gets the  ammount o f physical  memory in stalled in  bytes.
  614           // / </summar y>
  615           // / <returns >The ammou nt of phys ical memor y installe d in bytes </returns>
  616           pu blic stati c ulong Ge tPhysicalM emorySizeI nBytes()
  617           {
  618                ulong ph ysicalMemo ry = 0;
  619                MEMORYST ATUSEX mem stat = new  MEMORYSTA TUSEX();
  620                try
  621                {
  622                    if ( GlobalMemo ryStatusEx (memstat))
  623                    {
  624                         physicalMe mory = mem stat.ullTo talPhys;
  625                    }
  626                }
  627                catch (E xception e x)
  628                {
  629                    Logg er().Error ("Error ma king kerne l32 Global MemoryStat usEx call" );
  630                    Logg er().Error (ex.Messag e);
  631                }
  632  
  633                if (phys icalMemory  == 0)
  634                {
  635                    stri ng errmsg  = "Install er was not  able to d etermine t he amount  of physica l memory i n the syst em.";
  636                    Logg er().Error (errmsg);  // should  never happ en
  637                    thro w new Exce ption(errm sg);
  638                }
  639  
  640                return p hysicalMem ory;
  641           }
  642  
  643           // / <summary >
  644           // / Gets the  installed  deprecate d Tomcat p rerequsite .
  645           // / </summar y>
  646           // / <returns >The depre cated Tomc at prerequ isite if f ound.</ret urns>
  647           // / <remarks >Can retur n null.</r emarks>
  648           pr ivate stat ic TomcatP rerequisit e GetInsta lledDeprec atedTomcat Prerequsit e()
  649           {
  650                Debug.As sert(IsTom catInstall ed() == tr ue);
  651                string i nstalledTo mcatVersio n = Instal ledTomcatV ersion;
  652                TomcatPr erequisite  tomcatPre requisite  = null;
  653                foreach  (TomcatPre requisite  prerequisi te in Mani fest.Depre catedTomca tPrerequis ites)
  654                {
  655                    if ( IsPrerequi siteInstal led(prereq uisite))
  656                    {
  657                         tomcatPrer equisite =  prerequis ite;
  658                         break;
  659                    }
  660                }
  661                return t omcatPrere quisite;
  662           }
  663  
  664           // / <summary >
  665           // / Determin es whether  version T omcat spec ified by t he provide d prerequi site is in stalled.
  666           // / </summar y>
  667           // / <param n ame="prere quisite">T he prerequ isite spec ifying the  Tomcat ve rsion to c heck for.< /param>
  668           // / <returns ><c>true</ c> if spec ified vers ion of Tom cat is ins talled; ot herwise, < c>false</c >.</return s>
  669           pr ivate stat ic bool Is Prerequisi teInstalle d(TomcatPr erequisite  prerequis ite)
  670           {
  671                bool isI nstalled =  false;
  672                string i nstalledVe rsion = nu ll;
  673                string k ey = null;
  674                Registry View regVi ew = Regis tryView.Re gistry64;
  675  
  676                if (Busi nessFacade .Is64BitOp eratingSys tem() && p rerequisit e.Native = = NativeTy pe.x86)
  677                {
  678                    key  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Tomcat";
  679                }
  680                else //  native ins tallation  - either x 86 or x64
  681                {
  682                    key  = @"SOFTWA RE\Apache  Software F oundation\ Tomcat";
  683                }
  684                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  685                {
  686                    usin g (Registr yKey tomca t = regKey .OpenSubKe y(key, tru e))
  687                    {
  688                         if (tomcat  != null & & tomcat.S ubKeyCount  > 0)
  689                         {
  690                             string [] subkeys  = tomcat. GetSubKeyN ames(); //  try and r emain vers ion indepe ndent
  691                             Debug. Assert(sub keys.Lengt h == 1);
  692                             key +=  @"\" + su bkeys[0];
  693                             using  (RegistryK ey tomcatV ersion = r egKey.Open SubKey(key , true))
  694                             {
  695                                 ob ject o = t omcatVersi on.GetValu e("Version ");
  696                                 if  (o != nul l)
  697                                 {
  698                                      installe dVersion =  o.ToStrin g();
  699                                 }
  700                             }
  701                         }
  702                    }
  703                }
  704                // later  versions  of Tomcat  (somewhere  after 6.0 .20) moved  the locat ion of the  "Version"  value dow n a level
  705                if (inst alledVersi on == null )
  706                {
  707                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  708                    {
  709                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(key,  true))
  710                         {
  711                             if (to mcat != nu ll && tomc at.SubKeyC ount > 0)
  712                             {
  713                                 st ring[] sub keys = tom cat.GetSub KeyNames() ; // try a nd remain  version in dependent
  714                                 De bug.Assert (subkeys.L ength == 1 );
  715                                 ke y += @"\"  + subkeys[ 0];
  716                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (key, true ))
  717                                 {
  718                                      object o  = tomcatV ersion.Get Value("Ver sion");
  719                                      if (o !=  null)
  720                                      {
  721                                          inst alledVersi on = o.ToS tring();
  722                                      }
  723                                 }
  724                             }
  725                         }
  726                    }
  727                }
  728  
  729                if (inst alledVersi on != null  && instal ledVersion  == prereq uisite.Ver sion)
  730                {
  731                    isIn stalled =  true;
  732                }
  733  
  734                return i sInstalled ;
  735           }
  736  
  737           // / <summary >
  738           // / Gets the  installed  Tomcat ve rsion as a  string.
  739           // / </summar y>
  740           // / <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>
  741           // / <returns >The insta lled Tomca t version  as a strin g.</return s>
  742           pr ivate stat ic string  GetInstall edTomcatVe rsion(stri ng baseReg Key)
  743           {
  744                string i nstalledVe rsion = nu ll;
  745                Registry View regVi ew = Regis tryView.Re gistry64;
  746                if (Regi stryUtilit ies.DoesRe gKeyExist( baseRegKey ) == true)
  747                {
  748                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  749                    {
  750                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(base RegKey, tr ue))
  751                         {
  752                             if (to mcat != nu ll && tomc at.SubKeyC ount > 0)
  753                             {
  754                                 st ring[] sub keys = tom cat.GetSub KeyNames() ; // try a nd remain  version in dependent
  755                                 De bug.Assert (subkeys.L ength == 1 );
  756                                 ba seRegKey + = @"\" + s ubkeys[0];
  757                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (baseRegKe y, true))
  758                                 {
  759                                      object o  = tomcatV ersion.Get Value("Ver sion");
  760                                      if (o !=  null)
  761                                      {
  762                                          inst alledVersi on = o.ToS tring();
  763                                      }
  764                                 }
  765                             }
  766                         }
  767                    }
  768                    // 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
  769                    if ( installedV ersion ==  null)
  770                    {
  771                         using (Reg istryKey r egKey = Re gistryKey. OpenBaseKe y(Registry Hive.Local Machine, r egView))
  772                         {
  773                             using  (RegistryK ey tomcat  = regKey.O penSubKey( baseRegKey , true))
  774                             {
  775                                 De bug.Assert (tomcat !=  null);
  776                                 if  (tomcat ! = null &&  tomcat.Sub KeyCount >  0)
  777                                 {
  778                                      string[]  subkeys =  tomcat.Ge tSubKeyNam es(); // t ry and rem ain versio n independ ent
  779                                      Debug.As sert(subke ys.Length  == 1);
  780                                      baseRegK ey += @"\"  + subkeys [0];
  781                                      using (R egistryKey  tomcatVer sion = reg Key.OpenSu bKey(baseR egKey, tru e))
  782                                      {
  783                                          obje ct o = tom catVersion .GetValue( "Version") ;
  784                                          if ( o != null)
  785                                          {
  786                                               installedV ersion = o .ToString( );
  787                                          }
  788                                      }
  789                                 }
  790                             }
  791                         }
  792                    }
  793                }
  794  
  795                return i nstalledVe rsion;
  796           }
  797  
  798           // / <summary >
  799           // / Gets the  Tomcat in stallation  dirspec.
  800           // / </summar y>
  801           // / <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>
  802           // / <returns >The Tomca t installa tion dirsp ec.</retur ns>
  803           pr ivate stat ic string  GetTomcatI nstallatio nFolder(st ring baseR egKey)
  804           {
  805                string i nstallatio nFolder =  null;
  806                Registry View regVi ew = Regis tryView.Re gistry64;
  807  
  808                if (Regi stryUtilit ies.DoesRe gKeyExist( baseRegKey ))
  809                {
  810                    Logg er().Info( "Base Regi stry Key E xist.");
  811                    Debu g.Assert(T omcatFacad e.IsTomcat Installed( ) == true) ;
  812                    usin g (Registr yKey regKe y = Regist ryKey.Open BaseKey(Re gistryHive .LocalMach ine, regVi ew))
  813                    {
  814                         using (Reg istryKey t omcat = re gKey.OpenS ubKey(base RegKey, tr ue))
  815                         {
  816                             Debug. Assert(tom cat.SubKey Count > 0) ;
  817                             string [] subkeys  = tomcat. GetSubKeyN ames(); //  try and r emain vers ion indepe ndent
  818                             Debug. Assert(sub keys.Lengt h == 1);
  819                             if (su bkeys.Leng th > 0)
  820                             {
  821                                 ba seRegKey + = @"\" + s ubkeys[0];
  822                                 Lo gger().Inf o("Reg Key  with appe nded Subke y: " + bas eRegKey);
  823                                 us ing (Regis tryKey tom catVersion  = regKey. OpenSubKey (baseRegKe y, true))
  824                                 {
  825                                      object o  = tomcatV ersion.Get Value("Ins tallPath") ;
  826                                      if (o !=  null)
  827                                      {
  828                                          inst allationFo lder = o.T oString();
  829                                      }
  830                                 }
  831                             }
  832                         }
  833                    }
  834                    // 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
  835                    if ( installati onFolder = = null)
  836                    {
  837                         using (Reg istryKey r egKey = Re gistryKey. OpenBaseKe y(Registry Hive.Local Machine, r egView))
  838                         {
  839                             using  (RegistryK ey tomcat  = regKey.O penSubKey( baseRegKey , true))
  840                             // ope n the last  key where  we were l ooking for  InstallPa th
  841                             {
  842                                 if  (tomcat ! = null &&  tomcat.Sub KeyCount >  0)
  843                                 {
  844                                      string[]  subkeys =  tomcat.Ge tSubKeyNam es(); // t ry and rem ain versio n independ ent
  845                                      Debug.As sert(subke ys.Length  == 1);
  846                                      baseRegK ey += @"\"  + subkeys [0]; // lo ok one sub key deeper
  847                                      Logger() .Info("Reg  Key with  appended S ubkey: " +  baseRegKe y);
  848                                      using (R egistryKey  tomcatVer sion = reg Key.OpenSu bKey(baseR egKey, tru e))
  849                                      {
  850                                          obje ct o = tom catVersion .GetValue( "InstallPa th");
  851                                          if ( o != null)
  852                                          {
  853                                               installati onFolder =  o.ToStrin g();
  854                                          }
  855                                      }
  856                                 }
  857                             }
  858                         }
  859                    }
  860                }
  861                return i nstallatio nFolder;
  862           }
  863  
  864           #e ndregion
  865  
  866       }
  867   }