public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
                return _status;

            try
            {
                // get Everyone token for the current locale
                string everyone = new System.Security.Principal.SecurityIdentifier(
                    "S-1-1-0").Translate(typeof(System.Security.Principal.NTAccount)).ToString();
                string port = ConfigurationManager.AppSettings["Port"];
                string arguments = string.Format("http add urlacl url=http://+:{0}/ user=\"\\{1}\"", port, everyone);
                Log.Info("Adding ACL rule...");
                ProcessHelper.RunNetShell(arguments, "Failed to add URL ACL");
                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
                Settings.Instance.UrlReservationSetupHadErrors = true;
                Settings.Instance.Save();
                throw;
            }
            return _status;
        }
Пример #2
0
 public FirewallSetup()
 {
     try
     {
         if (Settings.Instance.FirewallSetupHadErrors)
         {
             _status = SetupStatus.Installed;
         }
         else
         {
             string port      = ConfigurationManager.AppSettings["Port"];
             string arguments = string.Format("advfirewall firewall show rule dir=in name=all");
             Log.Info("Checking Firewall rule...");
             string output = ProcessHelper.RunNetShell(arguments, "Failed to check Firewall rule status");
             // this check is kind of lame, but it works in any locale...
             _status = output.Contains(port) && output.Contains(FirewallRuleName)
                 ? SetupStatus.Installed : SetupStatus.Uninstalled;
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         _status = SetupStatus.Failed;
     }
 }
Пример #3
0
        public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
            {
                return(_status);
            }

            try
            {
                string port      = ConfigurationManager.AppSettings["Port"];
                string arguments = string.Format("advfirewall firewall add rule name=\"{0}\" " +
                                                 "dir=in action=allow protocol=TCP localport={1} remoteip=localsubnet", FirewallRuleName, port);
                Log.Info("Adding Firewall rule...");
                ProcessHelper.RunNetShell(arguments, "Failed to add Firewall rule");
                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                _status = SetupStatus.Failed;
                Log.Error(ex);
                Settings.Instance.FirewallSetupHadErrors = true;
                Settings.Instance.Save();
                throw new Exception("Cannot configure Windows Firewall." + Environment.NewLine +
                                    "If you are using some 3rd-party firewall please open " +
                                    ConfigurationManager.AppSettings["Port"] + " TCP port manually!", ex);
            }

            return(_status);
        }
Пример #4
0
 public void Test_Basic_Constructor_With_Invalid_Values_Throws_Exception(
     bool paramHaveOrganisations,
     bool paramHaveCommittees)
 {
     // ACT
     _ = new SetupStatus(
         haveOrganisations: paramHaveOrganisations,
         haveCommittees: paramHaveCommittees);
 }
Пример #5
0
        public async Task InitManagers()
        {
            _setupStatus = SetupStatus.Started;

            await _setupChain.Exec();

            if (_setupStatus != SetupStatus.Failed)
            {
                _setupStatus = SetupStatus.Complete;
            }
        }
Пример #6
0
        public void Test_Basic_Constructor_With_Valid_Values(
            bool paramHaveOrganisations,
            bool paramHaveCommittees)
        {
            // ACT
            ISetupStatus setupStatus = new SetupStatus(
                haveOrganisations: paramHaveOrganisations,
                haveCommittees: paramHaveCommittees);

            // ASSERT
            Assert.IsNotNull(setupStatus);
            Assert.AreEqual(paramHaveOrganisations, setupStatus.HaveOrganisations);
            Assert.AreEqual(paramHaveCommittees, setupStatus.HaveCommittees);
        }
Пример #7
0
 public PluginSetup()
 {
     try
     {
         Log.Info("Checking plugin DLL files...");
         bool pluginsExist = File.Exists(Ets2X86TelemetryPluginDllFileName) &&
                             File.Exists(Ets2X64TelemetryPluginDllFileName);
         _status = pluginsExist ? SetupStatus.Installed : SetupStatus.Uninstalled;
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         _status = SetupStatus.Failed;
     }
 }
Пример #8
0
 public UrlReservationSetup()
 {
     try
     {
         string port      = ConfigurationManager.AppSettings["Port"];
         string arguments = string.Format(@"http show urlacl url=http://+:{0}/", port);
         Log.Info("Adding ACL rule status...");
         string output = ProcessHelper.RunNetShell(arguments, "Failed to check URL ACL status");
         _status = output.Contains(port) ? SetupStatus.Installed : SetupStatus.Uninstalled;
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         _status = SetupStatus.Failed;
     }
 }
Пример #9
0
        public async Task NoMeetings()
        {
            // ARRANGE
            Mock <ILogger <MyHomeController> > loggerMock = CreateLoggerMock();

            IList <IMeeting> meetingList = new List <IMeeting>();
            ISetupStatus     setupStatus = new SetupStatus(
                haveOrganisations: false,
                haveCommittees: false);

            Mock <IAgendaService> agendaServiceMock = CreateAgendaServiceMock(meetingList, setupStatus);

            Mock <IFeatureManager> featureManagerMock = CreateFeatureManagerMock(
                newReferenceSearch: true);

            using MyHomeController controller = CreateHomeController(
                      loggerMock,
                      agendaServiceMock,
                      featureManagerMock);

            // ACT
            IActionResult actionResult = await controller.Index().ConfigureAwait(false);

            // ASSERT
            // Assert that this is a View Result
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)actionResult;

            // Assert that is has the correct view model.
            Assert.IsNotNull(viewResult.Model);
            Assert.IsInstanceOfType(viewResult.Model, typeof(IndexViewModel));

            // Verify service level methods called the correct number of times.
            agendaServiceMock.Verify(
                x =>
                x.GetRecentMeetingsMostRecentFirstAsync(
                    It.IsAny <IWho>(),
                    It.IsAny <TimeSpan?>(),
                    It.IsAny <int?>()),
                Times.Once());

            agendaServiceMock.Verify(
                x =>
                x.GetSetupStatusAsync(
                    It.IsAny <IWho>()),
                Times.Once);
        }
Пример #10
0
        public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
            {
                return(_status);
            }

            try
            {
                var ets2State = new GameState(Ets2, Settings.Instance.Ets2GamePath);
                var atsState  = new GameState(Ats, Settings.Instance.AtsGamePath);

                if (!ets2State.IsPluginValid())
                {
                    ets2State.DetectPath();
                    if (!ets2State.IsPathValid())
                    {
                        ets2State.BrowserForValidPath(owner);
                    }
                    ets2State.InstallPlugin();
                }

                if (!atsState.IsPluginValid())
                {
                    atsState.DetectPath();
                    if (!atsState.IsPathValid())
                    {
                        atsState.BrowserForValidPath(owner);
                    }
                    atsState.InstallPlugin();
                }

                Settings.Instance.Ets2GamePath = ets2State.GamePath;
                Settings.Instance.AtsGamePath  = atsState.GamePath;
                Settings.Instance.Save();

                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
                throw;
            }

            return(_status);
        }
Пример #11
0
        public SetupStatus Install(IWin32Window owner)
        {
            if (Status == SetupStatus.Installed)
            {
                return(Status);
            }

            try
            {
                var ets2State = new GameState(Ets2, Properties.Settings.Default.ETSPath);
                var atsState  = new GameState(Ats, Properties.Settings.Default.ATSPath);

                if (!ets2State.IsPluginValid())
                {
                    ets2State.DetectPath();
                    if (!ets2State.IsPathValid())
                    {
                        ets2State.BrowserForValidPath(owner);
                    }
                    ets2State.InstallPlugin();
                }

                if (!atsState.IsPluginValid())
                {
                    atsState.DetectPath();
                    if (!atsState.IsPathValid())
                    {
                        atsState.BrowserForValidPath(owner);
                    }
                    atsState.InstallPlugin();
                }

                Properties.Settings.Default.ETSPath = ets2State.GamePath;
                Properties.Settings.Default.ATSPath = atsState.GamePath;
                Properties.Settings.Default.Save();

                Status = SetupStatus.Installed;
            }
            catch (Exception)
            {
                Status = SetupStatus.Failed;
                throw;
            }

            return(Status);
        }
Пример #12
0
        public SetupStatus GetSetupStatus()
        {
            var setupStatus = new SetupStatus();

            try
            {
                var allEntries = GetSchemaVersions();
                var sortedList = _pathMapper.GetAvailableScripts();

                var schemaInstance = allEntries.LastOrDefault();
                var lastInstance   = sortedList.LastOrDefault();

                if (lastInstance != null && lastInstance.Equals(schemaInstance))
                {
                    setupStatus.StatusCode = SetupStatusCode.NoUpdates;
                    setupStatus.Message    = "Your instance is up to date!";
                }
                else
                {
                    setupStatus.StatusCode = SetupStatusCode.HasUpdates;
                    setupStatus.Message    = "Your instance has some updates";
                }
            }
            catch (Exception exception)
            {
                if (exception.Message == "Invalid object name 'Schema'.")
                {
                    setupStatus.StatusCode = SetupStatusCode.DatabaseNotSetup;
                    setupStatus.Message    = "Database has not been setup";
                }
                else
                {
                    setupStatus.StatusCode = SetupStatusCode.DatabaseError;
                    setupStatus.Message    = exception.Message;
                }
            }

            return(setupStatus);
        }
 public UrlReservationSetup()
 {
     try
     {
         if (Settings.Instance.UrlReservationSetupHadErrors)
         {
             _status = SetupStatus.Installed;
         }
         else
         {
             string port = ConfigurationManager.AppSettings["Port"];
             string arguments = $@"http show urlacl url=http://+:{port}/";
             Log.Info("Checking ACL rule status...");
             string output = ProcessHelper.RunNetShell(arguments, "Failed to check URL ACL status");
             _status = output.Contains(port) ? SetupStatus.Installed : SetupStatus.Uninstalled;
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         _status = SetupStatus.Failed;
     }
 }
 public UrlReservationSetup()
 {
     try
     {
         if (Settings.Instance.UrlReservationSetupHadErrors)
         {
             _status = SetupStatus.Installed;
         }
         else
         {
             string port      = ConfigurationManager.AppSettings["Port"];
             string arguments = $@"http show urlacl url=http://+:{port}/";
             Log.Info("Checking ACL rule status...");
             string output = ProcessHelper.RunNetShell(arguments, "Failed to check URL ACL status");
             _status = output.Contains(port) ? SetupStatus.Installed : SetupStatus.Uninstalled;
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         _status = SetupStatus.Failed;
     }
 }
Пример #15
0
        public PluginSetup()
        {
            try
            {
                Log.Info("Checking plugin DLL files...");

                var ets2State = new GameState(Ets2, Settings.Instance.Ets2GamePath);
                var atsState  = new GameState(Ats, Settings.Instance.AtsGamePath);

                if (ets2State.IsPluginValid() && atsState.IsPluginValid())
                {
                    _status = SetupStatus.Installed;
                }
                else
                {
                    _status = SetupStatus.Uninstalled;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
            }
        }
        public PluginSetup()
        {
            try
            {
                Log.Info("Checking plugin DLL files...");
                string gamePath = Settings.Instance.Ets2GamePath;

                if (ValidateEts2Path(gamePath))
                {
                    bool pluginsExist = Md5(GetTelemetryPluginDllFileName(gamePath, x64: true)) == TelemetryX64DllMd5 &&
                                        Md5(GetTelemetryPluginDllFileName(gamePath, x64: false)) == TelemetryX86DllMd5;
                    _status = pluginsExist ? SetupStatus.Installed : SetupStatus.Uninstalled;
                }
                else
                {
                    _status = SetupStatus.Uninstalled;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
            }
        }
Пример #17
0
        public PluginSetup()
        {
            try
            {
                Log.Info("Checking plugin DLL files...");
                string gamePath = Settings.Instance.Ets2GamePath;

                if (ValidateEts2Path(gamePath))
                {
                    bool pluginsExist = Md5(GetTelemetryPluginDllFileName(gamePath, x64: true)) == TelemetryX64DllMd5 &&
                                        Md5(GetTelemetryPluginDllFileName(gamePath, x64: false)) == TelemetryX86DllMd5;
                    _status = pluginsExist ? SetupStatus.Installed : SetupStatus.Uninstalled;
                }
                else
                {
                    _status = SetupStatus.Uninstalled;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
            }
        }
        public PluginSetup()
        {
            try
            {
                Log.Info("Checking plugin DLL files...");

                var ets2State = new GameState(Ets2, Settings.Instance.Ets2GamePath);
                var atsState = new GameState(Ats, Settings.Instance.AtsGamePath);

                if (ets2State.IsPluginValid() && atsState.IsPluginValid())
                {
                    _status = SetupStatus.Installed;
                }
                else
                {
                    _status = SetupStatus.Uninstalled;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
            }
        }
        public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
                return _status;

            try
            {
                var ets2State = new GameState(Ets2, Settings.Instance.Ets2GamePath);
                var atsState = new GameState(Ats, Settings.Instance.AtsGamePath);

                if (!ets2State.IsPluginValid())
                {
                    ets2State.DetectPath();
                    if (!ets2State.IsPathValid())
                        ets2State.BrowserForValidPath(owner);
                    ets2State.InstallPlugin();
                }

                if (!atsState.IsPluginValid())
                {
                    atsState.DetectPath();
                    if (!atsState.IsPathValid())
                        atsState.BrowserForValidPath(owner);
                    atsState.InstallPlugin();
                }

                Settings.Instance.Ets2GamePath = ets2State.GamePath;
                Settings.Instance.AtsGamePath = atsState.GamePath;
                Settings.Instance.Save();

                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
                throw;
            }

            return _status;
        }
        public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
                return _status;

            try
            {
                string gamePath = Settings.Instance.Ets2GamePath;
                if (string.IsNullOrEmpty(gamePath))
                {
                    gamePath = GetDefaultSteamPath();
                    if (!string.IsNullOrEmpty(gamePath))
                        gamePath = Path.Combine(
                            gamePath.Replace('/', '\\'), @"SteamApps\common\Euro Truck Simulator 2");
                }

                while (!ValidateEts2Path(gamePath))
                {
                    MessageBox.Show(owner,
                        @"Could not detect ETS2 game path. " +
                        @"Please click OK and select it manually." + Environment.NewLine + Environment.NewLine +
                        @"For example:" + Environment.NewLine + @"D:\STEAM\SteamApps\common\Euro Truck Simulator 2",
                        @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    var browser = new FolderBrowserDialog();
                    browser.Description = @"Select ETS2 game path";
                    browser.ShowNewFolderButton = false;
                    var result = browser.ShowDialog(owner);
                    if (result == DialogResult.Cancel)
                        Environment.Exit(1);
                    gamePath = browser.SelectedPath;
                }

                Settings.Instance.Ets2GamePath = gamePath;
                Settings.Instance.Save();

                // make sure that we disable old plugin (2.1.0 and earlier)
                // ReSharper disable once AssignNullToNotNullAttribute
                string oldX86PluginDllFileName = Path.Combine(GetPluginPath(gamePath, x64: false),
                    "ets2-telemetry.dll");
                // ReSharper disable once AssignNullToNotNullAttribute
                string oldX64PluginDllFileName = Path.Combine(GetPluginPath(gamePath, x64: true),
                    "ets2-telemetry.dll");
                if (File.Exists(oldX86PluginDllFileName))
                    File.Move(oldX86PluginDllFileName,
                        Path.ChangeExtension(oldX86PluginDllFileName, ".deprecated.bak"));
                if (File.Exists(oldX64PluginDllFileName))
                    File.Move(oldX64PluginDllFileName,
                        Path.ChangeExtension(oldX64PluginDllFileName, ".deprecated.bak"));

                // install new plugin

                string x64DllFileName = GetTelemetryPluginDllFileName(gamePath, x64: true);
                string x86DllFileName = GetTelemetryPluginDllFileName(gamePath, x64: false);

                Log.InfoFormat("Copying x86 plugin DLL file to: {0}", x86DllFileName);
                File.Copy(LocalEts2X86TelemetryPluginDllFileName, x86DllFileName, true);

                Log.InfoFormat("Copying x64 plugin DLL file to: {0}", x64DllFileName);
                File.Copy(LocalEts2X64TelemetryPluginDllFileName, x64DllFileName, true);

                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
                throw;
            }

            return _status;
        }
 private void updateStatus(SetupOption option, SetupStatus status)
 {
     updateStatus(option, status, null);
 }
Пример #22
0
 protected void OnManagerSetupFail(IManager manager)
 {
     _setupStatus = SetupStatus.Failed;
     _managers    = new List <IManager>();
     onSetupFail();
 }
Пример #23
0
        public SetupStatus Install(IWin32Window owner)
        {
            if (_status == SetupStatus.Installed)
            {
                return(_status);
            }

            try
            {
                string gamePath = Settings.Instance.Ets2GamePath;
                if (string.IsNullOrEmpty(gamePath))
                {
                    gamePath = GetDefaultSteamPath();
                    if (!string.IsNullOrEmpty(gamePath))
                    {
                        gamePath = Path.Combine(
                            gamePath.Replace('/', '\\'), @"SteamApps\common\Euro Truck Simulator 2");
                    }
                }

                while (!ValidateEts2Path(gamePath))
                {
                    MessageBox.Show(owner,
                                    @"Could not detect ETS2 game path. " +
                                    @"Please click OK and select it manually." + Environment.NewLine + Environment.NewLine +
                                    @"For example:" + Environment.NewLine + @"D:\STEAM\SteamApps\common\Euro Truck Simulator 2",
                                    @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    var browser = new FolderBrowserDialog();
                    browser.Description         = @"Select ETS2 game path";
                    browser.ShowNewFolderButton = false;
                    var result = browser.ShowDialog(owner);
                    if (result == DialogResult.Cancel)
                    {
                        Environment.Exit(1);
                    }
                    gamePath = browser.SelectedPath;
                }

                Settings.Instance.Ets2GamePath = gamePath;
                Settings.Instance.Save();

                // make sure that we disable old plugin (2.1.0 and earlier)
                // ReSharper disable once AssignNullToNotNullAttribute
                string oldX86PluginDllFileName = Path.Combine(GetPluginPath(gamePath, x64: false),
                                                              "ets2-telemetry.dll");
                // ReSharper disable once AssignNullToNotNullAttribute
                string oldX64PluginDllFileName = Path.Combine(GetPluginPath(gamePath, x64: true),
                                                              "ets2-telemetry.dll");
                if (File.Exists(oldX86PluginDllFileName))
                {
                    File.Move(oldX86PluginDllFileName,
                              Path.ChangeExtension(oldX86PluginDllFileName, ".deprecated.bak"));
                }
                if (File.Exists(oldX64PluginDllFileName))
                {
                    File.Move(oldX64PluginDllFileName,
                              Path.ChangeExtension(oldX64PluginDllFileName, ".deprecated.bak"));
                }

                // install new plugin

                string x64DllFileName = GetTelemetryPluginDllFileName(gamePath, x64: true);
                string x86DllFileName = GetTelemetryPluginDllFileName(gamePath, x64: false);

                Log.InfoFormat("Copying x86 plugin DLL file to: {0}", x86DllFileName);
                File.Copy(LocalEts2X86TelemetryPluginDllFileName, x86DllFileName, true);

                Log.InfoFormat("Copying x64 plugin DLL file to: {0}", x64DllFileName);
                File.Copy(LocalEts2X64TelemetryPluginDllFileName, x64DllFileName, true);

                _status = SetupStatus.Installed;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                _status = SetupStatus.Failed;
                throw;
            }

            return(_status);
        }
 void SetStepStatus(ISetup step, SetupStatus status)
 {
     SetupStatus inverseStatus = status;
     if (Program.UninstallMode)
     {
         switch (status)
         {
             case SetupStatus.Installed:
                 inverseStatus = SetupStatus.Uninstalled;
                 break;
             case SetupStatus.Uninstalled:
                 inverseStatus = SetupStatus.Installed;
                 break;
         }
     }
     // convert status enumeration to images
     Bitmap statusImage = inverseStatus == SetupStatus.Uninstalled
                              ? Resources.StatusIcon
                              : (inverseStatus == SetupStatus.Installed
                                     ? Resources.SuccessStatusIcon
                                     : Resources.FailureStatusIcon);
     if (_setupStatusImages.ContainsKey(step))
         _setupStatusImages[step].Image = statusImage;
 }