745. EPMO Open Source Coordination Office Redaction File Detail Report

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

745.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 VixFacade.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 VixFacade.cs Wed Oct 17 18:42:26 2018 UTC

745.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 7 4828
Changed 6 14
Inserted 0 0
Removed 0 0

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

745.4 Active regular expressions

No regular expressions were active.

745.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 log4 net;
  6   using Syst em.Diagnos tics;
  7   using Syst em.Threadi ng;
  8   using Micr osoft.Win3 2;
  9   using Micr osoft.Visu alBasic.Fi leIO;
  10   using Syst em.Xml;
  11   using Syst em.Net.Soc kets;
  12   using Syst em.Net;
  13                
  14   namespace  gov.va.med .imaging.e xchange.Vi xInstaller .business
  15   {
  16       public  static cl ass VixFac ade
  17       {
  18           pr ivate stat ic readonl y String V IX_CONFIG_ FILENAME =  "ViXConfi g.xml";
  19           pr ivate stat ic readonl y String S ITE_SERVIC E_SITE_RES OLUTION_FI LENAME = " SiteServic eSiteResol ution-1.0. config";
  20           pr ivate stat ic readonl y String E XCHANGE_DA TA_SOURCE_ FILENAME =  "Exchange DataSource -1.0.confi g";
  21           pr ivate stat ic readonl y String E XCHANGE_CA CHE_CONFIG _REL_FILES PEC = @"ca che-config \ImagingEx changeCach e-cache.xm l";
  22           pr ivate stat ic readonl y String E XCHANGE_CA CHE_DOD_IM AGE_REGION  = @"dod-i mage-regio n";
  23           pr ivate stat ic readonl y String F EDERATION_ KEYSTORE_F ILENAME =  "federatio n.keystore ";
  24           pr ivate stat ic readonl y String F EDERATION_ TRUSTSTORE _FILENAME  = "federat ion.trusts tore";
  25           pu blic stati c readonly  String VI X_CACHE_DI RECTORY =  @"VixCache ";
  26           pu blic stati c readonly  String VI X_CONFIG_D IRECTORY =  @"VixConf ig";
  27           pu blic stati c readonly  String VI X_CERTSTOR E_DIRECTOR Y = @"VixC ertStore";
  28           pu blic stati c readonly  int MINIM UM_VIX_CAC HE_SIZE_GB  = 20;
  29           pr ivate stat ic readonl y long ONE _GIGBYTE =  (1024 * 1 024 * 1024 );
  30           pu blic stati c readonly  String HD IG_DICOM_D IRECTORY =  @"DICOM";
  31           // private st atic reado nly String  XCA_KEYST ORE_FILENA ME = "xca. keystore";
  32           // private st atic reado nly String  XCA_TRUST STORE_FILE NAME = "xc a.truststo re";
  33           pr ivate stat ic readonl y String X CA_CERTIFI CATE_FILEN AME = "CVI X_XCA_Cert ificate.pe m";
  34           pr ivate stat ic readonl y String X CA_PRIVATE _KEY_FILEN AME = "CVI X_XCA_Priv ateKey.pem ";
  35           pr ivate stat ic readonl y String M ODALITY_BL ACKLIST_FI LENAME = " ExchangeMo dalityBlac kList.txt" ;
  36           pr ivate stat ic readonl y String J AVALOG_KEY STORE_FILE NAME = "Lo calAdmin.j ks";
  37           pr ivate stat ic readonl y String R OI_DISCLOS URE_DIRECT ORY = @"RO I\disclosu re";
  38           pr ivate stat ic readonl y String C VIX_KEYSTO RE_FILENAM E = "cvix. jks";
  39           pr ivate stat ic readonl y String D AS_TRUSTST ORE_FILENA ME = "das. truststore ";
  40             private st atic reado nly String  DAS_TRUST STORE_PASS WORD = "
A I ";
  41           
  42           #r egion prop erties
  43           pr ivate stat ic InfoDel egate info Delegate =  null; //  used to di splay a li ne of text  to any Wi zardPage t hat has re gistered
  44           pu blic stati c InfoDele gate InfoD elegate
  45           {
  46                get { re turn VixFa cade.infoD elegate; }
  47                set { Vi xFacade.in foDelegate  = value;  }
  48           }
  49  
  50           pr ivate stat ic AppEven tsDelegate  appEvents Delegate =  null; //  used to ke ep the UI  responsive
  51           pu blic stati c AppEvent sDelegate  AppEventsD elegate
  52           {
  53                get { re turn VixFa cade.appEv entsDelega te; }
  54                set { Vi xFacade.ap pEventsDel egate = va lue; }
  55           }
  56  
  57           pr ivate stat ic VixMani fest manif est = null ; // the i nstallatio n manifest
  58           pu blic stati c VixManif est Manife st
  59           {
  60                get { re turn VixFa cade.manif est; }
  61                set { Vi xFacade.ma nifest = v alue; }
  62           }
  63  
  64           pu blic stati c string V ixConfigFi lespec
  65           {
  66                get { re turn Path. Combine(Ge tVixConfig urationDir ectory(),  VIX_CONFIG _FILENAME) ; }
  67           }
  68  
  69           pu blic stati c string S iteService SiteResolu tionConfig Filespec
  70           {
  71                get { re turn Path. Combine(Ge tVixConfig urationDir ectory(),  SITE_SERVI CE_SITE_RE SOLUTION_F ILENAME);  }
  72           }
  73  
  74           pu blic stati c string E xchangeDat aSourceCon figFilespe c
  75           {
  76                get { re turn Path. Combine(Ge tVixConfig urationDir ectory(),  EXCHANGE_D ATA_SOURCE _FILENAME) ; }
  77           }
  78  
  79           pu blic stati c string E xchangeCac heConfigFi lespec
  80           {
  81                get { re turn Path. Combine(Ge tVixConfig urationDir ectory(),  EXCHANGE_C ACHE_CONFI G_REL_FILE SPEC); }
  82           }
  83  
  84           #e ndregion
  85  
  86           #r egion publ ic methods
  87           // / <summary >
  88           // / Checks t o see if a  VIX is in stalled wi th all the  required  prerequisi tes.
  89           // / </summar y>
  90           // / <returns >true if t he VIX is  installed,  false oth erwise</re turns>
  91           pu blic stati c bool IsV ixInstalle d()
  92           {
  93                bool isI nstalled =  false;
  94  
  95                //if (To mcatFacade .IsTomcatI nstalled()  == true & & JavaFaca de.IsJavaI nstalled(i sDeveloper Mode) == t rue)
  96                if (Tomc atFacade.I sTomcatIns talled() = = true)
  97                {
  98                    Stri ng vixPath  = Path.Co mbine(Tomc atFacade.T omcatWebAp plicationF older, @"V ixServerHe althWebApp ");
  99                    if ( Directory. Exists(vix Path) && I sVixConfig ured())
  100                    {
  101                         isInstalle d = true;
  102                    }
  103                }
  104                return i sInstalled ;
  105           }
  106  
  107           // / <summary >
  108           //
  109           // / </summar y>
  110           // / <returns ></returns >
  111           pu blic stati c bool IsV ixConfigur ed()
  112           {
  113                bool isC onfigured  = false;
  114  
  115                String v ixConfigDi r = Enviro nment.GetE nvironment Variable(" vixconfig" , Environm entVariabl eTarget.Ma chine);
  116                if (vixC onfigDir ! = null)
  117                {
  118                    Stri ng vixConf igFilepath  = Path.Co mbine(vixC onfigDir,  VIX_CONFIG _FILENAME) ;
  119                    if ( File.Exist s(vixConfi gFilepath) )
  120                    {
  121                         isConfigur ed = true;
  122                    }
  123                }
  124  
  125                return i sConfigure d;
  126           }
  127  
  128           // / <summary >
  129           //
  130           // / </summar y>
  131           // / <returns ></returns >
  132           pu blic stati c bool IsF ederationC ertificate InstalledO rNotRequir ed(IVixCon figuration Parameters  config)
  133           {
  134                bool isV ixCertific ateInstall edOrNotReq uired = fa lse;
  135                string c ertStoreDi r = VixFac ade.GetVix Certificat eStoreDir( );
  136                string v ixKeystore Filepath =  Path.Comb ine(certSt oreDir, FE DERATION_K EYSTORE_FI LENAME);
  137                string v ixTruststo reFilepath  = Path.Co mbine(cert StoreDir,  FEDERATION _TRUSTSTOR E_FILENAME );
  138  
  139                //if (Vi xFacade.Ma nifest.Maj orPatchNum ber == 34)
  140                if (conf ig.VixRole  == VixRol eType.Dico mGateway)
  141                {
  142                    isVi xCertifica teInstalle dOrNotRequ ired = tru e;
  143                    Logg er().Info( "VIX Certi ficate not  required. ");
  144                }
  145                else if  (File.Exis ts(vixKeys toreFilepa th) && Fil e.Exists(v ixTruststo reFilepath ))
  146                {
  147                    isVi xCertifica teInstalle dOrNotRequ ired = tru e;
  148                    Logg er().Info( "VIX Certi ficate is  installed. ");
  149                }
  150                return i sVixCertif icateInsta lledOrNotR equired;
  151           }
  152  
  153           // / <summary >
  154           //
  155           // / </summar y>
  156           // / <returns ></returns >
  157           pu blic stati c bool IsX caCertific ateInstall ed()
  158           {
  159                bool isX caCertific ateInstall ed = false ;
  160                string c ertStoreDi r = VixFac ade.GetVix Certificat eStoreDir( );
  161                //string  xcaKeysto reFilepath  = Path.Co mbine(cert StoreDir,  XCA_KEYSTO RE_FILENAM E);
  162                //string  xcaTrusts toreFilepa th = Path. Combine(ce rtStoreDir , XCA_TRUS TSTORE_FIL ENAME);
  163                string x caCertific ateFilepat h = Path.C ombine(cer tStoreDir,  XCA_CERTI FICATE_FIL ENAME);
  164                string x caPrivateK eyFilepath  = Path.Co mbine(cert StoreDir,  XCA_PRIVAT E_KEY_FILE NAME);
  165  
  166                //if (Fi le.Exists( xcaKeystor eFilepath)  && File.E xists(xcaT ruststoreF ilepath) & & File.Exi sts(xcaCer tificateFi lepath) &&  File.Exis ts(xcaPriv ateKeyFile path))
  167                if (File .Exists(xc aCertifica teFilepath ) && File. Exists(xca PrivateKey Filepath))
  168                {
  169                    isXc aCertifica teInstalle d = true;
  170                }
  171  
  172                return i sXcaCertif icateInsta lled;
  173           }
  174  
  175           // / <summary >
  176           // / Does DOD  Connector  certifica te exist? 
  177           // / </summar y>
  178           // / <returns >true if d as.trustst ore exists </returns>
  179           pu blic stati c bool IsD oDCertific ateInstall ed()
  180           {
  181                string d asCertPath  = Path.Co mbine(GetV ixCertific ateStoreDi r(), DAS_T RUSTSTORE_ FILENAME);
  182                return F ile.Exists (dasCertPa th);
  183           }
  184  
  185           // / <summary >
  186           // / Install  the VIX se rvice. Thi s is the m ethod that  acutally  installs a  VIX. It's  what the  wizard exi sts to sup port.
  187           // / </summar y>
  188           // / <param n ame="isDev eloperMode "></param>
  189           pu blic stati c void Ins tallVix(IV ixConfigur ationParam eters conf ig) //, bo ol isDevel operMode)
  190           {
  191                // HDIG  servers no w have a c ertificate  - needed  for viewin g encrypte d log entr ies
  192                if (conf ig.VixRole  == VixRol eType.Dico mGateway)
  193                {
  194                    stri ng certSto reDir = Vi xFacade.Ge tVixCertif icateStore Dir();
  195                    if ( !Directory .Exists(ce rtStoreDir ))
  196                    {
  197                         Directory. CreateDire ctory(cert StoreDir);  // this m ust be don e before A CLs are ap plied
  198                    }
  199                }
  200  
  201                // Apply  DAC for t he ViX ser vice accou nt to the  file syste m
  202                ApplyAcc essControl (config);
  203                
  204                // set t he ViX env ironment v ariables
  205                CreateEn vironmentV ariables(c onfig);
  206  
  207                // delet e any depr ecated fil es from a  previous r elease
  208                DeleteDe precatedDi stribution Files(conf ig, true);
  209  
  210                // delet e any depr ecated dir ectories f rom a prev ious relea se
  211                DeleteDe precatedDi stribution Directorie s(config,  true);
  212  
  213                // re-cr eate tomca t-users.xm l
  214                TomcatFa cade.Confi gureTomcat Users(conf ig);
  215  
  216                if (conf ig.VixRole  == VixRol eType.Site Vix)
  217                {
  218                    // U nregister  any OCX de pendencies
  219                    Unre gisterImag eGearDepen dencyFiles (config);
  220  
  221                    // C opy distri bution fil es to targ et locatio ns
  222                    Depl oyImageGea rDependenc yFiles(con fig, true) ;
  223  
  224                    // R egister an y OCX depe ndencies
  225                    Regi sterImageG earDepende ncyFiles(c onfig);
  226                }
  227  
  228                // Copy  distributi on files t o target l ocations
  229                DeployDe pendencyFi les(config , true);
  230  
  231                // deplo y the web  applicatio ns as dict ated by th e manifest  and confi guration p arameters
  232                DeployVi xWebApplic ations(con fig);
  233  
  234                // Copy  distributi on file th at update  the deploy ed web app s
  235                DeployWe bAppDepend encyFiles( config, tr ue);
  236  
  237                // write  ViX confi guration f iles
  238                // this  must come  after mani fest files  are copie d
  239                WriteViX Configurat ionFiles(c onfig); // , isDevelo perMode);
  240  
  241                // add t he java pr operties n eeded to b y the ViX  to the Pro crun envir onment
  242                ApplyVix JavaProper tiesFromMa nifest(con fig, true) ; // commi t result
  243  
  244                // fixup  Tomcat to  point to  the JVM sp ecified in  the manif est
  245                TomcatFa cade.Fixup TomcatServ iceJvm();
  246  
  247                // preve nt Tomcat  Monitor fr om running  at log in
  248                TomcatFa cade.Disab leTomcatMo nitor();
  249  
  250                // for C VIX instal ls, deploy  the vhasi tes.xml fi le that dr ives the s ite servic e to the 
  251                // VIX c onfig dire ctory.
  252                if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way && con fig.SitesF ile != nul l)
  253                {
  254                    Depl oySitesFil e(config);
  255                }
  256  
  257                // turn  off Tomcat  logging t o Stdout
  258                TomcatFa cade.Disab leStdOutLo gging();
  259  
  260                // fixup  Tomcat JV M memory u sage to co rrect case  where mor e than 1G  was being  allocated  for 32 bit  process
  261                TomcatFa cade.Confi gureTomcat JvmMemory( config);
  262  
  263                //set TC P Timeout
  264                TCPTimeo utInRegist ry();
  265  
  266                //Run a  Netsh comm and
  267                RunNetwo rkConfigur ationComma nd();
  268  
  269                // save  the VIX in staller co nfiguratio n paramete rs for lat er use
  270                // this  must go he re because  the Write Configurat ionFiles s tep change s the conf iguration.
  271                config.T oXml();
  272  
  273                if (mani fest.Clear Cache || m anifest.Cl earCacheIf PreviousVe rsion(conf ig.Previou sProductVe rsionProp) )
  274                {
  275                    Dele teAllLocal CacheRegio ns(config) ;
  276                }
  277  
  278                // start  the ViX i f not runn ing on a c luster
  279                switch ( config.Vix Deployment Option)
  280                {
  281                    case  VixDeploy mentType.F ocClusterN ode:
  282                         return;
  283                }
  284  
  285                //Reset  Catalina.p roperties  if it has  been chang ed
  286                String t omcatConfP ath = Tomc atFacade.T omcatConfi gurationFo lder;
  287                if (HadC atalinaPro pBeenChang ed(tomcatC onfPath))
  288                    Rese tCatalinaP rop(tomcat ConfPath);
  289  
  290                Info("St arting the  " + Tomca tFacade.To mcatServic eName + "  service.") ;
  291                ServiceU tilities.S tartLocalS ervice(Tom catFacade. TomcatServ iceName);
  292                System.S erviceProc ess.Servic eControlle rStatus st atus;
  293                // wait  for the Vi X to start
  294                do
  295                {
  296                    DoEv ents();
  297                    Thre ad.Sleep(5 00);
  298                    stat us = Servi ceUtilitie s.GetLocal ServiceSta tus(Tomcat Facade.Tom catService Name);
  299                }
  300                while (s tatus == S ystem.Serv iceProcess .ServiceCo ntrollerSt atus.Start Pending);
  301  
  302                if (stat us == Syst em.Service Process.Se rviceContr ollerStatu s.Running)
  303                {
  304                    Info ("The " +  TomcatFaca de.TomcatS erviceName  + " servi ce has bee n started. ");
  305                    //no w start th e Viewer a nd Render  services.
  306                    if ( ZFViewerFa cade.IsZFV iewerInsta lled())
  307                    {
  308                         bool viewe rStatus =  ZFViewerFa cade.Start ZFViewerSe rvices();
  309                         if (viewer Status ==  false)
  310                         {
  311                             Info(" The " + ZF ViewerFaca de.ViewerS erviceAcco untName +  " could no t be start ed.");
  312                         }
  313                    }
  314  
  315                    if ( ListenerFa cade.IsLis tenerInsta lled())
  316                    {
  317                         bool liste nerStatus  = Listener Facade.Sta rtListener Service();
  318                         if (listen erStatus = = false)
  319                         {
  320                             Info(" The " + Li stenerFaca de.LISTENE R_SERVICE_ NAME + " c ould not b e started. ");
  321                         }
  322                    }
  323                }
  324                else
  325                {
  326                    Info ("The " +  TomcatFaca de.TomcatS erviceName  + " could  not be st arted. The  current s tatus is "  + status. ToString() );
  327                }
  328           }
  329  
  330  
  331           pr ivate stat ic bool Ha dCatalinaP ropBeenCha nged(Strin g conf)
  332           {
  333                String c atalinaPro p = conf +  @"\catali na.propert ies";
  334  
  335                FileStre am fs = ne w FileStre am(catalin aProp, Fil eMode.Open OrCreate,  FileAccess .Read, Fil eShare.Non e);
  336                StreamRe ader sr =  new Stream Reader(fs) ;
  337  
  338                var line  = "";
  339                var resu lt = false ;
  340  
  341                while (( line = sr. ReadLine() ) != null)
  342                {
  343                    if ( line.Conta ins("tomca t.util.sca n.Standard JarScanFil ter.jarsTo Skip=*.jar "))
  344                    {
  345                         result = t rue;
  346                         break;
  347                    }
  348                }
  349  
  350                fs.Close ();
  351                return r esult;
  352           }
  353  
  354           pr ivate stat ic void Re setCatalin aProp(Stri ng conf)
  355           {
  356                Console. WriteLine( "\nReset "  + conf +  @"\Catalin a.properti es to scan  new jars. ..");
  357  
  358                String c atalinaPro p = conf +  @"\catali na.propert ies";
  359                String n ewCatalina Prop = con f + @"\new catalina.p roperties" ;
  360  
  361                FileStre am fs = ne w FileStre am(catalin aProp, Fil eMode.Open OrCreate,  FileAccess .Read, Fil eShare.Non e);
  362                FileStre am nfs = n ew FileStr eam(newCat alinaProp,  FileMode. Create, Fi leAccess.W rite, File Share.None );
  363  
  364                StreamRe ader sr =  new Stream Reader(fs) ;
  365                StreamWr iter sw =  new Stream Writer(nfs );
  366                var line  = "";
  367  
  368                while (( line = sr. ReadLine() ) != null)
  369                {
  370                    if ( line.Conta ins("tomca t.util.sca n.Standard JarScanFil ter.jarsTo Skip="))
  371                    {
  372                         line = @"t omcat.util .scan.Stan dardJarSca nFilter.ja rsToSkip=\ ";
  373                    }
  374                    sw.W riteLine(l ine);
  375                }
  376  
  377                sw.Flush ();
  378                fs.Close ();
  379                nfs.Clos e();
  380  
  381                File.Del ete(catali naProp);
  382                File.Cop y(newCatal inaProp, c atalinaPro p);
  383                File.Del ete(newCat alinaProp) ;
  384           }
  385  
  386  
  387  
  388           // / <summary >
  389           // / Unregist ers Image  Gear depen dency file s.
  390           // / </summar y>
  391           // / <remarks >At this t ime used t o unregist er Image G ear compon ents</rema rks>
  392           pu blic stati c void Unr egisterIma geGearDepe ndencyFile s(IVixConf igurationP arameters  config)
  393           {
  394                VixDepen dencyFile[ ] igFiles  = Manifest .GetImageG earDepende ncyFiles(c onfig);
  395                if (igFi les.Length  > 0)
  396                {
  397                    Info ("Unregist ering Imag eGear file s");
  398                    fore ach (VixDe pendencyFi le igFile  in igFiles )
  399                    {
  400                         if (igFile .Register)
  401                         {
  402                             string  igFilespe c = igFile .GetAppFil espec();
  403                             if (Fi le.Exists( igFilespec ))
  404                             {
  405                                 in t exitCode  = Registe rOrUnregis terOcx(igF ilespec, f alse);
  406                                 In fo("Unregi ster file  " + igFile spec + " :  " + (exit Code == 0  ? "Success " : "Failu re"));
  407                             }
  408                         }
  409                    }
  410                }
  411                else
  412                {
  413                    Info ("ImageGea r not inst alled - no  files to  unregister ");
  414                }
  415           }
  416  
  417           // / <summary >
  418           // / Register s Image Ge ar depende ncy files.
  419           // / </summar y>
  420           // / <remarks >At this t ime used t o register  Image Gea r componen ts</remark s>
  421           pu blic stati c void Reg isterImage GearDepend encyFiles( IVixConfig urationPar ameters co nfig)
  422           {
  423                VixDepen dencyFile[ ] igFiles  = Manifest .GetImageG earDepende ncyFiles(c onfig);
  424                if (igFi les.Length  > 0)
  425                {
  426                    Info ("Register ing ImageG ear files" );
  427                    fore ach (VixDe pendencyFi le igFile  in igFiles )
  428                    {
  429                         if (igFile .Register)
  430                         {
  431                             string  igFilespe c = igFile .GetAppFil espec();
  432                             if (!F ile.Exists (igFilespe c))
  433                             {
  434                                 th row new Ex ception("T rying to r egister fi le which d oes not ex ist: " + i gFilespec) ;
  435                             }
  436                             int ex itCode = R egisterOrU nregisterO cx(igFiles pec, true) ;
  437                             Info(" Register f ile " + ig Filespec +  " : " + ( exitCode = = 0 ? "Suc cess" : "F ailure"));
  438                         }
  439                    }
  440                }
  441           }
  442  
  443           // / <summary >
  444           // / Remove t he web app lication t races asso ciated wit h the web  applicatio ns specifi ed in the  manifest.  Note that
  445           // / it is no t necessar y to delet e applicat ion contex ts from se rver.xml b ecause the  contexts  will be ge nerated
  446           // / from scr atch in th e server.x ml shell t hat is dis tributed w ith each V iX payload .
  447           // / </summar y>
  448           // / <param n ame="confi g"></param >
  449           pu blic stati c void Und eployVixWe bApplicati ons(IVixCo nfiguratio nParameter s config)
  450           {
  451                if (Tomc atFacade.I sTomcatIns talled() = = false) / / sanity c heck - cou ld happen  in JDK man ual uninst all/reinst all scener io
  452                {
  453                    retu rn;
  454                }
  455                
  456                VixWebAp plication[ ] vixWebAp plications  = Manifes t.VixWebAp plications ;
  457                
  458                foreach  (VixWebApp lication v ixWebAppli cation in  vixWebAppl ications)
  459                {
  460                    if ( vixWebAppl ication.Is Axis2WebAp plication( ))
  461                    {
  462                         continue;
  463                    }
  464                    Info ("Uninstal ling Web A pplication  " + vixWe bApplicati on.Path);
  465                    Unin stallWebAp plication( config, vi xWebApplic ation, tru e);
  466                }
  467                Info("Al l web appl ications h ave been u ninstalled .");
  468           }
  469           // / <summary >
  470           //
  471           // / </summar y>
  472           // / <param n ame="confi g"></param >
  473           pu blic stati c void Dep loyVixWebA pplication s(IVixConf igurationP arameters  config)
  474           {
  475                VixWebAp plication[ ] vixWebAp plications  = Manifes t.VixWebAp plications ;
  476  
  477                foreach  (VixWebApp lication v ixWebAppli cation in  vixWebAppl ications)
  478                {
  479                    if ( vixWebAppl ication.Op tion == Vi xWebApplic ationOptio n.Remove)
  480                    {
  481                         continue;  // dont de ploy web a pplication s marked a s remove
  482                    }
  483  
  484                    if ( vixWebAppl ication.Is Axis2WebAp plication( ))
  485                    {
  486                         Info("Inst alling Axi s2 Web App lication "  + vixWebA pplication .War);
  487                         string sou rceJarFile Spec = Pat h.Combine( TomcatFaca de.TomcatW ebApplicat ionFolder,  vixWebApp lication.W ar);
  488                         string tar getJarFile Spec = Pat h.Combine( TomcatFaca de.TomcatA xis2WebApp licationFo lder, vixW ebApplicat ion.War);
  489                         File.Copy( sourceJarF ileSpec, t argetJarFi leSpec);
  490                         File.Delet e(sourceJa rFileSpec) ;
  491                    }
  492                    else
  493                    {
  494                         Info("Inst alling Web  Applicati on " + vix WebApplica tion.Path) ;
  495                         string war FileSpec =  Path.Comb ine(Tomcat Facade.Tom catWebAppl icationFol der, vixWe bApplicati on.War);
  496                         Debug.Asse rt(File.Ex ists(warFi leSpec));
  497  
  498                         string pat hFolder =  vixWebAppl ication.Pa th.StartsW ith("/") ?  vixWebApp lication.P ath.Substr ing(1) : v ixWebAppli cation.Pat h;
  499                         string web AppPathFol der = Path .Combine(T omcatFacad e.TomcatWe bApplicati onFolder,  pathFolder );
  500                         if (Direct ory.Exists (webAppPat hFolder))  // safety  net - shou ld not hap pen
  501                         {
  502                             Uninst allWebAppl ication(co nfig, vixW ebApplicat ion, false );
  503                         }
  504                         Directory. CreateDire ctory(webA ppPathFold er);
  505                         ZipUtiliti es.UnZip(w arFileSpec , webAppPa thFolder);  // unzip  the war to  the speci fied path
  506                         File.Delet e(warFileS pec); // d elete the  war so tha t it does  not auto d eploy
  507                    }
  508                }
  509  
  510                AddWebAp pContextEl ements(Pat h.Combine( TomcatFaca de.TomcatC onfigurati onFolder,  "server.xm l"), confi g);
  511           }
  512  
  513           // / <summary >
  514           //
  515           // / </summar y>
  516           // / <param n ame="serve rXmlFilesp ec"></para m>
  517           pu blic stati c void Add WebAppCont extElement s(string s erverXmlFi lespec, IV ixConfigur ationParam eters conf ig)
  518           {
  519                Debug.As sert(File. Exists(ser verXmlFile spec));
  520                XmlDocum ent xmlSer verDom = n ew XmlDocu ment();
  521                xmlServe rDom.Load( serverXmlF ilespec);
  522  
  523                Logger() .Info("Rep lacing con nector for  " + confi g.VixRole) ; // any i nfo provid ed to the  presentati on layer w ill be log ged.
  524  
  525                if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way)
  526                {
  527                    XmlN ode xmlHtt pConnector  = xmlServ erDom.Sele ctSingleNo de("Server /Service/C onnector[@ port='xxx' ]"); // Ge t port fro m config
  528                    Debu g.Assert(x mlHttpConn ector != n ull);
  529                    Logg er().Info( "Updating  httpConnec tor with "  + config. CvixHttpCo nnectorPor t.ToString ());
  530                    Upda teHttpConn ector(conf ig, xmlHtt pConnector );
  531  
  532                    XmlN ode xmlHtt psConnecto r = xmlSer verDom.Sel ectSingleN ode("Serve r/Service/ Connector[ @port='yyy ']"); // G et port fr om config
  533                    Debu g.Assert(x mlHttpsCon nector !=  null);
  534                    Logg er().Info( "Updating  httpsConne ctor with  " + config .CvixHttps ConnectorP ort.ToStri ng());
  535                    Upda teHttpsCon nector(con fig, xmlHt tpsConnect or);
  536                       
  537                    //** ** Xca is  no longer  used *** 
  538                    //Xm lNode xmlX caConnecto r = null;
  539                    //if  (config.U seOpenSslF orXCAConne ctor)
  540                    //{
  541                         // delete  the connec tor that w ould be us ed with js ee
  542                         //xmlXcaCo nnector =  xmlServerD om.SelectS ingleNode( "Server/Se rvice/Conn ector[@por t='yyy']") ; // Get p ort from c onfig
  543                         //Debug.As sert(xmlXc aConnector  != null);
  544                         //xmlXcaCo nnector.Pa rentNode.R emoveChild (xmlXcaCon nector);
  545                         //xmlXcaCo nnector =  xmlServerD om.SelectS ingleNode( "Server/Se rvice/Conn ector[@por t='zzz']") ; // Get p ort from c onfig
  546                         //Debug.As sert(xmlXc aConnector  != null);
  547                         //UpdateOp enSslXcaCo nnector(co nfig, xmlX caConnecto r);
  548                    //}
  549                    //el se
  550                    //     {
  551                         // delete  the connec tor that w ould be us ed with Op enSSL
  552                         //xmlXcaCo nnector =  xmlServerD om.SelectS ingleNode( "Server/Se rvice/Conn ector[@por t='zzz']") ; // Get p ort from c onfig
  553                         //Debug.As sert(xmlXc aConnector  != null);
  554                         //xmlXcaCo nnector.Pa rentNode.R emoveChild (xmlXcaCon nector);
  555                         //xmlXcaCo nnector =  xmlServerD om.SelectS ingleNode( "Server/Se rvice/Conn ector[@por t='yyy']") ; // Get p ort from c onfig
  556                         //Debug.As sert(xmlXc aConnector  != null);
  557                         //UpdateXc aConnector (config, x mlXcaConne ctor);
  558                    //}
  559                }
  560                else if  (config.Vi xRole == V ixRoleType .SiteVix | | config.V ixRole ==  VixRoleTyp e.DicomGat eway || co nfig.VixRo le == VixR oleType.Mi niVix) //  configure  a SSL conn ector to b e used jav a logs
  561                {
  562                    XmlN ode xmlHtt psConnecto r = xmlSer verDom.Sel ectSingleN ode("Serve r/Service/ Connector[ @port='443 ']");
  563                    if ( xmlHttpsCo nnector !=  null)
  564                    {
  565                         UpdateVixH digHttpsCo nnector(co nfig, xmlH ttpsConnec tor);
  566                    }
  567                }
  568                ////else  if (confi g.VixRole  == VixRole Type.Dicom Gateway)
  569                ////{
  570                ////     XmlNode xm lHttpsConn ector = xm lServerDom .SelectSin gleNode("S erver/Serv ice/Connec tor[@port= '443']");
  571                ////     if (xmlHtt psConnecto r != null)
  572                ////     {
  573                ////         Update HdigHttpsC onnector(c onfig, xml HttpsConne ctor);
  574                ////     }
  575                ////}
  576  
  577                XmlNode  xmlConnect or = xmlSe rverDom.Se lectSingle Node("Serv er/Service /Connector [@port='84 43']");
  578                if (xmlC onnector ! = null) //  patch 34  doesnt hav e a federa tion inter face
  579                {
  580                    Upda teFederati onConnecto r(config,  xmlConnect or);
  581                }
  582  
  583                XmlNode  xmlNioConn ector = xm lServerDom .SelectSin gleNode("S erver/Serv ice/Connec tor[@port= '8442']");
  584                if (xmlN ioConnecto r != null)  // patch  34 doesnt  have a fed eration in terface
  585                {
  586                    Upda teFederati onConnecto r(config,  xmlNioConn ector);
  587                }
  588                
  589                // updat e Engine e lement wit h default  host name
  590                XmlNode  xmlEngine  = xmlServe rDom.Selec tSingleNod e("Server/ Service[@n ame='Catal ina']/Engi ne");
  591                UpdateEn gine(confi g, xmlEngi ne);
  592                
  593                // updat e Host ele ment name  attribute
  594                XmlNode  xmlHost =  xmlEngine. SelectSing leNode("./ Host");
  595                UpdateHo st(config,  xmlHost);
  596                
  597                // updat e Realm el ement site  informati on
  598                XmlNode  xmlRealm =  xmlHost.S electSingl eNode("./R ealm");
  599                UpdateRe alm(config , xmlRealm );
  600                
  601                // write  context e lements fo r each web  applicati on
  602                VixWebAp plication[ ] vixWebAp plications  = Manifes t.VixWebAp plications ;
  603                foreach  (VixWebApp lication v ixWebAppli cation in  vixWebAppl ications)
  604                {
  605                    if ( vixWebAppl ication.Op tion == Vi xWebApplic ationOptio n.Remove)
  606                    {
  607                         continue;
  608                    }
  609  
  610                    if ( vixWebAppl ication.Us eContextFo lder == tr ue) 
  611                    {
  612                         continue;  // web app  provides  its own ME TA-INF\con text.xml -  no contex t tag need ed in serv er.xml
  613                    }
  614  
  615                    XmlE lement xml Context =  CreateCont ext(config , xmlServe rDom, vixW ebApplicat ion);
  616                    xmlH ost.Insert After(xmlC ontext, xm lRealm);
  617                }
  618  
  619                // confi gure the D icomSCPSer vice servi ce child e lements if  present
  620                xmlEngin e = xmlSer verDom.Sel ectSingleN ode("Serve r/Service[ @name='Dic omSCPServi ce']/Engin e");
  621                if (xmlE ngine != n ull)
  622                {
  623                    // u pdate Engi ne element  with defa ult host n ame
  624                    Upda teEngine(c onfig, xml Engine);
  625                    // u pdate Real m element  site infor mation
  626                    xmlR ealm = xml Engine.Sel ectSingleN ode("./Rea lm");
  627                    Upda teRealm(co nfig, xmlR ealm);
  628                    // u pdate Host  element n ame attrib ute
  629                    xmlH ost = xmlE ngine.Sele ctSingleNo de("./Host ");
  630                    Upda teHost(con fig, xmlHo st);
  631                }
  632  
  633                // confi gure the P eriodicCom mandServic e service  child elem ents if pr esent
  634                xmlEngin e = xmlSer verDom.Sel ectSingleN ode("Serve r/Service[ @name='Per iodicComma ndService' ]/Engine") ;
  635                if (xmlE ngine != n ull)
  636                {
  637                    // u pdate Engi ne element  with defa ult host n ame
  638                    Upda teEngine(c onfig, xml Engine);
  639                    // u pdate Real m element  site infor mation
  640                    xmlR ealm = xml Engine.Sel ectSingleN ode("./Rea lm");
  641                    Upda teRealm(co nfig, xmlR ealm);
  642                    // u pdate Host  element n ame attrib ute
  643                    xmlH ost = xmlE ngine.Sele ctSingleNo de("./Host ");
  644                    Upda teHost(con fig, xmlHo st);
  645                }
  646  
  647                // confi gure the P eriodicCom mandServic e service  child elem ents if pr esent
  648                xmlEngin e = xmlSer verDom.Sel ectSingleN ode("Serve r/Service[ @name='Per iodicROICo mmandServi ce']/Engin e");
  649                if (xmlE ngine != n ull)
  650                {
  651                    // u pdate Engi ne element  with defa ult host n ame
  652                    Upda teEngine(c onfig, xml Engine);
  653                    // u pdate Real m element  site infor mation
  654                    xmlR ealm = xml Engine.Sel ectSingleN ode("./Rea lm");
  655                    Upda teRealm(co nfig, xmlR ealm);
  656                    // u pdate Host  element n ame attrib ute
  657                    xmlH ost = xmlE ngine.Sele ctSingleNo de("./Host ");
  658                    Upda teHost(con fig, xmlHo st);
  659                }
  660  
  661                xmlServe rDom.Save( serverXmlF ilespec);
  662           }
  663           // ---------- ---------- ---------- ---------- ---------- ------
  664  
  665           pr ivate stat ic void Up dateFedera tionConnec tor(IVixCo nfiguratio nParameter s config,  XmlNode xm lConnector )
  666           {
  667                String s  = Path.Co mbine(VixF acade.GetV ixCertific ateStoreDi r(), FEDER ATION_KEYS TORE_FILEN AME);
  668                String f ederationK eystorePat h = s.Repl ace(@"\",  "/");
  669                s = Path .Combine(V ixFacade.G etVixCerti ficateStor eDir(), FE DERATION_T RUSTSTORE_ FILENAME);
  670                String f ederationT ruststoreP ath = s.Re place(@"\" , "/");
  671  
  672                xmlConne ctor.Attri butes["key storeFile" ].Value =  federation KeystorePa th;
  673                xmlConne ctor.Attri butes["key storePass" ].Value =  config.Fed erationKey storePassw ord;
  674                xmlConne ctor.Attri butes["tru ststoreFil e"].Value  = federati onTruststo rePath;
  675                xmlConne ctor.Attri butes["tru ststorePas s"].Value  = config.F ederationT ruststoreP assword;
  676           }
  677  
  678           pr ivate stat ic void Up dateVixHdi gHttpsConn ector(IVix Configurat ionParamet ers config , XmlNode  xmlConnect or)
  679           {
  680                String s  = Path.Co mbine(VixF acade.GetV ixCertific ateStoreDi r(), JAVAL OG_KEYSTOR E_FILENAME );
  681                String k eystorePat h = s.Repl ace(@"\",  "/");
  682  
  683                xmlConne ctor.Attri butes["key storeFile" ].Value =  keystorePa th;
  684                xmlConne ctor.Attri butes["key storePass" ].Value =  config.Fed erationTru ststorePas sword; //  JavaLog ce rt and Fed eration tr uststore u se the sam e password
  685           }
  686  
  687           // //private  static voi d UpdateVi xHttpsConn ector(IVix Configurat ionParamet ers config , XmlNode  xmlConnect or)
  688           // //{
  689           // //    Stri ng s = Pat h.Combine( VixFacade. GetVixCert ificateSto reDir(), F EDERATION_ KEYSTORE_F ILENAME);
  690           // //    Stri ng federat ionKeystor ePath = s. Replace(@" \", "/");
  691  
  692           // //    xmlC onnector.A ttributes[ "keystoreF ile"].Valu e = federa tionKeysto rePath;
  693           // //    xmlC onnector.A ttributes[ "keystoreP ass"].Valu e = config .Federatio nKeystoreP assword;
  694           // //}
  695  
  696           // private st atic void  UpdateXcaC onnector(I VixConfigu rationPara meters con fig, XmlNo de xmlConn ector)
  697           // {
  698           //     String  s = Path. Combine(Vi xFacade.Ge tVixCertif icateStore Dir(), FED ERATION_KE YSTORE_FIL ENAME); // XCA_KEYSTO RE_FILENAM E);
  699           //     String  xcaKeysto rePath = s .Replace(@ "\", "/");
  700           //     s = Pa th.Combine (VixFacade .GetVixCer tificateSt oreDir(),  FEDERATION _TRUSTSTOR E_FILENAME ); //XCA_T RUSTSTORE_ FILENAME);
  701           //     String  xcaTrusts torePath =  s.Replace (@"\", "/" );
  702  
  703           //     xmlCon nector.Att ributes["p ort"].Valu e = config .XcaConnec torPort.To String();
  704           //     xmlCon nector.Att ributes["k eystoreFil e"].Value  = xcaKeyst orePath;
  705           //     xmlCon nector.Att ributes["k eystorePas s"].Value  = config.F ederationK eystorePas sword; //  reusing fe deration c redentials ? Dont thi nk it matt ers...
  706           //     xmlCon nector.Att ributes["t ruststoreF ile"].Valu e = xcaTru ststorePat h;
  707           //     xmlCon nector.Att ributes["t ruststoreP ass"].Valu e = config .Federatio nTruststor ePassword;   // reusi ng federat ion creden tials? Don t think it  matters.. .
  708           // }
  709  
  710           // private st atic void  UpdateOpen SslXcaConn ector(IVix Configurat ionParamet ers config , XmlNode  xmlConnect or)
  711           // {
  712           //     String  s = Path. Combine(Vi xFacade.Ge tVixCertif icateStore Dir(), XCA _CERTIFICA TE_FILENAM E);
  713           //     String  xcaKeysto rePath = s .Replace(@ "\", "/");
  714           //     s = Pa th.Combine (VixFacade .GetVixCer tificateSt oreDir(),  XCA_PRIVAT E_KEY_FILE NAME);
  715           //     String  xcaPrivat eKeyPath =  s.Replace (@"\", "/" );
  716  
  717           //     xmlCon nector.Att ributes["p ort"].Valu e = config .XcaConnec torPort.To String();
  718           //     xmlCon nector.Att ributes["S SLCertific ateFile"]. Value = xc aKeystoreP ath;
  719           //     xmlCon nector.Att ributes["S SLCertific ateKeyFile "].Value =  xcaPrivat eKeyPath;
  720           //     //xmlC onnector.A ttributes[ "SSLPasswo rd"].Value  = config. Federation KeystorePa ssword; //  reusing f ederation  credential s? Dont th ink it mat ters...
  721           // }
  722  
  723           pr ivate stat ic void Up dateHttpCo nnector(IV ixConfigur ationParam eters conf ig, XmlNod e xmlConne ctor)
  724           {
  725                xmlConne ctor.Attri butes["por t"].Value  = config.C vixHttpCon nectorPort .ToString( );
  726           }
  727  
  728           pr ivate stat ic void Up dateHttpsC onnector(I VixConfigu rationPara meters con fig, XmlNo de xmlConn ector)
  729           {
  730                xmlConne ctor.Attri butes["por t"].Value  = config.C vixHttpsCo nnectorPor t.ToString ();
  731                String s  = Path.Co mbine(VixF acade.GetV ixCertific ateStoreDi r(), CVIX_ KEYSTORE_F ILENAME);
  732                String k eystorePat h = s.Repl ace(@"\",  "/");
  733                xmlConne ctor.Attri butes["key storeFile" ].Value =  keystorePa th;
  734                xmlConne ctor.Attri butes["key storePass" ].Value =  config.Cvi xCertPassw ord;
  735  
  736                KeytoolF acade.Crea teJksFromP fx(
  737                    Java Facade.Get ActiveJreP athLocatio nIndepende nt() + @"\ bin",
  738                    conf ig.CvixCer tFilename,  s, config .CvixCertP assword);
  739           }
  740  
  741           pr ivate stat ic void Up dateEngine (IVixConfi gurationPa rameters c onfig, Xml Node xmlEn gine)
  742           {
  743                string h ostName =  config.Sit eNumber +  ".med.va.g ov";
  744                xmlEngin e.Attribut es["defaul tHost"].Va lue = host Name;
  745           }
  746  
  747           pr ivate stat ic void Up dateHost(I VixConfigu rationPara meters con fig, XmlNo de xmlHost )
  748           {
  749                string h ostName =  config.Sit eNumber +  ".med.va.g ov";
  750                xmlHost. Attributes ["name"].V alue = hos tName;
  751           }
  752  
  753           // / <summary >
  754           // / Checks t o see if t he current  server is  a develop ment CVIX.  Very frag ile!!!
  755           // / </summar y>
  756           // / <param n ame="confi g"></param >
  757           // / <returns ><c>true</ c> if the  current se rver is a  developmen t CVIX; <c >false</c>  otherwise </returns>
  758           pr ivate stat ic bool Is Developmen tCvix(IVix Configurat ionParamet ers config )
  759           {
  760                bool isD evCvix = f alse;
  761                if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way)
  762                {
  763                    // f ragile - m ust be upd ated as th e test env ironment i s updated  - last upd ate 9/25/2 012
  764                      if (config .VixServer NameProp.T oUpper() = = " P I
I
" || confi g.VixServe rNameProp. ToUpper()  == " P I
I
" || confi g.VixServe rNameProp. ToUpper()  == "P
I
I
" ||
  765                          config.Vix ServerName Prop.ToUpp er() == "P
I
I
" || confi g.VixServe rNameProp. ToUpper()  == "P
I
I
" || confi g.VixServe rNameProp. ToUpper()  == " P I
I
" ||
  766                         /* Silver  Spring Int eragency C VIX server s */
  767                          config.Vix ServerName Prop.ToUpp er() == " P I
I
" || confi g.VixServe rNameProp. ToUpper()  == " P I
I
" ||
  768                         /* Martins burg Inter agency CVI X servers  */
  769                          config.Vix ServerName Prop.ToUpp er() == " PI I
" || confi g.VixServe rNameProp. ToUpper()  == " PI I
")
  770                    {
  771                         isDevCvix  = true;
  772                    }
  773                }
  774                return i sDevCvix;
  775           }
  776  
  777           // / <summary >
  778           // / Checks t o see if t he current  server is  a develop ment inter agency CVI X. Very fr agile!!!
  779           // / </summar y>
  780           // / <param n ame="confi g"></param >
  781           // / <returns ><c>true</ c> if the  current se rver is a  developeme nt interag ency CVIX;  <c>false< /c> otherw ise</retur ns>
  782           pr ivate stat ic bool Is Developmen tInteragen cyCvix(IVi xConfigura tionParame ters confi g)
  783           {
  784                bool isI nteragency Cvix = fal se;
  785                if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way)
  786                {
  787                    // f ragile - m ust be upd ated as th e test env ironment i s updated  - last upd ate 9/25/2 012
  788                    if ( /* Silver  Spring Int eragency C VIX server s */
  789                          config.Vix ServerName Prop.ToUpp er() == " P I
I
" || confi g.VixServe rNameProp. ToUpper()  == " P I
I
" ||
  790                         /* Martins burg Inter agency CVI X servers  */
  791                          config.Vix ServerName Prop.ToUpp er() == " PI I
" || confi g.VixServe rNameProp. ToUpper()  == " PI I
")
  792                    {
  793                         isInterage ncyCvix =  true;
  794                    }
  795                }
  796                return i sInteragen cyCvix;
  797           }
  798  
  799           pr ivate stat ic void Up dateRealm( IVixConfig urationPar ameters co nfig, XmlN ode xmlRea lm)
  800           {
  801                xmlRealm .Attribute s["siteNum ber"].Valu e = config .SiteNumbe r;
  802                xmlRealm .Attribute s["siteAbb reviation" ].Value =  config.Sit eAbbreviat ion;
  803                xmlRealm .Attribute s["siteNam e"].Value  = config.S iteName;
  804                xmlRealm .Attribute s["vistaSe rver"].Val ue = confi g.VistaSer verName;
  805                xmlRealm .Attribute s["vistaPo rt"].Value  = config. VistaServe rPort;
  806                if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way && xml Realm.Attr ibutes["ad ditionalUs erRoles"]  != null)
  807                {
  808                    xmlR ealm.Attri butes["add itionalUse rRoles"].V alue = con fig.Statio n200UserNa me + ":xca ,vista-use r";
  809                    // s et CPRS co ntext to f alse in th e test env ironment f or now
  810                    if ( config.Sta tion200Use rName.ToLo wer() == " testing_1"  || config .Station20 0UserName. ToLower()  == "boatin g1")
  811                    {
  812                         if (xmlRea lm.Attribu tes["setCp rsContext" ] != null)
  813                         {
  814                             xmlRea lm.Attribu tes["setCp rsContext" ].Value =  "false"; / / Perfrom  local conn ection to  VistA Imag ing in Rea lm - true  would mean  perform a  local Vis tA connect ion
  815                         }
  816                    }
  817                    if ( IsDevelopm entCvix(co nfig) == t rue && IsD evelopment Interagenc yCvix(conf ig) == tru e)
  818                    {
  819                         if (xmlRea lm.Attribu tes["gener ateBseToke n"] != nul l)
  820                         {
  821                             // Don t generate  a BSE tok en because  Station 2 00 token w ill not wo rk with ou r test env ironment -  CAPRI wil l be used  instead.
  822                             xmlRea lm.Attribu tes["gener ateBseToke n"].Value  = "false";
  823                         }
  824                    }
  825                }
  826           }
  827  
  828           pr ivate stat ic XmlElem ent Create Context(IV ixConfigur ationParam eters conf ig, XmlDoc ument xmlS erverDom,  VixWebAppl ication vi xWebApplic ation)
  829           {
  830                XmlEleme nt xmlCont ext = xmlS erverDom.C reateEleme nt("Contex t");
  831                xmlConte xt.SetAttr ibute("coo kies", "fa lse");
  832                xmlConte xt.SetAttr ibute("cro ssContext" , "false") ;
  833                xmlConte xt.SetAttr ibute("doc Base", vix WebApplica tion.DocBa se);
  834                xmlConte xt.SetAttr ibute("pat h", vixWeb Applicatio n.Path);
  835                xmlConte xt.SetAttr ibute("pri vileged",  "false");
  836                xmlConte xt.SetAttr ibute("rel oadable",  "false");
  837                xmlConte xt.SetAttr ibute("use Naming", " true");
  838                return x mlContext;
  839           }
  840  
  841           // ---------- ---------- ---------- -------
  842  
  843           // / <summary >
  844           // / Add or r emoves the  java prop erties req uired by t he ViX to  the Tomcat  Java envi ronment.
  845           // / The only  reason th is method  is public  is for tes ting purpo ses.
  846           // / </summar y>
  847           // / <returns >The set o f Procrun  Java prope rties that  were adde d as part  of the cur rent insta llation.</ returns>
  848           pu blic stati c void App lyVixJavaP ropertiesF romManifes t(IVixConf igurationP arameters  config, bo ol commit)
  849           {
  850                List<Str ing> modif iedOptions InfoList =  new List< String>();
  851                string p arametersK ey = null;
  852                Registry View regVi ew = Regis tryView.Re gistry64;
  853                if (Busi nessFacade .Is64BitOp eratingSys tem())
  854                {
  855                    para metersKey  = @"SOFTWA RE\Wow6432 Node\Apach e Software  Foundatio n\Procrun  2.0\" + To mcatFacade .TomcatSer viceName +  @"\Parame ters\Java" ;
  856                }
  857                else
  858                {
  859                    para metersKey  = @"SOFTWA RE\Apache  Software F oundation\ Procrun 2. 0\" + Tomc atFacade.T omcatServi ceName + @ "\Paramete rs\Java";
  860                }
  861  
  862                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  863                {
  864                    usin g (Registr yKey java  = regKey.O penSubKey( parameters Key, true) )
  865                    {
  866                         Debug.Asse rt(java.Ge tValueKind ("Options" ) == Regis tryValueKi nd.MultiSt ring);
  867                         VixJavaPro perty[] ma nifestVixJ avaPropert ies = Mani fest.GetMa nifestVixJ avaPropert ies(config .ConfigDir );
  868                         Dictionary <String, V ixJavaProp erty> inst alledVixJa vaProperti es = GetIn stalledViX JavaProper ties((Stri ng[])java. GetValue(" Options")) ;
  869  
  870                         foreach (V ixJavaProp erty manif estViXJava Property i n manifest VixJavaPro perties)
  871                         {
  872                             // klu dge - must  fix up jc ifs proper ty file lo cation wit h the sele ction ViX  configurat ion folder
  873                             //if ( manifestVi XJavaPrope rty.Name = = "jcifs.p roperties"  && Manife st.VixIter ation > 6)
  874                             //{
  875                             //     manifestVi XJavaPrope rty.Value  = Path.Com bine(confi g.ConfigDi r, manifes tViXJavaPr operty.Val ue);
  876                             //}
  877  
  878                             if (ma nifestViXJ avaPropert y.Option = = VixJavaP ropertyOpt ion.AddUpd ate)
  879                             {
  880                                 if  (installe dVixJavaPr operties.C ontainsKey (manifestV iXJavaProp erty.Name) )
  881                                 {
  882                                      VixJavaP roperty in stalledViX JavaProper ty = insta lledVixJav aPropertie s[manifest ViXJavaPro perty.Name ];
  883                                      if (inst alledViXJa vaProperty .Value !=  manifestVi XJavaPrope rty.Value)
  884                                      {
  885                                          modi fiedOption sInfoList. Add(instal ledViXJava Property.N ame + " ch anged from  " +
  886                                               installedV iXJavaProp erty.Value  + " to "  + manifest ViXJavaPro perty.Valu e);
  887                                          inst alledViXJa vaProperty .Value = m anifestViX JavaProper ty.Value;
  888                                      }
  889                                 }
  890                                 el se
  891                                 {
  892                                      if (stri ng.IsNullO rEmpty(man ifestViXJa vaProperty .Value))
  893                                      {
  894                                          modi fiedOption sInfoList. Add(manife stViXJavaP roperty.Na me  + " ha s been add ed");
  895                                      }
  896                                      else
  897                                      {
  898                                          modi fiedOption sInfoList. Add(manife stViXJavaP roperty.Na me + "=" +  manifestV iXJavaProp erty.Value
  899                                          + "  has been a dded");
  900                                      }
  901                                      
  902                                      installe dVixJavaPr operties.A dd(manifes tViXJavaPr operty.Nam e, manifes tViXJavaPr operty);
  903                                 }
  904                             }
  905                             else i f (manifes tViXJavaPr operty.Opt ion == Vix JavaProper tyOption.R emove)
  906                             {
  907                                 if  (installe dVixJavaPr operties.C ontainsKey (manifestV iXJavaProp erty.Name) )
  908                                 {
  909                                      modified OptionsInf oList.Add( manifestVi XJavaPrope rty.Name +  "=" + man ifestViXJa vaProperty .Value
  910                                          + "  has been r emoved");
  911                                      installe dVixJavaPr operties.R emove(mani festViXJav aProperty. Name);
  912                                 }
  913                             }
  914                         }
  915  
  916                         if (modifi edOptionsI nfoList.Co unt > 0)
  917                         {
  918                             Info(" Procrun JV M environm ent option s have bee n changed" );
  919                             if (co mmit == tr ue)
  920                             {
  921                                 mo difiedOpti onsInfoLis t.Add("Upd ated Procr un JVM opt ions are a s follows: ");
  922                             }
  923                             else
  924                             {
  925                                 mo difiedOpti onsInfoLis t.Add("Pro crun JVM o ptions tha t would be  written ( commit = f alse):");
  926                             }
  927                             List<S tring> opt ionsList =  new List< String>();
  928                             foreac h (String  key in ins talledVixJ avaPropert ies.Keys)
  929                             {
  930                                 if  (string.I sNullOrEmp ty(install edVixJavaP roperties[ key].Value ))
  931                                 {
  932                                      optionsL ist.Add(in stalledVix JavaProper ties[key]. Prefix + i nstalledVi xJavaPrope rties[key] .Name);
  933                                 }
  934                                 el se
  935                                 {
  936                                      optionsL ist.Add(in stalledVix JavaProper ties[key]. ToString() );
  937                                 }
  938                             }
  939                             modifi edOptionsI nfoList.Ad dRange(opt ionsList);
  940                             if (co mmit == tr ue)
  941                             {
  942                                 ja va.SetValu e("Options ", options List.ToArr ay());
  943                             }
  944                             foreac h (String  option in  modifiedOp tionsInfoL ist)
  945                             {
  946                                 In fo(option) ;
  947                             }
  948                         }
  949                    }
  950                }
  951           }
  952  
  953            / // <summar y>
  954           // / Reformat s a passed  array of  java prope rty string s as used  by Procrun  to establ ish Tomcat  Java envi ronment
  955           // / as a Dic tionary of  VixJavaPr operty obj ects.
  956           // / The only  reason th is method  is public  is for tes ting purpo ses.
  957           // / </summar y>
  958           // / <param n ame="prope rtyList">T he array o f Java pro perties ex pressed as  command l ine parama ters (i.e.  -Dparamet er=value)< /param>
  959           // / <returns >Returns a  Dictionar y of Java  properties  as VixJav aProperty  objects ke yed by nam e</returns >
  960           pu blic stati c Dictiona ry<String,  VixJavaPr operty> Ge tInstalled ViXJavaPro perties(St ring[] pro pertyList)
  961           {
  962                Dictiona ry<String,  VixJavaPr operty> vi xJavaPrope rties = ne w Dictiona ry<String,  VixJavaPr operty>();
  963                string p refix = nu ll;
  964                int pref ixLength =  0;
  965                foreach  (String pr operty in  propertyLi st)
  966                {
  967                    if ( property = = "")
  968                    {
  969                         continue;
  970                    }
  971                    //De bug.Assert (property. StartsWith ("-D") ||  property.S tartsWith( "-X"));
  972                    if ( property.S tartsWith( "-D"))
  973                    {
  974                         prefix = " -D";
  975                         prefixLeng th = 2;
  976                    }
  977                    else  if (prope rty.Starts With("-XX" ))
  978                    {
  979                         prefix = " -XX:";
  980                         prefixLeng th = 4;
  981                    }
  982                    else  if (prope rty.Starts With("-X") )
  983                    {
  984                         prefix = " -X";
  985                         prefixLeng th = 2;
  986                    }
  987                    else  if (prope rty.Starts With("-jav a"))
  988                    {
  989                         prefix = " -j";
  990                         prefixLeng th = 0;
  991                    }
  992                    else
  993                    {
  994                         throw new  Exception( "Unexpecte d prefix i n Java pro perty - wa s expectin g -D or -X X: or -j o r -X " + p roperty);
  995                    }
  996  
  997                    Stri ng s = pro perty.Subs tring(pref ixLength);
  998                    Stri ng[] split s = s.Spli t('=');
  999                    stri ng name =  splits[0]. Trim();
  1000                    stri ng value =  null;
  1001                    if ( splits.Len gth >= 2)
  1002                    {
  1003                         value = sp lits[1].Tr im();
  1004                         if (splits .Length >  2)
  1005                         {
  1006                             for (i nt i = 2;  i < splits .Length; i ++)
  1007                             {
  1008                                 va lue += "="  + splits[ i];
  1009                             }
  1010                             value  = value.Tr im();
  1011                         }
  1012                    }
  1013  
  1014                    VixJ avaPropert y installe dVixJavaPr operty = n ew VixJava Property(V ixJavaProp ertyOption .Installed , prefix,  name, valu e, null);
  1015                    
  1016                    if ( !vixJavaPr operties.C ontainsKey (installed VixJavaPro perty.Name )) 
  1017                    {
  1018                         vixJavaPro perties.Ad d(installe dVixJavaPr operty.Nam e, install edVixJavaP roperty);
  1019                    }
  1020                }
  1021  
  1022                return v ixJavaProp erties;
  1023           }
  1024  
  1025           // / <summary >
  1026           //
  1027           // / </summar y>
  1028           // / <returns ></returns >
  1029           pu blic stati c string G etVixConfi gurationDi rectory()
  1030           {
  1031                String v ixConfigDi r = null;
  1032                String v ixconfig =  Environme nt.GetEnvi ronmentVar iable("vix config", E nvironment VariableTa rget.Machi ne);
  1033                if (vixc onfig != n ull)
  1034                {
  1035                    vixC onfigDir =  vixconfig .Replace(" /", @"\");  // transl ate file s ystem deli miter back  from Java  forward s lash
  1036                }
  1037                return v ixConfigDi r;
  1038           }
  1039  
  1040           // / <summary >
  1041           //
  1042           // / </summar y>
  1043           // / <returns ></returns >
  1044           pu blic stati c String G etLocalVix CacheDirec tory()
  1045           {
  1046                String v ixCacheDir  = null;
  1047                String v ixcache =  Environmen t.GetEnvir onmentVari able("vixc ache", Env ironmentVa riableTarg et.Machine );
  1048                if (vixc ache != nu ll)
  1049                {
  1050                    vixC acheDir =  vixcache.R eplace("/" , @"\"); / / translat e file sys tem delimi ter back f rom Java f orward sla sh
  1051                }
  1052                return v ixCacheDir ;
  1053           }
  1054  
  1055           // / <summary >
  1056           // / This met hod search es for an  existing V IX configu ration fil e in a clu stered ins tall and r eturns the  directory  where the  configura tion resid es
  1057           // / </summar y>
  1058           // / <returns >The direc tory where  the confi guration r esides if  found, nul l otherwis e</returns >
  1059           pu blic stati c string G etExisting FocVixConf igurationD ir()
  1060           {
  1061                Debug.As sert(Clust erFacade.I sServerClu sterNode() );
  1062                DriveInf o[] drives  = GetConf igDrives() ;
  1063  
  1064                foreach  (DriveInfo  drive in  drives)
  1065                {
  1066                    stri ng configD ir = Path. Combine(dr ive.Name,  VixFacade. VIX_CONFIG _DIRECTORY );
  1067                    stri ng filespe c = Path.C ombine(con figDir, VI X_CONFIG_F ILENAME);
  1068                    if ( File.Exist s(filespec ))
  1069                    {
  1070                         return con figDir;
  1071                    }
  1072                }
  1073  
  1074                return n ull;
  1075           }
  1076  
  1077           // / <summary >
  1078           // / Returns  a list of  local driv es that ca n be used  for a loca l VIX cach e or confi guration b ased on De ploymentTy pe
  1079           // / </summar y>
  1080           // / <param n ame="deplo ymentType" ></param>
  1081           // / <returns ></returns >
  1082           pu blic stati c DriveInf o[] GetCon figDrives( )
  1083           {
  1084                List<Dri veInfo> dr ives = new  List<Driv eInfo>();
  1085  
  1086                foreach  (DriveInfo  drive in  FileSystem .Drives)
  1087                {
  1088                    if ( drive.IsRe ady && dri ve.DriveTy pe == Driv eType.Fixe d)
  1089                    {
  1090                         if (IsDriv eOkForDepl oyment(dri ve))
  1091                         {
  1092                             drives .Add(drive );
  1093                         }
  1094                    }
  1095                }
  1096                Debug.As sert(drive s.Count >  0);
  1097                return d rives.ToAr ray();
  1098           }
  1099  
  1100           // / <summary >
  1101           // / Returns  a list of  local driv es that ca n be used  for a loca l VIX cach e or confi guration b ased on De ploymentTy pe
  1102           // / </summar y>
  1103           // / <param n ame="deplo ymentType" ></param>
  1104           // / <returns ></returns >
  1105           pu blic stati c DriveInf o[] GetCac heDrives(V ixDeployme ntType dep loymentTyp e, VixCach eType cach eType, int  cacheSize InGB)
  1106           {
  1107                List<Dri veInfo> dr ives = new  List<Driv eInfo>();
  1108  
  1109                foreach  (DriveInfo  drive in  FileSystem .Drives)
  1110                {
  1111                    if ( drive.IsRe ady && dri ve.DriveTy pe == Driv eType.Fixe d)
  1112                    {
  1113                         if (cacheT ype == Vix CacheType. ExchangeTi meStorageE victionLoc alFilesyst em && driv e.Availabl eFreeSpace  < (cacheS izeInGB *  ONE_GIGBYT E))
  1114                         {
  1115                             contin ue;
  1116                         }
  1117  
  1118                         if (IsDriv eOkForDepl oyment(dri ve))
  1119                         {
  1120                             drives .Add(drive );
  1121                         }
  1122                    }
  1123                }
  1124                Debug.As sert(drive s.Count >  0);
  1125                return d rives.ToAr ray();
  1126           }
  1127  
  1128           pu blic stati c DriveInf o[] GetCac heAllDrive s(VixDeplo ymentType  deployment Type, VixC acheType c acheType,  int cacheS izeInGB)
  1129           {
  1130                List<Dri veInfo> dr ives = new  List<Driv eInfo>();
  1131  
  1132                foreach  (DriveInfo  drive in  DriveInfo. GetDrives( ))
  1133                {
  1134                    if ( drive.IsRe ady)
  1135                         drives.Add (drive);
  1136                }
  1137                Debug.As sert(drive s.Count >  0);
  1138                return d rives.ToAr ray();
  1139           }
  1140  
  1141           // / <summary >
  1142           //
  1143           // / </summar y>
  1144           // / <returns ></returns >
  1145           pu blic stati c String G etDefaultL ocalVixCac heDrive(Vi xDeploymen tType depl oymentType , VixCache Type cache Type, int  cacheSizeI nGB)
  1146           {
  1147                String v ixCacheDri ve = null;
  1148                DriveInf o mostFree Space = nu ll;
  1149                Info("Ge tDefaultLo calVixCach eDrive:");
  1150  
  1151                foreach  (DriveInfo  drive in  FileSystem .Drives)
  1152                {
  1153                    if ( drive.IsRe ady && dri ve.DriveTy pe == Driv eType.Fixe d)
  1154                    {
  1155                         if (IsDriv eOkForDepl oyment(dri ve))
  1156                         {
  1157                             // don t recommen d the quor um drive a s the defa ult (but a llow it)
  1158                             if (Cl usterFacad e.IsCluste rQuorumDri ve(drive))
  1159                             {
  1160                                 In fo("Drive  " + drive. Name + " i s quorum d rive - ski pping");
  1161                                 co ntinue;
  1162                             }
  1163  
  1164                             if (ca cheType ==  VixCacheT ype.Exchan geTimeStor ageEvictio nLocalFile system &&  drive.Avai lableFreeS pace < (ca cheSizeInG B * ONE_GI GBYTE))
  1165                             {
  1166                                 In fo("Drive  " + drive. Name + " h as less th an " + cac heSizeInGB .ToString( ) + " free  space - s kipping");
  1167                                 co ntinue;
  1168                             }
  1169  
  1170                             if (mo stFreeSpac e == null  || drive.T otalFreeSp ace > most FreeSpace. TotalFreeS pace)
  1171                             {
  1172                                 mo stFreeSpac e = drive;
  1173                                 In fo("Drive  " + drive. Name + " i s a candid ate");
  1174                             }
  1175                         }
  1176                    }
  1177                }
  1178  
  1179                Debug.As sert(mostF reeSpace ! = null);
  1180                vixCache Drive = mo stFreeSpac e.Name.ToU pper();
  1181                return v ixCacheDri ve;
  1182           }
  1183  
  1184           // / <summary >
  1185           //
  1186           // / </summar y>
  1187           // / <returns ></returns >
  1188           pu blic stati c String G etFullyQua ifiedHdigD icomDirect ory()
  1189           {
  1190                Info("Ge tFullyQuai fiedHdigDi comDirecto ry: ");
  1191  
  1192                foreach  (DriveInfo  drive in  FileSystem .Drives)
  1193                {
  1194                    if ( drive.IsRe ady && dri ve.DriveTy pe == Driv eType.Fixe d)
  1195                    {
  1196                         string dic omDirector y = drive. Name + Vix Facade.HDI G_DICOM_DI RECTORY;
  1197                         if (Direct ory.Exists (dicomDire ctory))
  1198                         {
  1199                             Info(" \tFound "  + dicomDir ectory);
  1200                             return  dicomDire ctory;
  1201                         }
  1202                    }
  1203                }
  1204  
  1205                Info("\t Found null ");
  1206                return n ull;
  1207           }
  1208  
  1209           // / <summary >
  1210           //
  1211           // / </summar y>
  1212           // / <param n ame="deplo ymentType" ></param>
  1213           // / <param n ame="cache Type"></pa ram>
  1214           // / <param n ame="cache SizeInGB"> </param>
  1215           // / <returns ></returns >
  1216           pu blic stati c String G etDefaultV ixConfigDr ive(VixDep loymentTyp e deployme ntType, Vi xCacheType  cacheType , int cach eSizeInGB)
  1217           {
  1218                if (depl oymentType  == VixDep loymentTyp e.SingleSe rver)
  1219                {
  1220                    Stri ng systemD rive = Env ironment.G etEnvironm entVariabl e("SystemD rive", Env ironmentVa riableTarg et.Process ).ToUpper( ) + @"\";
  1221                    retu rn systemD rive;
  1222                }
  1223                else
  1224                {
  1225                    retu rn GetDefa ultLocalVi xCacheDriv e(deployme ntType, ca cheType, c acheSizeIn GB);
  1226                }
  1227           }
  1228  
  1229           // / <summary >
  1230           // /  Returns  the direc tory where  the VIX k eystore an d truststo re files w ill go.
  1231           // / </summar y>
  1232           // / <returns ></returns >
  1233           pu blic stati c String G etVixCerti ficateStor eDir()
  1234           {
  1235                String s ystemDrive  = Environ ment.GetEn vironmentV ariable("S ystemDrive ", Environ mentVariab leTarget.P rocess).To Upper() +  @"\";
  1236                return P ath.Combin e(systemDr ive, VIX_C ERTSTORE_D IRECTORY);
  1237           }
  1238  
  1239  
  1240           pu blic stati c void Del eteLocalCa cheRegions (IVixConfi gurationPa rameters c onfig)
  1241           {
  1242                Logger() .Info(Info ("Deleting  files fro m the loca l VIX cach e."));
  1243                Info("Th is may tak e several  minutes -  please be  patient.") ;
  1244                string b aseCacheDi r = config .LocalCach eDir.Repla ce("/", @" \");
  1245                DeleteCa cheRegion( baseCacheD ir, DOD_ME TADATA_REG ION);
  1246                DeleteCa cheRegion( baseCacheD ir, DOD_IM AGE_REGION );
  1247                DeleteCa cheRegion( baseCacheD ir, VA_MET ADATA_REGI ON);
  1248                DeleteCa cheRegion( baseCacheD ir, VA_IMA GE_REGION) ;
  1249                Info("Th e VIX cach e has been  cleared." );
  1250           }
  1251  
  1252  
  1253           #e ndregion
  1254  
  1255           #r egion priv ate utilit y methods
  1256  
  1257           // / <summary >
  1258           // / Recursiv ely remove  read only  attribute s from all  files in  the specif ied folder  and its s ubfolders.
  1259           // / </summar y>
  1260           // / <param n ame="paren tFolder">T he parent  folder.</p aram>
  1261           // / <remarks ></remarks >
  1262           st atic priva te void Re moveReadOn lyAttribut es(String  parentFold er)
  1263           {
  1264                String[]  folders =  Directory .GetDirect ories(pare ntFolder);
  1265                long fol derCount =  folders.L ength;
  1266  
  1267                Director yInfo pare ntFolderIn fo = new D irectoryIn fo(parentF older);
  1268                foreach  (FileInfo  fileInfo i n parentFo lderInfo.G etFiles())
  1269                {
  1270                    File .SetAttrib utes(fileI nfo.FullNa me, FileAt tributes.N ormal);
  1271                }
  1272  
  1273                foreach  (String fo lder in fo lders)
  1274                {
  1275                    Remo veReadOnly Attributes (folder);
  1276                }
  1277           }
  1278  
  1279           // / <summary >
  1280           // / Register s the or u nregisters  an ocx fi le
  1281           // / </summar y>
  1282           // / <param n ame="ocxFi lespec">Th e ocx file spec to re gister or  unregusrer .</param>
  1283           // / <param n ame="regis ter">if se t to <c>tr ue</c> [re gister]; < c>false</c > [unregis ter].</par am>
  1284           // / <returns >command p rocessor e xit code w here 0 is  success</r eturns>
  1285           // / <remarks ></remarks >
  1286           pr ivate stat ic int Reg isterOrUnr egisterOcx (string oc xFilespec,  bool regi ster)
  1287           {
  1288                int exit Code = 0;  // externa l process  executed o k - comman d shell co nvention
  1289  
  1290                using (P rocess ext ernalProce ss = new P rocess())
  1291                {
  1292                    exte rnalProces s.StartInf o.FileName  = "regsvr 32";
  1293                    exte rnalProces s.StartInf o.Argument s = (regis ter ? "/s"  : "/s /u" ) + " " +  ocxFilespe c;
  1294                    exte rnalProces s.StartInf o.WorkingD irectory =  Path.GetD irectoryNa me(ocxFile spec); ;
  1295                    exte rnalProces s.StartInf o.UseShell Execute =  false;
  1296                    exte rnalProces s.StartInf o.CreateNo Window = t rue;
  1297                    exte rnalProces s.Start();
  1298  
  1299                    try
  1300                    {
  1301                         do
  1302                         {
  1303                             DoEven ts();
  1304                             Thread .Sleep(500 );
  1305                             extern alProcess. Refresh();
  1306                         } while (! externalPr ocess.HasE xited);
  1307                         exitCode =  externalP rocess.Exi tCode;
  1308                    }
  1309                    fina lly
  1310                    {
  1311                         externalPr ocess.Clos e();
  1312                    }
  1313                }
  1314  
  1315                return e xitCode;
  1316           }
  1317  
  1318           // / <summary >
  1319           //
  1320           // / </summar y>
  1321           // / <param n ame="deplo ymentType" ></param>
  1322           // / <returns ></returns >
  1323           pr ivate stat ic bool Is DriveOkFor Deployment (DriveInfo  drive)
  1324           {
  1325                bool isD riveOk = t rue;
  1326                String s ystemDrive  = Environ ment.GetEn vironmentV ariable("S ystemDrive ", Environ mentVariab leTarget.P rocess).To Upper() +  @"\";
  1327  
  1328                try
  1329                {
  1330                    if ( drive.Driv eType == D riveType.F ixed && dr ive.IsRead y == true)
  1331                    {
  1332                         if (drive. Name.ToUpp er() == sy stemDrive)  // for FO C clusters , system d rive is no t shared
  1333                         {
  1334                             if (Cl usterFacad e.IsServer ClusterNod e())
  1335                             {
  1336                                 is DriveOk =  false;
  1337                             }
  1338                         }
  1339                    }
  1340                    else
  1341                    {
  1342                         isDriveOk  = false;
  1343                    }
  1344                }
  1345                catch (E xception e x)
  1346                {
  1347                    Info (ex.Messag e);
  1348                    isDr iveOk = fa lse;
  1349                }
  1350                //finall y
  1351                //{
  1352                //    In fo(drive.N ame + (isD riveOk ? "  is OK for  cache or  config fil es" : "is  not OK for  cache or  config fil es"));
  1353                //}
  1354  
  1355                return i sDriveOk;
  1356           }
  1357            
  1358           // / <summary >
  1359           // / A helper  method to  wrap the  infoDelega te member,  which if  non null p rovide a w ay to repo rt status  to the 
  1360           // / user int erface.
  1361           // / </summar y>
  1362           // / <param n ame="infoM essage">me ssage to d isplay in  the user i nterface.< /param>
  1363           // / <returns >the messa ge string  passed in  the infoMe ssage para meter to s upport cha ining.</re turns>
  1364           pr ivate stat ic String  Info(Strin g infoMess age)
  1365           {
  1366                if (info Delegate ! = null)
  1367                {
  1368                    info Delegate(i nfoMessage );
  1369                }
  1370                Logger() .Info(info Message);  // any inf o provided  to the pr esentation  layer wil l be logge d.
  1371                return i nfoMessage ;
  1372           }
  1373  
  1374           // / <summary >
  1375           //
  1376           // / </summar y>
  1377           pr ivate stat ic void Do Events()
  1378           {
  1379                if (appE ventsDeleg ate != nul l)
  1380                {
  1381                    appE ventsDeleg ate();
  1382                }
  1383           }
  1384  
  1385           // / <summary >
  1386           // / Retrieve  a logger  for this c lass.
  1387           // / </summar y>
  1388           // / <returns >A logger  as a ILog  interface. </returns>
  1389           pr ivate stat ic ILog Lo gger()
  1390           {
  1391                return L ogManager. GetLogger( typeof(Vix Facade).Na me);
  1392           }
  1393  
  1394           // / <summary >
  1395           //
  1396           // / </summar y>
  1397           // / <param n ame="filen ame"></par am>
  1398           // / <param n ame="targe tDir"></pa ram>
  1399           pr ivate stat ic void De leteHelper (String fi lename, St ring targe tDir)
  1400           {
  1401                String t argetPath  = Path.Com bine(targe tDir, file name);
  1402                if (File .Exists(ta rgetPath))
  1403                {
  1404                    Info ("Deleting  deprecate d file " +  targetPat h);
  1405                    File .Delete(ta rgetPath);
  1406                }
  1407           }
  1408  
  1409           // / <summary >
  1410           //
  1411           // / </summar y>
  1412           // / <param n ame="comma ndParamete rs"></para m>
  1413           // / <param n ame="paylo adPath"></ param>
  1414           // / <param n ame="confi g"></param >
  1415           pr ivate stat ic void Ru nJavaUtili ty(String  commandPar ameters, I VixConfigu rationPara meters con fig)
  1416           {
  1417                String p ayloadJar  = Path.Com bine(VixFa cade.Manif est.Payloa dPath, @"s erver\jars ");
  1418                String j avaExeFile spec = Pat h.Combine( JavaFacade .GetActive JavaPath(J avaFacade. IsActiveJr eInstalled ()), @"bin \java.exe" );
  1419  
  1420                using (P rocess ext ernalProce ss = new P rocess())
  1421                {
  1422                    exte rnalProces s.StartInf o.FileName  = javaExe Filespec;
  1423                    exte rnalProces s.StartInf o.Argument s = comman dParameter s;
  1424                    exte rnalProces s.StartInf o.WorkingD irectory =  payloadJa r;
  1425                    exte rnalProces s.StartInf o.UseShell Execute =  false;
  1426                    exte rnalProces s.StartInf o.CreateNo Window = t rue; // DK B - 5/25/1 0
  1427                    if ( externalPr ocess.Star tInfo.Envi ronmentVar iables.Con tainsKey(" vixconfig" ))
  1428                    {
  1429                         externalPr ocess.Star tInfo.Envi ronmentVar iables.Rem ove("vixco nfig");
  1430                    }
  1431                    exte rnalProces s.StartInf o.Environm entVariabl es.Add("vi xconfig",  config.Con figDir);
  1432                    if ( externalPr ocess.Star tInfo.Envi ronmentVar iables.Con tainsKey(" vixcache") )
  1433                    {
  1434                         externalPr ocess.Star tInfo.Envi ronmentVar iables.Rem ove("vixca che");
  1435                    }
  1436  
  1437                    Logg er().Info( payloadJar  + " " + j avaExeFile spec + " "  + command Parameters );
  1438  
  1439                    exte rnalProces s.StartInf o.Environm entVariabl es.Add("vi xcache", c onfig.Loca lCacheDir) ;
  1440                    exte rnalProces s.Start();
  1441  
  1442                    try
  1443                    {
  1444                         do
  1445                         {
  1446                             DoEven ts();
  1447                             Thread .Sleep(500 );
  1448                             extern alProcess. Refresh();
  1449                         } while (! externalPr ocess.HasE xited);
  1450                         //exitCode  = externa lProcess.E xitCode;
  1451                    }
  1452                    fina lly
  1453                    {
  1454                         externalPr ocess.Clos e();
  1455                    }
  1456                }
  1457           }
  1458  
  1459           // / <summary >
  1460           //
  1461           // / </summar y>
  1462           // / <param n ame="confi g"></param >
  1463           // / <param n ame="paylo adPath"></ param>
  1464           pu blic stati c void Dep loyDepende ncyFiles(I VixConfigu rationPara meters con fig, bool  commit)
  1465           {
  1466                VixDepen dencyFile[ ] vixDepen dencyFiles  = Manifes t.GetDepen dencyFiles (config);
  1467                NativeTy pe native  = manifest .CurrentNa tiveInstal lation;
  1468  
  1469                if (vixD ependencyF iles.Lengt h > 0)
  1470                {
  1471                    Info ("Copying  distributi on files.. .");
  1472                }
  1473                foreach  (VixDepend encyFile v ixDependen cyFile in  vixDepende ncyFiles)
  1474                {
  1475                    if ( commit ==  true)
  1476                    {
  1477                         if (vixDep endencyFil e.Dependen cyType ==  VixDepende ncyType.Zi pConfigFil e)
  1478                         {
  1479                             Info(" Unzipping  " + vixDep endencyFil e.GetPaylo adFilespec () + " to  " + vixDep endencyFil e.GetAppFo lder());
  1480                             ZipUti lities.UnZ ip(vixDepe ndencyFile .GetPayloa dFilespec( ), vixDepe ndencyFile .GetAppFol der());
  1481                         }
  1482                         else if (v ixDependen cyFile.Nat ive == Nat iveType.al l || vixDe pendencyFi le.Native  == native)
  1483                         {
  1484                             Info(" Copying "  + vixDepen dencyFile. GetPayload Filespec()  + " to "  + vixDepen dencyFile. GetAppFile spec());
  1485                             if (Fi le.Exists( vixDepende ncyFile.Ge tAppFilesp ec()))
  1486                             {
  1487                                 Fi le.SetAttr ibutes(vix Dependency File.GetAp pFilespec( ), FileAtt ributes.No rmal);
  1488                             }
  1489                             File.D elete(vixD ependencyF ile.GetApp Filespec() );
  1490                             File.C opy(vixDep endencyFil e.GetPaylo adFilespec (), vixDep endencyFil e.GetAppFi lespec());
  1491                         }
  1492                         else
  1493                         {
  1494                             Info(" Skipping "  + vixDepe ndencyFile .Native +  " dependen cy " + vix Dependency File.GetPa yloadFiles pec());
  1495                         }
  1496                    }
  1497                }
  1498  
  1499                if (!con fig.IsPatc h)
  1500                {
  1501                    Stri ng payload Properties  = Path.Co mbine(VixF acade.Mani fest.Paylo adPath, @" server/pro perties");
  1502                    if ( commit ==  true)
  1503                    {
  1504                         Logger().I nfo("Log4j  version:  " + VixFac ade.Manife st.Log4jVe rsion);
  1505                         if (VixFac ade.Manife st.Log4jVe rsion == 2 )
  1506                         {
  1507                             Rewrit eLoggingPr opertiesFi le(payload Properties , "log4j2. xml", VixF acade.GetV ixConfigur ationDirec tory(), co nfig);
  1508                         }
  1509                         else
  1510                         {
  1511                             Rewrit eLoggingPr opertiesFi le(payload Properties , "log4j.p roperties" , VixFacad e.GetVixCo nfiguratio nDirectory (), config );
  1512                         }
  1513                    }
  1514                }
  1515           }
  1516  
  1517  
  1518           pu blic stati c void Dep loyWebAppD ependencyF iles(IVixC onfigurati onParamete rs config,  bool comm it)
  1519           {
  1520                VixDepen dencyFile[ ] vixDepen dencyFiles  = Manifes t.GetWebAp pDependenc yFiles(con fig);
  1521                NativeTy pe native  = manifest .CurrentNa tiveInstal lation;
  1522  
  1523                if (vixD ependencyF iles.Lengt h > 0)
  1524                {
  1525                    Info ("Copying  web applic ation dist ribution f iles...");
  1526                }
  1527                foreach  (VixDepend encyFile v ixDependen cyFile in  vixDepende ncyFiles)
  1528                {
  1529                    if ( commit ==  true)
  1530                    {
  1531                         if (vixDep endencyFil e.Dependen cyType ==  VixDepende ncyType.Zi pConfigFil e)
  1532                         {
  1533                             Info(" Unzipping  " + vixDep endencyFil e.GetPaylo adFilespec () + " to  " + vixDep endencyFil e.GetAppFo lder());
  1534                             ZipUti lities.UnZ ip(vixDepe ndencyFile .GetPayloa dFilespec( ), vixDepe ndencyFile .GetAppFol der());
  1535                         }
  1536                         else if (v ixDependen cyFile.Nat ive == Nat iveType.al l || vixDe pendencyFi le.Native  == native)
  1537                         {
  1538                             Info(" Copying "  + vixDepen dencyFile. GetPayload Filespec()  + " to "  + vixDepen dencyFile. GetAppFile spec());
  1539                             if (Fi le.Exists( vixDepende ncyFile.Ge tAppFilesp ec()))
  1540                             {
  1541                                 Fi le.SetAttr ibutes(vix Dependency File.GetAp pFilespec( ), FileAtt ributes.No rmal);
  1542                             }
  1543                             File.D elete(vixD ependencyF ile.GetApp Filespec() ); // hand les read o nly file
  1544                             File.C opy(vixDep endencyFil e.GetPaylo adFilespec (), vixDep endencyFil e.GetAppFi lespec());
  1545                         }
  1546                         else
  1547                         {
  1548                             Info(" Skipping "  + vixDepe ndencyFile .Native +  " dependen cy " + vix Dependency File.GetPa yloadFiles pec());
  1549                         }
  1550                    }
  1551                }
  1552           }
  1553  
  1554           pu blic stati c void Dep loyImageGe arDependen cyFiles(IV ixConfigur ationParam eters conf ig, bool c ommit)
  1555           {
  1556                VixDepen dencyFile[ ] vixDepen dencyFiles  = Manifes t.GetImage GearDepend encyFiles( config);
  1557  
  1558                if (vixD ependencyF iles.Lengt h > 0)
  1559                {
  1560                    Info ("Copying  web applic ation dist ribution f iles...");
  1561                }
  1562                foreach  (VixDepend encyFile v ixDependen cyFile in  vixDepende ncyFiles)
  1563                {
  1564                    if ( commit ==  true)
  1565                    {
  1566                         if (vixDep endencyFil e.Dependen cyType ==  VixDepende ncyType.Zi pConfigFil e)
  1567                         {
  1568                             Info(" Unzipping  " + vixDep endencyFil e.GetPaylo adFilespec () + " to  " + vixDep endencyFil e.GetAppFo lder());
  1569                             ZipUti lities.UnZ ip(vixDepe ndencyFile .GetPayloa dFilespec( ), vixDepe ndencyFile .GetAppFol der());
  1570                         }
  1571                         else
  1572                         {
  1573                             Info(" Copying "  + vixDepen dencyFile. GetPayload Filespec()  + " to "  + vixDepen dencyFile. GetAppFile spec()); / / side eff ect - crea tes folder  if necess ary
  1574                             if (Fi le.Exists( vixDepende ncyFile.Ge tAppFilesp ec()))
  1575                             {
  1576                                 Fi le.SetAttr ibutes(vix Dependency File.GetAp pFilespec( ), FileAtt ributes.No rmal);
  1577                             }
  1578                             File.D elete(vixD ependencyF ile.GetApp Filespec() ); // hand les read o nly file
  1579                             File.C opy(vixDep endencyFil e.GetPaylo adFilespec (), vixDep endencyFil e.GetAppFi lespec());
  1580                         }
  1581                    }
  1582                }
  1583           }
  1584  
  1585           pu blic stati c void Del eteDepreca tedDistrib utionFiles (IVixConfi gurationPa rameters c onfig, boo l commit)
  1586           {
  1587                VixDepre catedFile[ ] vixDepre catedFiles  = Manifes t.GetDepre catedFiles (config);
  1588  
  1589                Info("De leting dep recated fi les...");
  1590                foreach  (VixDeprec atedFile v ixDeprecat edFile in  vixDepreca tedFiles)
  1591                {
  1592                    if ( File.Exist s(vixDepre catedFile. GetAppFile spec()))
  1593                    {
  1594                         Info("Dele ting " + v ixDeprecat edFile.Get AppFilespe c());
  1595                         if (commit  == true)
  1596                         {
  1597                             File.D elete(vixD eprecatedF ile.GetApp Filespec() );
  1598                         }
  1599                    }
  1600                }
  1601           }
  1602  
  1603           pu blic stati c VixDepen dencyFile[ ] FilterFi lesByType( VixDepende ncyFile[]  vixDepende ncyFiles,  IVixConfig urationPar ameters co nfig, VixD ependencyT ype vixDep endencyTyp e)
  1604           {
  1605                List<Vix Dependency File> filt eredFiles  = new List <VixDepend encyFile>( );
  1606  
  1607                foreach  (VixDepend encyFile v ixDependen cyFile in  vixDepende ncyFiles)
  1608                {
  1609                    if ( vixDepende ncyFile.De pendencyTy pe == vixD ependencyT ype)
  1610                    {
  1611                         filteredFi les.Add(vi xDependenc yFile);
  1612                    }
  1613                }
  1614                return f ilteredFil es.ToArray ();
  1615           }
  1616  
  1617           pu blic stati c void Del eteDepreca tedDistrib utionDirec tories(IVi xConfigura tionParame ters confi g, bool co mmit)
  1618           {
  1619                VixDepre catedDirec tory[] vix Deprecated Directorie s = Manife st.GetDepr ecatedDire ctories(co nfig);
  1620  
  1621                Info("De leting dep recated di rectories. ..");
  1622                foreach  (VixDeprec atedDirect ory vixDep recatedDir ectory in  vixDepreca tedDirecto ries)
  1623                {
  1624                    if ( Directory. Exists(vix Deprecated Directory. GetDirecto ryPath()))
  1625                    {
  1626                         Info("Dele ting " + v ixDeprecat edDirector y.GetDirec toryPath() );
  1627                         if (commit  == true)
  1628                         {
  1629                             Direct ory.Delete (vixDeprec atedDirect ory.GetDir ectoryPath (), true);  // recurs ive delete
  1630                         }
  1631                    }
  1632                }
  1633  
  1634           }
  1635  
  1636           // / <summary >
  1637           //
  1638           // / </summar y>
  1639           // / <param n ame="confi g"></param >
  1640           // / <param n ame="paylo adPath"></ param>
  1641           // / <param n ame="isDev eloperMode "></param>
  1642           pu blic stati c void Wri teViXConfi gurationFi les(IVixCo nfiguratio nParameter s config)  //, bool i sDeveloper Mode)
  1643           {
  1644                VixJavaC onfigurati onUtility[ ] vixConfi gUtilites  = Manifest .JavaConfi gurationUt ilityPrope rties;
  1645  
  1646                foreach  (VixJavaCo nfiguratio nUtility c onfigUtili ty in vixC onfigUtili tes)
  1647                {
  1648                    Exec uteConfigu rationUtil ity(config Utility, c onfig);
  1649                }
  1650           }
  1651  
  1652           // / <summary >
  1653           // / Check to  see that  a zip file  contains  a keystore  and trust store maki ng it a "v alid" cert ificate. 
  1654           // / </summar y>
  1655           // / <param n ame="certi ficateFile spec">The  zip file w hich shoul d contain  a keystore  and trust store</par am>
  1656           // / <returns >true if t he zip fil e contains  a keystor e and trus tstore</re turns>
  1657           pu blic stati c bool IsF ederationC ertificate Valid(stri ng certifi cateFilesp ec)
  1658           {
  1659                bool isV ixCertific ateValid =  false;
  1660                List<str ing> allow edCertific ateFiles =  new List< string>();
  1661                allowedC ertificate Files.Add( FEDERATION _KEYSTORE_ FILENAME);
  1662                allowedC ertificate Files.Add( FEDERATION _TRUSTSTOR E_FILENAME );
  1663                //TODO:  add host n ame check
  1664                if (ZipU tilities.F ileCount(c ertificate Filespec)  == 2 && Zi pUtilities .CheckZipC ontents(ce rtificateF ilespec, a llowedCert ificateFil es.ToArray ()))
  1665                {
  1666                    isVi xCertifica teValid =  true;
  1667                }
  1668                return i sVixCertif icateValid ;
  1669           }
  1670  
  1671           // / <summary >
  1672           // / Check to  see that  a zip file  contains  a keystore  and trust store maki ng it a "v alid" cert ificate. 
  1673           // / </summar y>
  1674           // / <param n ame="certi ficateFile spec">The  zip file w hich shoul d contain  a keystore  and trust store</par am>
  1675           // / <returns >true if t he zip fil e contains  a keystor e and trus tstore</re turns>
  1676           pu blic stati c bool IsX caCertific ateValid(s tring cert ificateFil espec)
  1677           {
  1678                bool isX caCertific ateValid =  false;
  1679                List<str ing> allow edCertific ateFiles =  new List< string>();
  1680                //allowe dCertifica teFiles.Ad d(XCA_KEYS TORE_FILEN AME);
  1681                //allowe dCertifica teFiles.Ad d(XCA_TRUS TSTORE_FIL ENAME);
  1682                allowedC ertificate Files.Add( XCA_CERTIF ICATE_FILE NAME);
  1683                allowedC ertificate Files.Add( XCA_PRIVAT E_KEY_FILE NAME);
  1684                //TODO:  add host n ame check
  1685                if (ZipU tilities.F ileCount(c ertificate Filespec)  >= allowed Certificat eFiles.Cou nt && ZipU tilities.C heckZipCon tents(cert ificateFil espec, all owedCertif icateFiles .ToArray() ))
  1686                {
  1687                    isXc aCertifica teValid =  true;
  1688                }
  1689                return i sXcaCertif icateValid ;
  1690           }
  1691  
  1692           // / <summary >
  1693           // / Check to  see that  a zip file  contains  certificat es making  it a "vali d" certifi cate. 
  1694           // / </summar y>
  1695           // / <param n ame="certi ficateFile spec">The  zip file w hich shoul d contain  a keystore  and trust store</par am>
  1696           // / <returns >true if t he zip fil e contains  a keystor e and trus tstore</re turns>
  1697           pu blic stati c bool IsD oDCertific ateValid(s tring cert ificateFil espec)
  1698           {
  1699                bool isD oDCertific ateValid =  false;
  1700                //List<s tring> all owedCertif icateFiles  = new Lis t<string>( );
  1701                //allowe dCertifica teFiles.Ad d(DOD_CERT IFICATE_FI LENAME);
  1702                int nCer ts = ZipUt ilities.Fi leCount(ce rtificateF ilespec); 
  1703                if ( nCe rts >= 1)
  1704                {
  1705                    Logg er().Info( "IsDoDCert ificateVal id - # of  certificat es: " + nC erts);
  1706                    isDo DCertifica teValid =  true;
  1707                }
  1708                return i sDoDCertif icateValid ;
  1709           }
  1710           
  1711           
  1712           #e ndregion
  1713  
  1714           #r egion priv ate instal lation met hods
  1715  
  1716  
  1717           // / <summary >
  1718           // / Uninstal ls the web  applicati on.
  1719           // / </summar y>
  1720           // / <param n ame="vixWe bApplicati on">The vi x web appl ication ob ject.</par am>
  1721           // / <param n ame="delet eWar">if s et to <c>t rue</c> [d elete the  war the we b applicat ion came f rom].</par am>
  1722           // / <remarks ></remarks >
  1723           pr ivate stat ic void Un installWeb Applicatio n(IVixConf igurationP arameters  config, Vi xWebApplic ation vixW ebApplicat ion, bool  deleteWar)
  1724           {
  1725                if (dele teWar)
  1726                {
  1727                    stri ng warFile Spec = Pat h.Combine( TomcatFaca de.TomcatW ebApplicat ionFolder,  vixWebApp lication.W ar);
  1728                    if ( File.Exist s(warFileS pec))
  1729                    {
  1730                         File.Delet e(warFileS pec);
  1731                         Info("     Deleted "  + warFileS pec);
  1732                    }
  1733                }
  1734  
  1735                string p athFolder  = vixWebAp plication. Path.Start sWith("/")  ? vixWebA pplication .Path.Subs tring(1) :  vixWebApp lication.P ath;
  1736                string w ebAppPathF older = Pa th.Combine (TomcatFac ade.Tomcat WebApplica tionFolder , pathFold er);
  1737                if (Dire ctory.Exis ts(webAppP athFolder) )
  1738                {
  1739                    Remo veReadOnly Attributes (webAppPat hFolder);  // recurse
  1740                    Dire ctory.Dele te(webAppP athFolder,  true); //  recurse
  1741                    Info ("    Dele ted " + we bAppPathFo lder);
  1742                }
  1743                string w ebAppPathW orkFolder  = Path.Com bine(Tomca tFacade.Ge tTomcatWor kFolder(co nfig.SiteN umber), pa thFolder);
  1744                if (Dire ctory.Exis ts(webAppP athWorkFol der))
  1745                {
  1746                    Remo veReadOnly Attributes (webAppPat hWorkFolde r); // rec urse
  1747                    Dire ctory.Dele te(webAppP athWorkFol der, true) ; // recur se
  1748                    Info ("    Dele ted " + we bAppPathWo rkFolder);
  1749                }
  1750           }
  1751  
  1752           // / <summary >
  1753           //
  1754           // / </summar y>
  1755           // / <param n ame="sourc eDir"></pa ram>
  1756           // / <param n ame="sourc eFilename" ></param>
  1757           // / <param n ame="targe tDir"></pa ram>
  1758           // / <param n ame="confi g"></param >
  1759           pr ivate stat ic void Re writeLoggi ngProperti esFile(Str ing source Dir, Strin g sourceFi lename, St ring targe tDir,
  1760                IVixConf igurationP arameters  config)
  1761           {
  1762                String s ourcePath  = Path.Com bine(sourc eDir, sour ceFilename );
  1763                String t argetPath  = Path.Com bine(targe tDir, sour ceFilename );
  1764                String v ixConfigDi r = config .ConfigDir .Replace(@ "\", "/");  // transl ate file s ystem deli miter so J ava doesnt  barf
  1765                Info("Re writing "  + sourcePa th + " to  " + target Path);
  1766  
  1767                using (S treamReade r sr = new  StreamRea der(source Path))
  1768                {
  1769                    usin g (StreamW riter sw =  File.Crea teText(tar getPath))  // file wi ll be over written
  1770                    {
  1771                         String lin e;
  1772                         while ((li ne = sr.Re adLine())  != null)
  1773                         {
  1774                             if (li ne.Contain s("vixconf ig="))
  1775                             {
  1776                                 sw .WriteLine ("vixconfi g=" + vixC onfigDir);
  1777                             }
  1778                             else
  1779                             {
  1780                                 sw .WriteLine (line);
  1781                             }
  1782                         }
  1783                         sw.Close() ;
  1784                    }
  1785                    sr.C lose();
  1786                }
  1787           }
  1788  
  1789           // / <summary >
  1790           //
  1791           // / </summar y>
  1792           // / <param n ame="confi gUtility"> </param>
  1793           // / <param n ame="confi g"></param >
  1794           // / <param n ame="paylo adPath"></ param>
  1795           pr ivate stat ic void Ex ecuteConfi gurationUt ility(VixJ avaConfigu rationUtil ity config Utility, I VixConfigu rationPara meters con fig)
  1796           {
  1797                StringBu ilder sb =  new Strin gBuilder() ;
  1798  
  1799                // Trans action Imp ort Log ut ility requ ires this  to operate
  1800                string l ogProperti esFilespec  = null;
  1801  
  1802                Logger() .Info("Log 4j version : " + VixF acade.Mani fest.Log4j Version);
  1803                if (VixF acade.Mani fest.Log4j Version ==  2)
  1804                {
  1805                    logP ropertiesF ilespec =  Path.Combi ne(config. ConfigDir,  "log4j2.x ml");
  1806                    sb.A ppendForma t(" -Dlog4 j.configur ationFile= file:/{0}  -cp ./*;{1 } {2} ", l ogProperti esFilespec .Replace(@ "\", "/"),
  1807                         configUtil ity.Jar, c onfigUtili ty.Package );
  1808                }
  1809                else
  1810                {
  1811                    logP ropertiesF ilespec =  Path.Combi ne(config. ConfigDir,  "log4j.pr operties") ;
  1812                    sb.A ppendForma t(" -Dlog4 j.configur ation=file :/{0} -cp  ./*;{1} {2 } ", logPr opertiesFi lespec.Rep lace(@"\",  "/"),
  1813                    conf igUtility. Jar, confi gUtility.P ackage);
  1814                }
  1815                
  1816                switch ( configUtil ity.Config UtilityTyp e)
  1817                {
  1818                    case  ViXConfig urationUti lityType.V iX:
  1819                         sb.AppendF ormat("\"L ocalSiteNu mber={0}\"  \"SmtpSer verUri={1} \" \"VixSo ftwareVers ion={2}\"" ,
  1820                             config .SiteNumbe r, Busines sFacade.Ge tSmtpServe rUri(), co nfig.Produ ctVersionP rop);
  1821                         break;
  1822                    case  ViXConfig urationUti lityType.C ache:
  1823                         BuildCache Configurat ionParamet ers(config , sb); //  sb gets po pulated
  1824                         break;
  1825                    case  ViXConfig urationUti lityType.S iteResolut ionProvide r:
  1826                         //}
  1827                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  1828                         {
  1829                             string  commandFi lespec = P ath.Combin e(config.C onfigDir,  "configure SiteResolu tionProvid er.command s");
  1830                             sb.App endFormat( "-f \"file :/{0}\" \" {1}\"", co mmandFiles pec.Replac e(@"\", "/ "), config .SiteServi ceUri);
  1831                         }
  1832                         else if (c onfig.VixR ole == Vix RoleType.S iteVix)
  1833                         {
  1834                             if (co nfig.HasLo calDodConf iguration( )) // worm hole
  1835                             {
  1836                                 st ring comma ndFilespec  = Path.Co mbine(conf ig.ConfigD ir, "confi gureSiteRe solutionPr ovider3.co mmands");
  1837                                 st ring pacsi ExchangeMe tadataUrl  = "exchang e://" + co nfig.Local DodServer  + ":" + co nfig.Local DodServerP ort + "/Va ImagingExc hange/Imag eMetadataS ervice.asm x";
  1838                                 st ring pacsi ExchangeIm ageUrl = " exchange:/ /" + confi g.LocalDod Server + " :" + confi g.LocalDod ServerPort  + "/VaIma gingExchan ge/Retriev eImage.ash x";
  1839                                 sb .AppendFor mat("-f \" file:/{0}\ " \"{1}\"  \"{2}\" \" {3}\" \"{4 }\" \"{5}\ "", comman dFilespec. Replace(@" \", "/"),
  1840                                      config.S iteService Uri, confi g.SiteNumb er, config .LocalDodS iteNumber,  pacsiExch angeMetada taUrl, pac siExchange ImageUrl);
  1841                             }
  1842                             else
  1843                             {
  1844                                 //  param 3 -  exchange
  1845                                 st ring comma ndFilespec  = Path.Co mbine(conf ig.ConfigD ir, "confi gureSiteRe solutionPr ovider.com mands");
  1846                                 sb .AppendFor mat("-f \" file:/{0}\ " \"{1}\"  \"{2}\"",  commandFil espec.Repl ace(@"\",  "/"), conf ig.SiteSer viceUri, c onfig.Site Number);
  1847                             }
  1848                         }
  1849                         else if (c onfig.VixR ole == Vix RoleType.D icomGatewa y)
  1850                         {
  1851                             string  commandFi lespec = P ath.Combin e(config.C onfigDir,  "configure SiteResolu tionProvid er.command s");
  1852                             sb.App endFormat( "-f \"file :/{0}\" \" {1}\" \"{2 }\"", comm andFilespe c.Replace( @"\", "/") , config.S iteService Uri, confi g.SiteNumb er);
  1853                         }
  1854                         else if (c onfig.VixR ole == Vix RoleType.M iniVix)
  1855                         {
  1856                             // par am 3 - exc hange
  1857                             string  commandFi lespec = P ath.Combin e(config.C onfigDir,  "configure SiteResolu tionProvid er2.comman ds");
  1858                             sb.App endFormat( "-f \"file :/{0}\" \" {1}\" \"{2 }\"", comm andFilespe c.Replace( @"\", "/") , config.S iteService Uri, confi g.SiteNumb er);
  1859                         }
  1860                         else // sh ould never  happen
  1861                         {
  1862                               thro w new Exce ption(conf ig.VixRole .ToString( ) + "  Sit e Resoluti on Configu ration not  currently  supported ");
  1863                         }
  1864                         break;
  1865                    case  ViXConfig urationUti lityType.C linicalDis playProvid er:
  1866                         break; //  no paramet ers yet
  1867                    case  ViXConfig urationUti lityType.E xchangeDat aSourcePro vider:
  1868                         sb.AppendF ormat("\"- biaUsernam e\" \"{0}\ " \"-biaPa ssword\" \ "{1}\"", c onfig.BiaU sername, c onfig.BiaP assword);
  1869                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  1870                         {
  1871                             sb.App end(Blackl istModalit yArguments (config));
  1872                         }
  1873                         else if (c onfig.HasL ocalDodCon figuration ())
  1874                         {
  1875                             sb.App endFormat( " \"-alien Site\" \"{ 0}\" \"{1} \" \"{2}\"  \"{3}\" \ "{4}\"",
  1876                                 co nfig.Local DodSiteNum ber, confi g.LocalDod Server, co nfig.Local DodServerP ort, confi g.LocalDod Username,  config.Loc alDodPassw ord);
  1877                         }
  1878                         break;
  1879                    case  ViXConfig urationUti lityType.E xchangePro cedureFilt erTermsCon figuration :
  1880                         break; //  no paramet ers yet
  1881                    case  ViXConfig urationUti lityType.I mageConver sion:
  1882                         break; //  no paramet ers yet
  1883                    case  ViXConfig urationUti lityType.V istaDataSo urceProvid er:
  1884                         break; //  no paramet ers yet
  1885                    case  ViXConfig urationUti lityType.V istaOnlyDa taSourcePr ovider:
  1886                         // used to  be CVIX o nly - not  any more a s of P119  - DKB
  1887                         if (config .Station20 0UserName  == null) / / VIX or M ini-VIX
  1888                         {
  1889                             sb.App end("false "); // pro duction -  use CPRS T reating Fa cility Lis t RPC
  1890                         }
  1891                         else if (c onfig.Stat ion200User Name.ToLow er() == "t esting_1"  || config. Station200 UserName.T oLower() = = "boating 1") // CVI X
  1892                         {
  1893                             sb.App end("true" ); // inte rnal test  environmen t - use Vi stA Imagin g Treating  Facility  List RPC
  1894                         }
  1895                         else
  1896                         {
  1897                             sb.App end("false "); // pro duction -  use CPRS T reating Fa cility Lis t RPC - CV IX
  1898                         }
  1899                         break;
  1900                    case  ViXConfig urationUti lityType.T ransaction LoggerData SourceProv ider:
  1901                         break; //  no paramet ers yet
  1902                    case  ViXConfig urationUti lityType.V ixLogConfi guration:
  1903                         break; //  no paramet ers yet
  1904                    case  ViXConfig urationUti lityType.B yteBufferP oolConfigu ration:
  1905                         if (config .VixRole = = VixRoleT ype.MiniVi x)
  1906                         {
  1907                             sb.App end("-m");
  1908                         }
  1909                         break; 
  1910                    case  ViXConfig urationUti lityType.V istaRadCom mandConfig uration:
  1911                         if (config .VixRole = = VixRoleT ype.MiniVi x)
  1912                         {
  1913                             sb.App end("-m");
  1914                         }
  1915                         break;
  1916                    case  ViXConfig urationUti lityType.I dsProxyCon figuration :
  1917                         break; //  no paramet ers yet
  1918                    case  ViXConfig urationUti lityType.F ederationD ataSourceP rovider:
  1919                         String s =  Path.Comb ine(VixFac ade.GetVix Certificat eStoreDir( ), FEDERAT ION_KEYSTO RE_FILENAM E);
  1920                         String fed erationKey storePath  = s.Replac e(@"\", "/ ");
  1921                         s = Path.C ombine(Vix Facade.Get VixCertifi cateStoreD ir(), FEDE RATION_TRU STSTORE_FI LENAME);
  1922                         String fed erationTru ststorePat h = s.Repl ace(@"\",  "/");
  1923                         sb.AppendF ormat("\"- truststore Password\"  \"{0}\" \ "-keystore Password\"  \"{1}\" \ "-keystore Url\" \"fi le:///{2}\ " \"-trust storeUrl\"  \"file:// /{3}\" -fe derationSs lProtocol  \"https\"" ,
  1924                             config .Federatio nTruststor ePassword,  config.Fe derationKe ystorePass word, fede rationKeys torePath,  federation Truststore Path);
  1925                         break;
  1926                    case  ViXConfig urationUti lityType.V ixHealthCo nfiguratio n:
  1927                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  1928                         {
  1929                             sb.App endFormat( "\"{0}\" t rue true t rue false" , config.S iteNumber) ;
  1930                         }
  1931                         else if (c onfig.VixR ole == Vix RoleType.S iteVix ||  config.Vix Role == Vi xRoleType. MiniVix)
  1932                         {
  1933                             sb.App endFormat( "\"{0}\" t rue true f alse false ", config. SiteNumber );
  1934                         }
  1935                         else if (c onfig.VixR ole == Vix RoleType.D icomGatewa y)
  1936                         {
  1937                             sb.App endFormat( "\"{0}\" t rue true f alse true" , config.S iteNumber) ;
  1938                         }
  1939                         else // sh ould never  happen
  1940                         {
  1941                             throw  new Except ion(config .VixRole.T oString()  + "  Healt h Configur ation not  currently  supported" );
  1942                         }
  1943                         break;
  1944                    case  ViXConfig urationUti lityType.N otificatio nConfigura tion:
  1945                         if (config .VixRole = = VixRoleT ype.DicomG ateway)
  1946                         {
  1947                             sb.App endFormat( "\"{0}\" f alse", con fig.SiteNu mber); //  DICOM VIXe n do not e nable noti fications  for now
  1948                         }
  1949                         else
  1950                         {
  1951                             sb.App endFormat( "\"{0}\" t rue", conf ig.SiteNum ber);
  1952                         }
  1953                         break;
  1954                    case  ViXConfig urationUti lityType.N otificatio nEmailConf iguration:
  1955                         if (config .Notificat ionEmailAd dresses !=  null)
  1956                         {
  1957                             sb.App endFormat( " \"{0}\"" , config.N otificatio nEmailAddr esses);
  1958                         }
  1959                         break;
  1960                    case  ViXConfig urationUti lityType.D icomGatewa yConfigura tion:
  1961                         string dco rrectDir =  Path.Comb ine(config .LocalCach eDir, "DCo rrect").Re place(@"\" , "/");
  1962                         string dde bugDir = P ath.Combin e(config.L ocalCacheD ir, "DDebu g").Replac e(@"\", "/ ");
  1963                         sb.AppendF ormat("\"{ 0}\" \"{1} \" \"{2}\"  \"{3}\" \ "{4}\" \"D LE={5}\" \ "AE={6}\"  \"IPE={7}\ "", config .SiteNumbe r, config. DicomImage GatewaySer ver,
  1964                             config .DicomImag eGatewayPo rt, config .VdigAcces sor, confi g.VdigVeri fier, conf ig.DicomLi stenerEnab led.ToStri ng().ToLow er(), conf ig.Archive Enabled.To String().T oLower(),
  1965                             config .IconGener ationEnabl ed.ToStrin g().ToLowe r());
  1966                         break;
  1967                    case  ViXConfig urationUti lityType.S torageServ erConfigur ation:
  1968                         break;  //  no parame ters yet
  1969                    case  ViXConfig urationUti lityType.P eriodicCom mandConfig uration:
  1970                         if (config .VixRole = = VixRoleT ype.DicomG ateway)
  1971                         {
  1972                             sb.App endFormat( "\"{0}\" \ "{1}\" \"{ 2}\" \"{3} \" \"{4}\"  \"{5}\" \ "{6}\" \"{ 7}\" \"{8} \" \"{9}\"  \"{10}\"  \"{11}\" \ "{12}\" \" {13}\"", 
  1973                                 "a ccessCode" , "none", 
  1974                                 "v erifyCode" , "none",
  1975                                 "P rocessAsyn cStorageQu eueSendEma ilCommand" , "60000",  
  1976                                 "P rocessDico mCorrectCo mmand", "6 0000",
  1977                                 "P rocessIcon ImageCreat ionQueueCo mmand", "6 0000", 
  1978                                 "P rocessEmai lQueueComm and", "300 00", 
  1979                                 "P rocessPort ListeningC heckComman d", "60000 ");
  1980                             // thi s was prev iously a P 79 only fe ature...
  1981                             sb.App endFormat( " \"{0}\"  \"{1}\"",  "ProcessSt oreCommitW orkItemCom mand", "60 000");
  1982                         }
  1983                         else if (c onfig.VixR ole == Vix RoleType.S iteVix)
  1984                         {
  1985                             if (ma nifest.Maj orPatchNum ber >= 197 )
  1986                             {
  1987                                 sb .AppendFor mat(" \"{0 }\" \"{1}\ " \"{2}\"  \"{3}\" \" {4}\" \"{5 }\"",
  1988                                      "accessC ode", conf ig.RoiAcce ssor,
  1989                                      "verifyC ode", conf ig.RoiVeri fier,
  1990                                      "Process ViewerPreC acheWorkIt emsCommand ", "60000" );
  1991                             }
  1992                         }
  1993                         break;
  1994                    case  ViXConfig urationUti lityType.R oiConfigur ation: //  P130, P138  VIX
  1995                         sb.AppendF ormat("\"{ 0}\" \"{1} \"", confi g.RoiAcces sor, confi g.RoiVerif ier);
  1996                         break;
  1997                    case  ViXConfig urationUti lityType.I mageGearDa taSourcePr ovider: //  P130, P13 8 VIX
  1998                         VixDepende ncyFile[]  roiAnnotat e = Filter FilesByTyp e(manifest .GetDepend encyFiles( config), c onfig, Vix Dependency Type.RoiAn notationEx e);
  1999                         if (roiAnn otate.Leng th != 1) t hrow new E xception(" Cannot con figure Ima geGearData SourceProv ider - mis sing ROI a nnotation  exe");
  2000                         VixDepende ncyFile[]  roiPdf = F ilterFiles ByType(man ifest.GetD ependencyF iles(confi g), config , VixDepen dencyType. RoiPdfExe) ;
  2001                         if (roiAnn otate.Leng th != 1) t hrow new E xception(" Cannot con figure Ima geGearData SourceProv ider - mis sing ROI P DF exe");
  2002                         string roi Disclosure Dirspec =  Path.Combi ne(config. ConfigDir,  ROI_DISCL OSURE_DIRE CTORY);
  2003                         if (!Direc tory.Exist s(roiDiscl osureDirsp ec))
  2004                         {
  2005                             Direct ory.Create Directory( roiDisclos ureDirspec );
  2006                         }
  2007                         sb.AppendF ormat("\"{ 0}\" \"{1} \" \"{2}\"  \"{3}\"",  roiDisclo sureDirspe c, config. SiteName,  roiPdf[0]. GetAppFile spec(), ro iAnnotate[ 0].GetAppF ilespec()) ;
  2008                         break;
  2009                    //Co py the con fig file r ather than  generate  using java
  2010                    //ca se ViXConf igurationU tilityType .VistaConn ectionConf iguration:
  2011                    //     if (conf ig.VixRole  == VixRol eType.Ente rpriseGate way || con fig.VixRol e == VixRo leType.Sit eVix)
  2012                    //     {
  2013                    //         if ( IsDevelopm entCvix(co nfig) == f alse)
  2014                    //         {
  2015                    //              sb.Append( "-new fals e"); // us e new styl e broker
  2016                    //         }
  2017                    //     }
  2018                    //     break;
  2019                    case  ViXConfig urationUti lityType.C ommandConf iguration:
  2020                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  2021                         {
  2022                             if (co nfig.Stati on200UserN ame.ToLowe r() == "te sting_1" | | config.S tation200U serName.To Lower() ==  "boating1 ")
  2023                             {
  2024                                 sb .Append("t rue false  false"); / / dont not  use CPRS  context
  2025                             }
  2026                             else
  2027                             {
  2028                                 sb .Append("t rue true f alse");
  2029                             }
  2030                         }
  2031                         else // VI X and Mini -VIX, HDIG  does not  have this  configured
  2032                         {
  2033                             sb.App end("true  false true ");
  2034                         }
  2035                         break;
  2036                    case  ViXConfig urationUti lityType.I magingFaca deConfigur ation:
  2037                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  2038                         {
  2039                             sb.App end("false  true");
  2040                         }
  2041                         else if (c onfig.VixR ole == Vix RoleType.S iteVix ||  config.Vix Role == Vi xRoleType. MiniVix)
  2042                         {
  2043                             sb.App end("true  false");
  2044                         }
  2045                         else // sh ould never  happen
  2046                         {
  2047                             throw  new Except ion(config .VixRole.T oString()  + "  Imagi ng Facade  Configurat ion not cu rrently su pported");
  2048                         }
  2049                         break;
  2050                    case  ViXConfig urationUti lityType.M ixDataSour ceProvider :
  2051                         //sb.Appen dFormat("\ "-biaUsern ame\" \"{0 }\" \"-bia Password\"  \"{1}\"",  
  2052                         //    conf ig.BiaUser name, conf ig.BiaPass word);
  2053                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  2054                         {
  2055                             sb.App end(Blackl istModalit yArguments (config));
  2056                             sb.App endFormat( " \"-host\ " \"{0}\"  \"-port\"  \"{1}\" \" -cvixCertP wd\" \"{2} \" \"-dasC ertPwd\" \ "{3}\"",
  2057                                 co nfig.DoDCo nnectorHos t, config. DoDConnect orPort,
  2058                                 co nfig.CvixC ertPasswor d, DAS_TRU STSTORE_PA SSWORD
  2059                                 );
  2060                         }
  2061  
  2062                         //if (conf ig.HasLoca lDodConfig uration())
  2063                         //{
  2064                         //    sb.A ppendForma t(" \"-ali enSite\" \ "{0}\" \"{ 1}\" \"{2} \" \"{3}\"  \"{4}\"",
  2065                         //         config.Loc alDodSiteN umber, con fig.LocalD odServer, 
  2066                         //         config.Loc alDodServe rPort, con fig.LocalD odUsername , config.L ocalDodPas sword);
  2067                         //}
  2068                         break;
  2069                    case  ViXConfig urationUti lityType.D xDataSourc eProvider:
  2070                         if (config .VixRole = = VixRoleT ype.Enterp riseGatewa y)
  2071                         {
  2072                             sb.App endFormat( "\"-host\"  \"{0}\" \ "-port\" \ "{1}\" \"- provider\"  \"{2}\" "  +
  2073                                 "\ "-loinc\"  \"{3}\" \" -requestSo urce\" \"{ 4}\" \"-cv ixCertPwd\ " \"{5}\"  \"-dasCert Pwd\" \"{6 }\" " +
  2074                                 "\ "-localIp\ " \"{7}\"  \"-alexdel argePwd\"  \"655321\" ",
  2075                                 co nfig.DoDCo nnectorHos t, config. DoDConnect orPort, co nfig.DoDCo nnectorPro vider,
  2076                                 co nfig.DoDCo nnectorLoi nc, config .DoDConnec torRequest Source,
  2077                                 co nfig.CvixC ertPasswor d, DAS_TRU STSTORE_PA SSWORD,
  2078                                 En vironment. MachineNam e
  2079                                 );
  2080                         }
  2081                         break;
  2082                    case  ViXConfig urationUti lityType.F ileSystemC acheConfig urator:
  2083                         if ((confi g.VixRole  == VixRole Type.Enter priseGatew ay) &&
  2084                             (confi g.ClusterC ache) && 
  2085                             (!stri ng.IsNullO rEmpty(con fig.Cluste rHost)) &&
  2086                             (!stri ng.IsNullO rEmpty(con fig.Cluste rPort)) &&
  2087                             (!stri ng.IsNullO rEmpty(con fig.Cluste rLogin)) & &
  2088                             (!stri ng.IsNullO rEmpty(con fig.Cluste rPassword) ) &&
  2089                             (!stri ng.IsNullO rEmpty(con fig.Cluste rNetworkLo gin)) &&
  2090                             (!stri ng.IsNullO rEmpty(con fig.Cluste rNetworkPa ssword))
  2091                             )
  2092                         {
  2093                             sb.App endFormat( "\"-host\"  \"{0}\" \ "-port\" \ "{1}\" \"- login\" \" {2}\" \"-p wd\" \"{3} \" " +
  2094                                 "\ "-netDomai n\" \"{4}\ " \"-netLo gin\" \"{5 }\" \"-net Pwd\" \"{6 }\"",
  2095                                 co nfig.Clust erHost, co nfig.Clust erPort, 
  2096                                 co nfig.Clust erLogin, c onfig.Clus terPasswor d,
  2097                                 (c onfig.Clus terNetwork Domain ==  null ? "nu ll" : conf ig.Cluster NetworkDom ain),
  2098                                 co nfig.Clust erNetworkL ogin, conf ig.Cluster NetworkPas sword
  2099                                 );
  2100                         }
  2101                         break;
  2102                    case  ViXConfig urationUti lityType.M useDataSou rceProvide r:
  2103                         break;
  2104                    //ca se ViXConf igurationU tilityType .XCAInitia tingGatewa yDataSourc eProvider:
  2105                    //     //"file: /C:/VixCer tStore/xca .keystore"  "R00tbeer " "file:/C :/VixCertS tore/xca.t ruststore"  "R00tbeer " "7443" " null" "nul l" "null"  "xcas" "nu ll" "null"  "xcas" "n catusernam e" "ncatpa ssword"
  2106  
  2107                    //     s = Path .Combine(V ixFacade.G etVixConfi gurationDi rectory(),  "configur eCVIX_XCA. commands") ;
  2108                    //     String x caCommands  = s.Repla ce(@"\", " /");
  2109                    //     sb.Appen dFormat("- f \"file:/ {0}\" ", x caCommands );
  2110  
  2111                    //     s = Path .Combine(V ixFacade.G etVixCerti ficateStor eDir(), FE DERATION_K EYSTORE_FI LENAME); / / XCA_KEYS TORE_FILEN AME);
  2112                    //     String x caKeystore Path = s.R eplace(@"\ ", "/");
  2113                    //     s = Path .Combine(V ixFacade.G etVixCerti ficateStor eDir(), FE DERATION_T RUSTSTORE_ FILENAME); // XCA_TRU STSTORE_FI LENAME);
  2114                    //     String x caTruststo rePath = s .Replace(@ "\", "/");
  2115                    //     sb.Appen dFormat("\ "file:/{0} \" \"{1}\"  \"file:/{ 2}\" \"{3} \" \"{4}\"  \"{5}\" \ "{6}\" \"{ 7}\" \"{8} \" \"{9}\"  \"{10}\"  \"{11}\" \ "{12}\" \" {13}\"",
  2116                    //         xcaK eystorePat h, config. Federation KeystorePa ssword, xc aTruststor ePath, con fig.Federa tionTrusts torePasswo rd, config .XcaConnec torPort.To String(),
  2117                    //         conf ig.BhiePro tocol, (co nfig.BhieU serName ==  null ? "n ull" : con fig.BhieUs erName), ( config.Bhi ePassword  == null ?  "null" : c onfig.Bhie Password),
  2118                    //         conf ig.HaimsPr otocol, (c onfig.Haim sUserName  == null ?  "null" : c onfig.Haim sUserName) , (config. HaimsPassw ord == nul l ? "null"  : config. HaimsPassw ord),
  2119                    //         conf ig.NcatPro tocol, (co nfig.NcatU serName ==  null ? "n ull" : con fig.NcatUs erName), ( config.Nca tPassword  == null ?  "null" : c onfig.Ncat Password)) ;
  2120                    //     break;
  2121                }
  2122                
  2123                String p arameters  = sb.ToStr ing();
  2124                Logger() .Info("jav a arg: " +  parameter s);
  2125                Logger() .Info("Con figuring "  + configU tility.Con figUtility Type.ToStr ing());
  2126                RunJavaU tility(par ameters, c onfig);
  2127                Logger() .Info("Don e.");
  2128           }
  2129  
  2130           pr ivate stat ic string  GetLocalIp ()
  2131           {
  2132                string l ocalIP;
  2133                using (S ocket sock et = new S ocket(Addr essFamily. InterNetwo rk, Socket Type.Dgram , 0))
  2134                {
  2135                    sock et.Connect ("8.8.8.8" , 65530);
  2136                    IPEn dPoint end Point = so cket.Local EndPoint a s IPEndPoi nt;
  2137                    loca lIP = endP oint.Addre ss.ToStrin g();
  2138                }
  2139                return l ocalIP;
  2140           }
  2141           // / <summary >
  2142           //
  2143           // / </summar y>
  2144           // / <param n ame="confi g"></param >
  2145           // / <returns ></returns >
  2146           pr ivate stat ic string  BlacklistM odalityArg uments(IVi xConfigura tionParame ters confi g)
  2147           {
  2148                string b lacklistFi lespec = P ath.Combin e(config.C onfigDir,  MODALITY_B LACKLIST_F ILENAME);
  2149                StringBu ilder sb =  new Strin gBuilder() ;
  2150  
  2151                if (File .Exists(bl acklistFil espec))
  2152                {
  2153                    stri ng line;
  2154  
  2155                    usin g (StreamR eader sr =  new Strea mReader(bl acklistFil espec))
  2156                    {
  2157                         while ((li ne = sr.Re adLine())  != null)
  2158                         {
  2159                             if (li ne.Length  == 0)
  2160                             {
  2161                                 co ntinue;
  2162                             }
  2163                             sb.App end(" -emp tyModality  " + "\""  + line + " \"");
  2164                         }
  2165                         sr.Close() ;
  2166                    }
  2167                }
  2168  
  2169                return s b.ToString ();
  2170           }
  2171  
  2172           // / <summary >
  2173           // / Populate  the passe d StringBu ilder with  the param eters need ed to init ialize the  VIX cache
  2174           // / </summar y>
  2175           // / <param n ame="confi g"></param >
  2176           // / <param n ame="sb">< /param>
  2177           pr ivate stat ic void Bu ildCacheCo nfiguratio nParameter s(IVixConf igurationP arameters  config, St ringBuilde r sb)
  2178           {
  2179                string l ocalCacheD ir = confi g.LocalCac heDir.Repl ace(@"\",  "/"); // t ranslate f ile system  delimiter  so Java d oesnt barf
  2180                switch ( config.Vix CacheOptio n)
  2181                {
  2182                    case  VixCacheT ype.Exchan geTimeEvic tionLocalF ilesystem:
  2183                         sb.AppendF ormat("cre ate \"<Ima gingExchan geCache>\"  \"<file:/ /{0}>\" \" <VixProtot ype>\" ini tialize en able store  exit",
  2184                             localC acheDir);
  2185                         break;
  2186                    case  VixCacheT ype.Exchan geTimeStor ageEvictio nLocalFile system:
  2187                         sb.AppendF ormat("cre ate \"<Ima gingExchan geCache>\"  \"<file:/ /{0}>\" \" <LimitedSp aceVixProt otype>\" i nitialize  enable ",
  2188                             localC acheDir);
  2189                         // image s torage evi ction modi fication b ased on ca che size
  2190                         // default  combined  metadata r egion size  is 1GB wh ich should  be all we  need
  2191                         long image RegionSize  = (config .VixCacheS ize - 1) *  ONE_GIGBY TE;
  2192                         Debug.Asse rt(imageRe gionSize >  0);
  2193                         long image RegionFree SpaceThres hold = (lo ng)(imageR egionSize  * 0.05); / / start ev icting at  95% full
  2194                         long image RegionTarg etFreeSpac eThreshold  = (long)( imageRegio nSize * 0. 1); // sto p evicting  at 90% fu ll
  2195                         sb.AppendF ormat("mod ify-evicti on \"<imag e-storage- threshold> \" \"<maxU sedSpaceTh reshold>\"  \"<{0}>\"  ",
  2196                             imageR egionSize) ; // maxUs edSpaceThr eshold is  MAX cache  size (may  be exceede d)
  2197                         sb.AppendF ormat("mod ify-evicti on \"<imag e-storage- threshold> \" \"<minF reeSpaceTh reshold>\"  \"<{0}>\"  ",
  2198                             imageR egionFreeS paceThresh old); // M AX - minFr eeSpaceThr eshold is  where evic tion start s to occur
  2199                         sb.AppendF ormat("mod ify-evicti on \"<imag e-storage- threshold> \" \"<targ etFreeSpac eThreshold >\" \"<{0} >\" ",
  2200                             imageR egionTarge tFreeSpace Threshold) ; // MAX -  targetFre eSpaceThre shold is w here evict ion stops
  2201                         // save an d exit
  2202                         sb.Append( "store exi t");
  2203                         break;
  2204                    defa ult:
  2205                         string mes sage = "Bu ildCacheCo nfiguratio nParameter s: unsuppo rted cache  option "  + config.V ixCacheOpt ion.ToStri ng();
  2206                         throw new  Exception( message);
  2207                }
  2208           }
  2209  
  2210           // / <summary >
  2211           // / Set acce ss control  on all di rectories  needed by  the Apache  Tomcat se rvice acco unt
  2212           // / </summar y>
  2213           // / <param n ame="confi g"></param >
  2214           pr ivate stat ic void Ap plyAccessC ontrol(IVi xConfigura tionParame ters confi g)
  2215           {
  2216                String s ystemDrive  = Environ ment.GetEn vironmentV ariable("S ystemDrive ", Environ mentVariab leTarget.P rocess).To Upper() +  @"\";
  2217                String j avaPath =  JavaFacade .GetActive JavaPath(J avaFacade. IsActiveJr eInstalled ());
  2218                String t omcatPath  = TomcatFa cade.Tomca tInstallat ionFolder;
  2219                String l aurelBridg ePath = La urelBridge Facade.Get ActiveDcfR ootFromMan ifest();
  2220                String s erviceAcco untUsernam e = Tomcat Facade.Ser viceAccoun tUsername;
  2221  
  2222                Info("Se tting file  system ac cess rules .");
  2223                try
  2224                {
  2225                    Info ("Applying  access co ntrol for  the " + se rviceAccou ntUsername  + " accou nt to " +  systemDriv e);
  2226                    Acce ssContolUt ilities.Se tRootDirec toryAccess Control(se rviceAccou ntUsername , systemDr ive);
  2227                }
  2228                catch (E xception e x)
  2229                {
  2230                    Info ("Non fata l error de nying acce ss to " +  serviceAcc ountUserna me + " acc ount to "  + systemDr ive);
  2231                    Logg er().Warn( "Non fatal  error den ying acces s to " + s erviceAcco untUsernam e + " acco unt to " +  systemDri ve);
  2232                    Logg er().Warn( ex.Message );
  2233                }
  2234                Info("Ap plying acc ess contro l for the  " + servic eAccountUs ername + "  account t o " + java Path);
  2235                AccessCo ntolUtilit ies.SetJav aDirectory AccessCont rol(servic eAccountUs ername, ja vaPath);
  2236                Info("Ap plying acc ess contro l for the  " + servic eAccountUs ername + "  account t o " + tomc atPath);
  2237                AccessCo ntolUtilit ies.SetTom catAccessC ontrol(ser viceAccoun tUsername,  tomcatPat h);
  2238                if (Laur elBridgeFa cade.IsLau relBridgeR equired(co nfig))
  2239                {
  2240                    Info ("Applying  access co ntrol for  the " + se rviceAccou ntUsername  + " accou nt to " +  laurelBrid gePath);
  2241                    Acce ssContolUt ilities.Se tDcfDirect oryAccessC ontrol(ser viceAccoun tUsername,  laurelBri dgePath);
  2242                }
  2243                Info("Ap plying acc ess contro l for the  " + servic eAccountUs ername + "  account t o " + conf ig.ConfigD ir.Replace (@"/",@"\" ));
  2244                AccessCo ntolUtilit ies.SetFul lDirectory AccessCont rol(servic eAccountUs ername, co nfig.Confi gDir);
  2245  
  2246                Info("Ap plying acc ess contro l for the  " + servic eAccountUs ername + "  account t o " + VixF acade.GetV ixCertific ateStoreDi r());
  2247                AccessCo ntolUtilit ies.SetFul lDirectory AccessCont rol(servic eAccountUs ername, Vi xFacade.Ge tVixCertif icateStore Dir());
  2248  
  2249                // if th e cache is  in a loca l dir, the n apply ac cess contr ol
  2250                if (conf ig.LocalCa cheDir !=  null)
  2251                {
  2252                    Info ("Applying  access co ntrol for  the " + se rviceAccou ntUsername  + " accou nt to " +  config.Loc alCacheDir .Replace(@ "/", @"\") );
  2253                    Acce ssContolUt ilities.Se tFullDirec toryAccess Control(se rviceAccou ntUsername , config.L ocalCacheD ir);
  2254                }
  2255  
  2256                if (conf ig.VixRole  == VixRol eType.Dico mGateway)
  2257                {
  2258                    stri ng dicomDi r = GetFul lyQuaified HdigDicomD irectory() ;
  2259                    if ( dicomDir ! = null)
  2260                    {
  2261                         Info("Appl ying acces s control  for the "  + serviceA ccountUser name + " a ccount to  " + dicomD ir);
  2262                         AccessCont olUtilitie s.SetFullD irectoryAc cessContro l(serviceA ccountUser name, dico mDir);
  2263                    }
  2264                }
  2265           }
  2266  
  2267           // / <summary >
  2268           //
  2269           // / </summar y>
  2270           // / <param n ame="confi g"></param >
  2271           pr ivate stat ic void Cr eateEnviro nmentVaria bles(IVixC onfigurati onParamete rs config)
  2272           {
  2273                Info("Se tting Wind ows enviro nment vari ables.");
  2274                // set t he vixconf ig environ ment varia ble to the  local con figuration  dir
  2275                String v ixConfigDi r = config .ConfigDir .Replace(@ "\", @"/") ; // trans late file  system del imiter so  Java doesn t barf
  2276                Info("Se tting Wind ows enviro nment vari able vixco nfig=" + v ixConfigDi r.Replace( @"/", @"\" ));
  2277                Environm ent.SetEnv ironmentVa riable("vi xconfig",  vixConfigD ir, Enviro nmentVaria bleTarget. Machine);
  2278  
  2279                if (conf ig.LocalCa cheDir !=  null)
  2280                {
  2281                    Stri ng vixCach eDir = con fig.LocalC acheDir.Re place(@"\" , @"/"); / / translat e file sys tem delimi ter so Jav a doesnt b arf
  2282                    // s et the vix cache envi ronment va riable to  the local  cache dir
  2283                    Info ("Setting  Windows en vironment  variable v ixcache="  + vixCache Dir.Replac e(@"/", @" \"));
  2284                    Envi ronment.Se tEnvironme ntVariable ("vixcache ", vixCach eDir, Envi ronmentVar iableTarge t.Machine) ;
  2285                }
  2286                else
  2287                {
  2288                    // s et the vix cache envi ronment va riable to  the cache  network sh are
  2289                    Info ("Setting  Windows en vironment  variable v ixcache="  + config.N etworkFile Share);
  2290                    Envi ronment.Se tEnvironme ntVariable ("vixcache ", config. NetworkFil eShare, En vironmentV ariableTar get.Machin e);
  2291                }
  2292  
  2293                Info("Se tting Wind ows enviro nment vari able CATAL INA_HOME="  + TomcatF acade.Tomc atInstalla tionFolder );
  2294                Environm ent.SetEnv ironmentVa riable("CA TALINA_HOM E", Tomcat Facade.Tom catInstall ationFolde r, Environ mentVariab leTarget.M achine);
  2295           }
  2296  
  2297           pr ivate stat ic bool Is LocalCache Configured (IVixConfi gurationPa rameters c onfig)
  2298           {
  2299                bool isC onfigured  = true;
  2300                Debug.As sert(confi g.LocalCac heDir != n ull);
  2301                Debug.As sert(confi g.ConfigDi r != null) ;
  2302  
  2303                if (File .Exists(Vi xFacade.Vi xConfigFil espec) ==  false)
  2304                {
  2305                    isCo nfigured =  false;
  2306                }
  2307  
  2308                string c acheRegion Dirspec =  Path.Combi ne(config. LocalCache Dir, EXCHA NGE_CACHE_ DOD_IMAGE_ REGION);
  2309                if (Dire ctory.Exis ts(cacheRe gionDirspe c) == fals e)
  2310                {
  2311                    isCo nfigured =  false;
  2312                }
  2313                
  2314                return i sConfigure d;
  2315           }
  2316  
  2317           pr ivate stat ic readonl y String D OD_METADAT A_REGION =  @"dod-met adata-regi on";
  2318           pr ivate stat ic readonl y String D OD_IMAGE_R EGION = @" dod-image- region";
  2319           pr ivate stat ic readonl y String V A_METADATA _REGION =  @"va-metad ata-region ";
  2320           pr ivate stat ic readonl y String V A_IMAGE_RE GION = @"v a-image-re gion";
  2321  
  2322           pr ivate stat ic void De leteAllLoc alCacheReg ions(IVixC onfigurati onParamete rs config)
  2323           {
  2324                if (IsLo calCacheCo nfigured(c onfig))
  2325                {
  2326                    Logg er().Info( Info("Dele ting files  from the  local VIX  cache."));
  2327                    Info ("This may  take seve ral minute s - please  be patien t.");
  2328                    stri ng baseCac heDir = co nfig.Local CacheDir.R eplace("/" , @"\");
  2329                    Dele teCacheReg ion(baseCa cheDir, DO D_METADATA _REGION);
  2330                    Dele teCacheReg ion(baseCa cheDir, DO D_IMAGE_RE GION);
  2331                    Dele teCacheReg ion(baseCa cheDir, VA _METADATA_ REGION);
  2332                    Dele teCacheReg ion(baseCa cheDir, VA _IMAGE_REG ION);
  2333                    Info ("The VIX  cache has  been clear ed.");
  2334                }
  2335           }
  2336           
  2337           pr ivate stat ic void De leteCacheR egion(stri ng baseCac heDir, str ing region Dir)
  2338           {
  2339                string r egionPath  = Path.Com bine(baseC acheDir, r egionDir);
  2340                string f ooDir = Pa th.Combine (baseCache Dir, "foo" );
  2341                if (Dire ctory.Exis ts(regionP ath))
  2342                {
  2343                    Logg er().Info( Info("Dele ting conte nts of " +  regionPat h));
  2344                    stri ng[] dirs  = Director y.GetDirec tories(reg ionPath);
  2345                    fore ach (strin g subDir i n dirs)
  2346                    {
  2347                         try
  2348                         {
  2349                             Direct ory.Move(s ubDir, foo Dir);
  2350                             Direct ory.Delete (fooDir, t rue);
  2351                         }
  2352                         catch (Exc eption) {  }
  2353                         finally
  2354                         {
  2355                             if (Di rectory.Ex ists(subDi r))
  2356                             {
  2357                                 Lo gger().Err or("Could  not delete  directory  " + subDi r);
  2358                             }
  2359                         }
  2360                    }
  2361                }
  2362           }
  2363  
  2364           // / <summary >
  2365           // / Copy the  sites fil e (usualy  vhasites.x ml) to the  VIX confi g director y and rena me to vhas ites.xml.
  2366           // / </summar y>
  2367           // / <param n ame="confi g"></param >
  2368           pr ivate stat ic void De ploySitesF ile(IVixCo nfiguratio nParameter s config)
  2369           {
  2370                string t argetFiles pec = Path .Combine(G etVixConfi gurationDi rectory(),  "VhaSites .xml");
  2371                Debug.As sert(File. Exists(con fig.SitesF ile));
  2372                File.Cop y(config.S itesFile,  targetFile spec, true ); // over write
  2373           }
  2374  
  2375           pr ivate stat ic void TC PTimeoutIn Registry() {
  2376  
  2377                Registry View regVi ew = Regis tryView.Re gistry64;
  2378                string k ey = @"SYS TEM\Curren tControlSe t\Services \Tcpip\Par ameters";
  2379                using (R egistryKey  regKey =  RegistryKe y.OpenBase Key(Regist ryHive.Loc alMachine,  regView))
  2380                {
  2381                    usin g (Registr yKey tcpKe y = regKey .OpenSubKe y(key, tru e))
  2382                    {
  2383                         tcpKey.Set Value("Tcp TimedWaitD elay", 30,  RegistryV alueKind.D Word);
  2384                    }
  2385                }
  2386           }
  2387  
  2388           pr ivate stat ic void Ru nNetworkCo nfiguratio nCommand() {
  2389                int exit Code = 0;
  2390                using (P rocess ext ernalProce ss = new P rocess())
  2391                {
  2392                    exte rnalProces s.StartInf o.FileName  = "NetSh" ;
  2393                    exte rnalProces s.StartInf o.Argument s = "INT I PV4 SET Dy namicPort  TCP Start= 1025 num=6 4511";
  2394                    //ex ternalProc ess.StartI nfo.Workin gDirectory ;
  2395                    exte rnalProces s.StartInf o.UseShell Execute =  false;
  2396                    exte rnalProces s.StartInf o.CreateNo Window = t rue;
  2397                    exte rnalProces s.Start();
  2398  
  2399                    try
  2400                    {
  2401                         do
  2402                         {
  2403                             DoEven ts();
  2404                             Thread .Sleep(500 );
  2405                             extern alProcess. Refresh();
  2406                         } while (! externalPr ocess.HasE xited);
  2407                         exitCode =  externalP rocess.Exi tCode;
  2408                    }
  2409                    fina lly
  2410                    {
  2411                         externalPr ocess.Clos e();
  2412                    }
  2413                }
  2414  
  2415           }
  2416           
  2417           #e ndregion
  2418       }
  2419   }
  2420  
  2421