-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomLinqQuery.cs
More file actions
102 lines (84 loc) · 3.47 KB
/
CustomLinqQuery.cs
File metadata and controls
102 lines (84 loc) · 3.47 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mooege.Net.GS.Message;
using Mooege.Net.GS.Message.Definitions.ACD;
using System.Reflection;
using System.IO;
namespace GameMessageViewer
{
public partial class CustomLinqQuery : Form
{
List<MessageNode> mNodes = new List<MessageNode>();
List<BufferNode> bNodes = new List<BufferNode>();
public IEnumerable<MessageNode> QueryResult = new List<MessageNode>();
public CustomLinqQuery()
{
InitializeComponent();
}
class cboEntry
{
public Type type;
public cboEntry(Type type) { this.type = type; }
public override string ToString() { return type.Name; }
}
internal DialogResult Show(IEnumerable<BufferNode> nodes)
{
// Gather all Types in the AppDomain that inherit from GameMessage
List<cboEntry> items = new List<cboEntry>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (Type type in assembly.GetTypes())
if (type.BaseType == typeof(GameMessage))
items.Add(new cboEntry(type));
// show them in a combobox
var sorted = items.OrderBy(x => x.ToString());
foreach (cboEntry message in sorted)
comboBox1.Items.Add(message);
// Create a List of only MessageNodes
foreach (BufferNode bn in nodes)
foreach (MessageNode mn in bn.allNodes)
mNodes.Add(mn);
comboBox1.SelectedIndex = 0;
this.ShowDialog();
return DialogResult;
}
private void button1_Click(object sender, EventArgs e)
{
//string f = "";
//for (int i = 0; i < 40; i++)
//{
Type genericQuery = typeof(QueryTemplate<>);
Type concreteQuery = genericQuery.MakeGenericType(((cboEntry)comboBox1.SelectedItem).type);
object query = Activator.CreateInstance(concreteQuery);
try
{
QueryResult = (IEnumerable<MessageNode>)concreteQuery.GetMethod("Query").Invoke(query, new object[] { mNodes, textBox1.Text });
//QueryResult = (IEnumerable<MessageNode>)concreteQuery.GetMethod("Query").Invoke(query, new object[] { mNodes, "Field2==" + i });
QueryResult.Count(); // Force evaluation
}
catch (Exception exception)
{
lblException.Text = exception.Message;
return;
}
//string s = i.ToString("X8") + "\r\n";
//foreach (MessageNode mn in QueryResult)
// s += (mn.gameMessage as ACDEnterKnownMessage).ActorSNO + ":" + SNOAliases.Aliases[(mn.gameMessage as ACDEnterKnownMessage).ActorSNO.ToString()] + "\r\n";
//f += "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + s;
//}
//File.WriteAllText("F:\\out.txt", f);
DialogResult = DialogResult.OK;
this.Close();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
button1_Click(sender, e);
}
}
}