-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (77 loc) · 2.66 KB
/
Copy pathProgram.cs
File metadata and controls
78 lines (77 loc) · 2.66 KB
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
71
72
73
74
75
76
77
78
using LiteDB;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Ao.Cache.Sample.CodeGen
{
internal class Program
{
static void Main(string[] args)
{
var db = new LiteDatabase("filename=a.ldb");
var provider = new ServiceCollection()
.AddInMemoryFinder()
.AddSingleton<ILiteDatabase>(db)
.AddSingleton<UserService, Gen.UserServiceProxy>()
.BuildServiceProvider();
var ser = provider.GetRequiredService<UserService>();
while (true)
{
try
{
Console.Write("> ");
var c = Console.ReadLine();
var command = c.Split(' ');
var key = command[0][0];
Console.Clear();
Console.CursorLeft = 0;
var sw = Stopwatch.GetTimestamp();
if (key == 'a')
{
var users = ser.AllUser();
Console.WriteLine("Total:" + users.Length);
foreach (var item in users)
{
Console.WriteLine(item);
}
}
else if (key == 'f')
{
Console.WriteLine(ser.GetUser(command[1]));
}
else if (key == 'i')
{
Console.WriteLine(ser.Add(command[1]).ToString());
}
else if (key == 'r')
{
var count = int.Parse(command[1]);
Console.WriteLine(ser.AddRange(count));
}
else if (key == 'd')
{
Console.WriteLine(ser.Delete(command[1]).ToString());
}
else if (key == 'p')
{
db.Checkpoint();
Console.WriteLine("ok");
}
else if (key == 'c')
{
Console.WriteLine(ser.Clear());
}
else if (key == 'q')
{
break;
}
Console.WriteLine(Stopwatch.GetElapsedTime(sw));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
}