-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundRequest.cs
193 lines (170 loc) · 6.52 KB
/
BackgroundRequest.cs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using FLAccountDB.Data;
using FLAccountDB.LoginDB;
using LogDispatcher;
namespace FLAccountDB
{
public static class BackgroundRequest
{
static event EventHandler OnMetaReady;
static event EventHandler OnIPReady;
static event EventHandler OnIDReady;
public static readonly OneShotHandlerQueue<EventArgs> IPDataReady = new OneShotHandlerQueue<EventArgs>();
public static readonly OneShotHandlerQueue<EventArgs> IDDataReady = new OneShotHandlerQueue<EventArgs>();
public static readonly OneShotHandlerQueue<EventArgs> MetaDataReady = new OneShotHandlerQueue<EventArgs>();
static BackgroundRequest()
{
OnMetaReady += MetaDataReady.Handle;
OnIPReady += IPDataReady.Handle;
OnIDReady += IDDataReady.Handle;
}
public static void GetIPData(SQLiteConnection conn, string command)
{
var bgw = new BackgroundWorker();
//bgw.RunWorkerCompleted += ;
bgw.DoWork += _bgw_DoWork_IP;
bgw.RunWorkerAsync(
new object[]
{
conn,
command
});
}
static void _bgw_DoWork_IP(object sender, DoWorkEventArgs e)
{
OnIPReady(GetIP((string)((object[])e.Argument)[1], (SQLiteConnection)((object[])e.Argument)[0]), null);
}
/// <summary>
/// Executes the issued command in current thread and returns list of resulting IP data.
/// </summary>
/// <param name="command"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static List<IPData> GetIP(string command, SQLiteConnection conn)
{
Logger.LogDisp.NewMessage(LogType.Debug, "GetIP Query: {0}", command);
if (conn == null) return null;
if (conn.State == ConnectionState.Closed) return null;
var ret = new List<IPData>();
using (var cmd = new SQLiteCommand(command, conn))
{
cmd.CommandText = command;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
var md = new IPData
{
AccID = reader.GetString(0),
IP = reader.GetString(1),
Date = reader.GetDateTime(2)
};
ret.Add(md);
}
}
return ret;
}
public static void GetIDData(SQLiteConnection conn, string command)
{
var bgw = new BackgroundWorker();
//bgw.RunWorkerCompleted += ;
bgw.DoWork += _bgw_DoWork_ID;
bgw.RunWorkerAsync(
new object[]
{
conn,
command
});
}
private static void _bgw_DoWork_ID(object sender, DoWorkEventArgs e)
{
OnIDReady(GetID((string)((object[])e.Argument)[1], (SQLiteConnection)((object[])e.Argument)[0]), null);
}
static void _bgw_DoWork(object sender, DoWorkEventArgs e)
{
OnMetaReady(GetMetaForeground((string)((object[])e.Argument)[1], (SQLiteConnection)((object[])e.Argument)[0]),null);
}
public static void GetMetas(SQLiteConnection conn, string command)
{
var bgw = new BackgroundWorker();
//bgw.RunWorkerCompleted += ;
bgw.DoWork += _bgw_DoWork;
bgw.RunWorkerAsync(
new object[]
{
conn,
command
});
}
/// <summary>
/// Executes the issued command in current thread and returns list of resulting ID data.
/// </summary>
/// <param name="command"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static List<IDData> GetID(string command, SQLiteConnection conn)
{
Logger.LogDisp.NewMessage(LogType.Debug, "GetIP Query: {0}", command);
if (conn == null) return null;
if (conn.State == ConnectionState.Closed) return null;
var ret = new List<IDData>();
using (var cmd = new SQLiteCommand(command, conn))
{
cmd.CommandText = command;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
var md = new IDData
{
AccID = reader.GetString(0),
ID1 = reader.GetString(1),
ID2 = reader.GetString(2)
};
ret.Add(md);
}
}
return ret;
}
/// <summary>
/// Executes the issued command and returns list of resulting acc metadata.
/// </summary>
/// <param name="command"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static List<Metadata> GetMetaForeground(string command,SQLiteConnection conn)
{
Logger.LogDisp.NewMessage(LogType.Debug, "GetMeta Query: {0}", command);
if (conn == null) return null;
if (conn.State == ConnectionState.Closed) return null;
var ret = new List<Metadata>();
using (var cmd = new SQLiteCommand(command, conn))
{
cmd.CommandText = command;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
var md = new Metadata();
//{
md.CharPath = reader.GetString(0);
md.Name = reader.GetString(1);
md.AccountID = reader.GetString(2);
md.CharID = reader.GetString(3);
md.Money = (uint)reader.GetInt32(4);
md.Rank = (byte)reader.GetInt32(5);
md.ShipArch = (uint)reader.GetInt32(6);
md.System = reader.GetString(7);
md.Base = reader.GetValue(8).ToString();
md.Equipment = reader.GetString(9);
md.LastOnline = reader.GetDateTime(11);
md.IsBanned = reader.GetBoolean(14);
//};
ret.Add(md);
}
}
return ret;
}
}
}