예제 #1
0
 public void Init()
 {
     using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, regview))
         using (var dtcKey = localMachine.OpenSubKey(RegPathDTCSecurity, true))
         {
             if (dtcKey == null)
             {
                 throw new Exception($@"Registry key not found: HKEY_LOCAL_MACHINE\{RegPathDTCSecurity}");
             }
             InstallState = RegValues.All(p => (int)dtcKey.GetValue(p, 0) == 1) ? InstallState.Installed : InstallState.NotInstalled;
         }
 }
예제 #2
0
    public async Task Execute(Action <string> logOutput, Action <string> logError)
    {
        eventAggregator.PublishOnUIThread(new NestedInstallProgressEvent {
            Name = Name
        });
        try
        {
            using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, regview))
                using (var dtcKey = localMachine.OpenSubKey(RegPathDTCSecurity, true))
                {
                    if (dtcKey == null)
                    {
                        throw new Exception($@"Registry key not found: HKEY_LOCAL_MACHINE\{RegPathDTCSecurity}");
                    }

                    foreach (var regValue in RegValues.Where(p => (int)dtcKey.GetValue(p, 0) != 1).ToList())
                    {
                        dtcKey.SetValue(regValue, 1, RegistryValueKind.DWord);
                        logOutput($@"HKEY_LOCAL_MACHINE\{RegPathDTCSecurity}\{regValue} set to 1");
                    }
                }
            logOutput($"Attempting restart of {Controller.DisplayName}");
            await Controller.ChangeServiceStatus(ServiceControllerStatus.Stopped, Controller.Stop)
            .ConfigureAwait(false);

            await Controller.ChangeServiceStatus(ServiceControllerStatus.Running, Controller.Start)
            .ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            logError("DTC install has failed:");
            logError($"{ex}");
        }
        finally
        {
            eventAggregator.PublishOnUIThread(new NestedInstallCompleteEvent());
        }
    }