<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
	<Fragment>
    <PropertyRef Id="STARTSERVICEONINSTALL"/>
    
    <Component Id="CardReaderServiceStarter" Directory="INSTALLFOLDER" 
               Guid="{E37EA846-FF70-4D2C-95CF-EFD06850BBF3}" KeyPath="yes">
      <ServiceControl Id="CardReaderServiceStarter"
                        Start="install"
                        Stop="uninstall"
                        Remove="uninstall"
                        Name="FlexitimeCardReaderService"
                        Wait="yes" />
      <Condition><![CDATA[STARTSERVICEONINSTALL <> "false"]]></Condition>
    </Component>
    
    <Component Id="CardReaderEventLog" Directory="INSTALLFOLDER"
               Guid="{A97DF87D-257C-4321-9ECA-0551FA9301C3}" KeyPath="yes">
      <util:EventSource Log="CardReaderService" 
                        EventMessageFile="[WindowsFolder]Microsoft.NET\Framework\v4.0.30319\EventLogMessages.dll"
                        Name="CardReaderDefaultLogger"/>
    </Component>
    
    <ComponentGroup Id="CardReaderServiceComponents" Directory="INSTALLFOLDER">
      <ComponentRef Id="CardReaderServiceStarter" />
      <ComponentRef Id="CardReaderEventLog" />
      <!-- Start the Smart Card Service which is a dependency of the PCSC library. -->
      <Component Id="SmartCardServiceConfig" Guid="{73D2E31D-F256-457C-AFD5-EC456CDAD7E8}" KeyPath="yes">
        <ServiceControl Id="SmartCardServiceStarter"
                        Start="install"
                        Name="SCardSvr"
                        Wait="yes" />
      </Component>
      <Component Id="CardReaderServiceExe" Guid="{24C9D834-21E2-476D-8302-EF35730D0BA8}">
        <File Id="CardReaderService.exe"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)CardReaderService.exe" />
        <ServiceInstall Id="CardReaderService"
                        Start="auto"
                        ErrorControl="ignore"
                        Type="ownProcess"
                        Vital="yes"
                        Name="FlexitimeCardReaderService"
                        DisplayName="FlexitimeCardReaderService"
                        Description="Flexitime Card Reader Service"
                        Account="LocalSystem">
          <util:PermissionEx  User="Everyone"
                              ServicePauseContinue="yes"
                              ServiceQueryStatus="yes"
                              ServiceStart="yes"
                              ServiceStop="yes"
                              ServiceUserDefinedControl="yes"  />
          <ServiceConfig Id="CardReaderServiceConfig"
                         OnInstall="yes"
                         DelayedAutoStart="0" />
          <util:ServiceConfig FirstFailureActionType="restart"
                              SecondFailureActionType="restart"
                              ThirdFailureActionType="restart"
                              ResetPeriodInDays="1"
                              RestartServiceDelayInSeconds="10" />
        </ServiceInstall>
      </Component>
      <Component Id="CardReaderServiceExeConfig" Guid="{E20D23BC-C8E7-49F8-962C-DE856A84258E}">
        <File Id="CardReaderService.exe.config"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)CardReaderService.exe.config" />
      </Component>
      <Component Id="NewtonsoftJson" Guid="{98006F04-1335-40D5-8D2F-A394C8176A1A}">
        <File Id="Newtonsoft.Json.dll"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)Newtonsoft.Json.dll" />
      </Component>
      <Component Id="Ninject" Guid="{A5C71803-AD3C-45CB-9973-FB5B6C7579D2}">
        <File Id="Ninject.dll"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)Ninject.dll" />
      </Component>
      <Component Id="NinjectExtensionsXmlDll" Guid="{3809511F-9C51-4C05-AFE5-F59160EDCB71}">
        <File Id="Ninject.Extensions.Xml.dll"
              Source="$(var.CardReaderService.TargetDir)Ninject.Extensions.Xml.dll"
              KeyPath="yes"
              Checksum="yes"/>
      </Component>
      <Component Id="NinjectConfig" Guid="{C7106002-A5E5-4223-AC34-75704C71D2F4}">
        <File Id="NinjectConfig.xml"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)NinjectConfig.xml" />
      </Component>
      <Component Id="PCSC" Guid="{9DD367D4-3760-46DA-8A4A-6E801ED754D5}">
        <File Id="pcsc_sharp.dll"
              Checksum="yes"
              KeyPath="yes"
              Source="$(var.CardReaderService.TargetDir)pcsc-sharp.dll" />
      </Component>
    </ComponentGroup>
	</Fragment>
</Wix>
