Example #1
0
 public static void Kill(string exeName)
 {
     using var cmd = new CommandProcedure()
           {
               FileName  = "taskkill",
               Arguments = $"/F /IM {exeName} /T"
           };
     cmd.Execute();
 }
Example #2
0
 /// <summary>
 /// 使用Windows taskkill命令进行结束
 /// </summary>
 /// <param name="proc"></param>
 /// <exception cref="PlatformNotSupportedException">此命令仅支持WIN32平台,在其它平台调用将抛出此异常</exception>
 public static void TaskKill(this Process proc)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         var logger = LoggerFactory.Auto(nameof(ProcessExtensions));
         var cmd    = new CommandProcedure("cmd.exe", $"/C taskkill /F /PID {proc.Id}");
     }
     else
     {
         throw new PlatformNotSupportedException();
     }
 }
Example #3
0
 private void KilProcesses()
 {
     using var cmd = new CommandProcedure()
           {
               FileName  = "taskkill",
               Arguments = "/f /im adb.exe"
           };
     cmd.OutputReceived += (s, e) =>
     {
         SLogger <AdbServerKiller> .Info(e.Text);
     };
     cmd.Execute();
 }
    private ConsoleCommand(string name, int argumentCountMin, int argumentCountMax, CommandProcedure commandProcedure)
    {
        Guard.CheckIsEmptyString("name", name);

        if (argumentCountMin > argumentCountMax)
        {
            Logger.Error("Cannot add command {0} because argumentCountMin cannot be larger than argumentCountMax", name);
        }

        Name             = name.ToLower();
        ArgumentCountMin = argumentCountMin;
        ArgumentCountMax = argumentCountMax;

        CommandProcedure = commandProcedure;
    }
Example #5
0
    private ConsoleCommand(string name, int argumentCountMin, int argumentCountMax, CommandProcedure commandProcedure)
    {
        Guard.CheckIsEmptyString("name", name);

        if (argumentCountMin > argumentCountMax)
        {
            Logger.Error("Cannot add command <color=" + ConsoleConfiguration.HighlightColour + ">" + "{0}</color> because argumentCountMin cannot be larger than argumentCountMax", name);
        }

        Name             = name.ToLower();
        ArgumentCountMin = argumentCountMin;
        ArgumentCountMax = argumentCountMax;

        CommandProcedure = commandProcedure;
    }
Example #6
0
 protected virtual void KillServer()
 {
     lock (concurrentLock)
     {
         using var cmd = new CommandProcedure(AdbExecutableFile.ToString(), $"-P{ServerEndPoint.Port} kill-server");
         int line = 0;
         cmd.OutputReceived += (s, e) =>
         {
             line++;
             SLogger.Info(this, $"killing adb server {line}:{e.Text}");
         };
         cmd.Execute();
         SLogger.Info(this, "server killed");
     }
 }
Example #7
0
        public async Task CommandProcedure_ExecuteAsync_ParameterContextWithNullableInputAndOutputParams()
        {
            var procedureContext = new InputOutputProcedureContext();

            var dataComponentFactory = new SqlServerDataComponentFactory(new SqlServerTransientRetryPolicy(60, TimeSpan.FromSeconds(30)), AppState.ConnectionString);

            using (var connection = dataComponentFactory.Open())
                using (var procedure = new CommandProcedure(connection, dataComponentFactory))
                {
                    var result = await procedure.ExecuteAsync(procedureContext);

                    Assert.AreEqual(-1, result);
                }

            Assert.IsTrue(procedureContext.InDate.HasValue);
            Assert.IsTrue(procedureContext.OutDate.HasValue);
            Assert.AreEqual(procedureContext.InDate.Value.ToString(), procedureContext.OutDate.Value.ToString());
        }
Example #8
0
        protected override IPEndPoint StartServer()
        {
            var    random = new Random();
            ushort port;

            do
            {
                port = (ushort)random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort);
            } while (PortIsUsinngNow(port));
            using (var cmd =
                       new CommandProcedure("adb.exe", $"-P{port} start-server"))
            {
                cmd.KillChildWhenDisposing = false;
                cmd.OutputReceived        += (s, e) =>
                {
                    SLogger <Win32AdbManager> .Info($"adb server starting: {e.Text}");
                };
                cmd.Disposed += (s, e) => SLogger <Win32AdbManager> .Info("Command start-adb disposed");

                cmd.Execute();
            }
            return(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port));
        }
 public static ConsoleCommand AddCommand(string name, int argumentCountMin, CommandProcedure commandProcedure)
 {
     return(new ConsoleCommand(name, argumentCountMin, 9999, commandProcedure));
 }
 public static ConsoleCommand AddCommand(string name, CommandProcedure commandProcedure)
 {
     return(new ConsoleCommand(name, 0, 0, commandProcedure));
 }
        public SqlServerCommandProcedureWithRetry(IDataComponentFactory factory, RetryOptions retryOptions)
        {
            var instance = new CommandProcedure(factory);

            _proxy = RetryProxy.Create <ICommandProcedure>(instance, retryOptions, new SqlServerTransientErrorTester());
        }
        public SqlServerCommandProcedureWithRetry(DbConnection dbConnection, RetryOptions retryOptions)
        {
            var instance = new CommandProcedure(dbConnection, new SqlServerParameterFactory());

            _proxy = RetryProxy.Create <ICommandProcedure>(instance, retryOptions, new SqlServerTransientErrorTester());
        }
Example #13
0
 public static void Kill(string exeName)
 {
     using var cmd = new CommandProcedure("cmd.exe", "/c", $"taskkill /F /IM {exeName} /T");
     cmd.Execute();
 }
        public SqlServerCommandProcedureWithRetry(IDataComponentFactory factory, SqlServerTransientRetryPolicy retryPolicy)
        {
            var instance = new CommandProcedure(factory);

            _proxy = RetryProxy.Create <ICommandProcedure>(instance, retryPolicy);
        }
        public SqlServerCommandProcedureWithRetry(DbConnection dbConnection, SqlServerTransientRetryPolicy retryPolicy)
        {
            var instance = new CommandProcedure(dbConnection, new SqlServerParameterFactory());

            _proxy = RetryProxy.Create <ICommandProcedure>(instance, retryPolicy);
        }