Exemplo n.º 1
0
        private void Idle()
        {
            logger.Info("Scanner service started");
            KillAllScanners();

            while (true)
            {
                try
                {
                    if (_cts.IsCancellationRequested)
                    {
                        break;
                    }

                    var loggedInUserName = ProcessAsCurrentUser.GetLoggedInUserName();
                    if (_loggedUser != loggedInUserName)
                    {
                        KillAllScanners();
                        _loggedUser = loggedInUserName;
                    }

                    var userService = Process.GetProcessesByName(Constants.SCANNER_NAME);
                    if (userService.Length < 1 && !string.IsNullOrEmpty(_loggedUser))
                    {
                        LaunchScannerForLoggedUser();
                    }
                    _cts.Token.WaitHandle.WaitOne(1000);
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }

                var runUserService = Process.GetProcesses()
                                     .Where(p => p.ProcessName.StartsWith(ScannerName))
                                     .FirstOrDefault();

                if (runUserService == null && !String.IsNullOrEmpty(_loggedUser))
                {
                    LaunchScannerForLoggedUser();
                }

                if (_cts.IsCancellationRequested)
                {
                    break;
                }

                _cts.Token.WaitHandle.WaitOne(1000);
            }

            KillAllScanners();
        }
Exemplo n.º 2
0
 private void LaunchScannerForLoggedUser()
 {
     try
     {
         var codeBase = Assembly.GetExecutingAssembly().CodeBase;
         var uri      = new UriBuilder(codeBase);
         var path     = Uri.UnescapeDataString(uri.Path);
         path = Path.Combine(Path.GetDirectoryName(path), Constants.SCANNER_NAME + ".exe " + settings);
         ProcessAsCurrentUser.Launch(path);
     }
     catch (Exception ex)
     {
         logger.Error(ex, "Launch {0}", Constants.SCANNER_NAME);
     }
 }