alielie
2026-09-10 f3889f2d36c50cf99468594854def9b7ed069fb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Threading;
 
namespace DynamicExpressoWebShell.Services
{
 
    public class CommandEvent
    {
        public CommandEvent(string exp)
        {
            Expression = exp;
            Time = DateTime.UtcNow;
            //UserHostAddress = HttpContext.Current.Request.UserHostAddress;
            //UserAgent = HttpContext.Current.Request.Browser.Browser;
        }
 
        public string Expression { get; private set; }
        public DateTime Time { get; private set; }
        //public string UserHostAddress { get; private set; }
        //public string UserAgent { get; private set; }
    }
 
    public class CommandsHistory
    {
        readonly List<CommandEvent> _lastCommands = new List<CommandEvent>();
        long _count = 0;
        readonly object _lock = new object();
 
        public long Count
        {
            get
            {
                return Interlocked.Read(ref _count);
            }
        }
 
        public void HandleCommandExecuted(CommandEvent cmd)
        {
            Interlocked.Increment(ref _count);
 
            lock (_lock)
            {
                if (_lastCommands.Count > 50)
                    _lastCommands.Clear();
 
                _lastCommands.Add(cmd);
            }
        }
 
        public CommandEvent[] GetLastCommands()
        {
            CommandEvent[] currentList;
            lock (_lock)
            {
                currentList = _lastCommands.ToArray();
            }
 
            return currentList;
        }
 
        public void Clear()
        {
            lock (_lock)
            {
                _lastCommands.Clear();
            }
        }
    }
}