Basic Plugs Inspector code working - it can load plugs from all referenced assemblies correctly and display the list of plugs.

This commit is contained in:
EdwardNutting_cp 2014-02-01 12:21:04 +00:00
parent 3bc116caa3
commit b7fbc80043
7 changed files with 237 additions and 28 deletions

View file

@ -566,7 +566,6 @@ Global
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Any CPU.Build.0 = Release|Any CPU
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Mixed Platforms.ActiveCfg = Release|x86
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Mixed Platforms.Build.0 = Release|x86
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|x86.ActiveCfg = Release|x86
{5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|x86.Build.0 = Release|x86
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -576,7 +575,6 @@ Global
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Any CPU.Build.0 = Release|Any CPU
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Mixed Platforms.ActiveCfg = Release|x86
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Mixed Platforms.Build.0 = Release|x86
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|x86.ActiveCfg = Release|x86
{819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|x86.Build.0 = Release|x86
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -586,7 +584,6 @@ Global
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Any CPU.Build.0 = Release|Any CPU
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Mixed Platforms.ActiveCfg = Release|x86
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Mixed Platforms.Build.0 = Release|x86
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|x86.ActiveCfg = Release|x86
{6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|x86.Build.0 = Release|x86
{0462E82B-8C29-41A9-8265-9C89038ADB29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -668,7 +665,6 @@ Global
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Any CPU.Build.0 = Release|Any CPU
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Mixed Platforms.ActiveCfg = Release|x86
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Mixed Platforms.Build.0 = Release|x86
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|x86.ActiveCfg = Release|x86
{B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|x86.Build.0 = Release|x86
{6658FCE0-7032-4B7B-BD95-F2765C393442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@ -855,7 +851,6 @@ Global
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Any CPU.Build.0 = Release|Any CPU
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Mixed Platforms.ActiveCfg = Release|x86
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Mixed Platforms.Build.0 = Release|x86
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|x86.ActiveCfg = Release|x86
{73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|x86.Build.0 = Release|x86
{5B2C0369-7A84-4113-892C-F71B50E1DA12}.Debug|Any CPU.ActiveCfg = Debug|x86
@ -960,7 +955,6 @@ Global
{6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Any CPU.Build.0 = Release|Any CPU
{6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|x86.ActiveCfg = Release|Any CPU
{86F88A09-6801-4474-BFC8-EF09F3A9B89D}.Debug|Any CPU.ActiveCfg = Debug|x86
{86F88A09-6801-4474-BFC8-EF09F3A9B89D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
@ -1117,7 +1111,6 @@ Global
{8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Any CPU.Build.0 = Release|Any CPU
{8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|x86.ActiveCfg = Release|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
@ -1127,7 +1120,6 @@ Global
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Any CPU.Build.0 = Debug|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Mixed Platforms.ActiveCfg = Debug|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Mixed Platforms.Build.0 = Debug|Any CPU
{91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|x86.ActiveCfg = Debug|Any CPU
{5DE37AE3-3F59-4D15-851B-945C23DBB633}.Debug|Any CPU.ActiveCfg = Debug|x86
{5DE37AE3-3F59-4D15-851B-945C23DBB633}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
@ -1147,7 +1139,6 @@ Global
{DA4198CA-59DF-41B3-9884-867647900D76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA4198CA-59DF-41B3-9884-867647900D76}.Release|Any CPU.Build.0 = Release|Any CPU
{DA4198CA-59DF-41B3-9884-867647900D76}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DA4198CA-59DF-41B3-9884-867647900D76}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DA4198CA-59DF-41B3-9884-867647900D76}.Release|x86.ActiveCfg = Release|Any CPU
{0A7DF241-1000-405D-A09B-9E2C51A5CB95}.Debug|Any CPU.ActiveCfg = Debug|x86
{0A7DF241-1000-405D-A09B-9E2C51A5CB95}.Debug|Any CPU.Build.0 = Debug|x86
@ -1199,7 +1190,6 @@ Global
{05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Any CPU.Build.0 = Release|Any CPU
{05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|x86.ActiveCfg = Release|Any CPU
{6C741857-F812-4D37-85CA-A0487B95A8D7}.Debug|Any CPU.ActiveCfg = Debug|x86
{6C741857-F812-4D37-85CA-A0487B95A8D7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86

View file

@ -14,6 +14,8 @@ using _MemberInfo = System.Runtime.InteropServices._MemberInfo;
namespace Cosmos.IL2CPU
{
public delegate void LogExceptionDelegate(Exception e);
// This is necessary because HashSet and Dictionary
// have troubles when different types of objects are stored
// in them. I dont remember the exact problem, but something
@ -58,7 +60,6 @@ namespace Cosmos.IL2CPU
public class ILScanner : IDisposable
{
public delegate void LogExceptionDelegate(Exception e);
public LogExceptionDelegate LogException = null;
protected ILReader mReader;
@ -100,7 +101,7 @@ namespace Cosmos.IL2CPU
mAsmblr = aAsmblr;
mReader = new ILReader();
mPlugManager = new PlugManager(this.ScanMethod, this.Queue);
mPlugManager = new PlugManager(this.LogException, this.ScanMethod, this.Queue);
}
public void EnableLogging(string aPathname)

View file

@ -16,7 +16,8 @@ namespace Cosmos.IL2CPU
{
public class PlugManager
{
public delegate void LogExceptionDelegate(Exception e);
public bool ThrowExceptions = true;
public LogExceptionDelegate LogException = null;
public delegate void ScanMethodDelegate(MethodBase aMethod, bool aIsPlug, object sourceItem);
@ -63,11 +64,13 @@ namespace Cosmos.IL2CPU
}
public PlugManager()
public PlugManager(LogExceptionDelegate aLogException)
{
LogException = aLogException;
}
public PlugManager(ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod)
public PlugManager(LogExceptionDelegate aLogException, ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod)
{
LogException = aLogException;
ScanMethod = aScanMethod;
Queue = aQueueMethod;
}
@ -319,7 +322,15 @@ namespace Cosmos.IL2CPU
{
if (xAttrib.IsWildcard && xAttrib.Assembler == null)
{
throw new Exception("Wildcard PlugMethods need to use an assembler for now.");
Exception anEx = new Exception("Wildcard PlugMethods need to use an assembler for now.");
if (ThrowExceptions)
{
throw anEx;
}
else
{
LogException(anEx);
}
}
if (xAttrib.Enabled && !xAttrib.IsMonoOnly)
{
@ -342,7 +353,15 @@ namespace Cosmos.IL2CPU
}
if (xFields.ContainsKey(xField.FieldId))
{
throw new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!");
Exception anEx = new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!");
if (ThrowExceptions)
{
throw anEx;
}
else
{
LogException(anEx);
}
}
xFields.Add(xField.FieldId, xField);
}
@ -718,5 +737,13 @@ namespace Cosmos.IL2CPU
}
}
public void Clean()
{
mPlugImpls = new Dictionary<Type, List<Type>>();
mPlugImplsInhrt = new Dictionary<Type, List<Type>>();
mPlugFields = new Dictionary<Type, IDictionary<string, PlugFieldAttribute>>();
ResolvedPlugs = new Orvid.Collections.SkipList();
}
}
}

View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace PlugsInspector
{
public class AssembliesPreloader
{
public static void LoadAllAssemblies()
{
AllFilesInApplicationFolder().ForEach(fi => Assembly.LoadFrom(fi.FullName));
}
public static List<FileInfo> AllDllFilesIn(string path, bool recursively = false)
{
return new DirectoryInfo(path)
.EnumerateFiles("*.dll", recursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList();
}
public static List<FileInfo> AllFilesInApplicationFolder()
{
return AllDllFilesIn(Path.GetDirectoryName(Application.ExecutablePath), true);
}
}
}

View file

@ -28,36 +28,60 @@
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.LoadPlugsButton = new System.Windows.Forms.Button();
this.PlugsListBox = new System.Windows.Forms.ListBox();
this.ExceptionsListBox = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// label1
// LoadPlugsButton
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(85, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Plugs assembly :";
this.LoadPlugsButton.Location = new System.Drawing.Point(13, 13);
this.LoadPlugsButton.Name = "LoadPlugsButton";
this.LoadPlugsButton.Size = new System.Drawing.Size(75, 23);
this.LoadPlugsButton.TabIndex = 0;
this.LoadPlugsButton.Text = "Load Plugs";
this.LoadPlugsButton.UseVisualStyleBackColor = true;
this.LoadPlugsButton.Click += new System.EventHandler(this.LoadPlugsButton_Click);
//
// PlugsListBox
//
this.PlugsListBox.FormattingEnabled = true;
this.PlugsListBox.Location = new System.Drawing.Point(13, 42);
this.PlugsListBox.Name = "PlugsListBox";
this.PlugsListBox.Size = new System.Drawing.Size(642, 511);
this.PlugsListBox.Sorted = true;
this.PlugsListBox.TabIndex = 1;
//
// ExceptionsListBox
//
this.ExceptionsListBox.FormattingEnabled = true;
this.ExceptionsListBox.Location = new System.Drawing.Point(661, 42);
this.ExceptionsListBox.Name = "ExceptionsListBox";
this.ExceptionsListBox.Size = new System.Drawing.Size(505, 511);
this.ExceptionsListBox.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1178, 568);
this.Controls.Add(this.label1);
this.Controls.Add(this.ExceptionsListBox);
this.Controls.Add(this.PlugsListBox);
this.Controls.Add(this.LoadPlugsButton);
this.Name = "Form1";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Plugs Inspector";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button LoadPlugsButton;
private System.Windows.Forms.ListBox PlugsListBox;
private System.Windows.Forms.ListBox ExceptionsListBox;
}
}

View file

@ -8,13 +8,128 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cosmos.IL2CPU;
using System.Reflection;
namespace PlugsInspector
{
public partial class Form1 : Form
{
PlugManager plugManager;
bool LoadingPlugs = false;
public Form1()
{
InitializeComponent();
//Force it to load/include all plugs assemblies so all types are correctly found
//Otherwise the CLR's delay loading techniques block us...
AssembliesPreloader.LoadAllAssemblies();
plugManager = new PlugManager((Exception ex) => {
AddExceptionEntry(ex.Message);
}, this.ScanMethod, null);
plugManager.ThrowExceptions = false;
}
private void LoadPlugsButton_Click(object sender, EventArgs e)
{
if (!LoadingPlugs)
{
PlugsListBox.Items.Clear();
ExceptionsListBox.Items.Clear();
new Task(LoadPlugs).Start();
}
}
private void LoadPlugs()
{
if (LoadingPlugs)
return;
try
{
LoadingPlugs = true;
plugManager.Clean();
plugManager.FindPlugImpls();
plugManager.ScanFoundPlugs();
foreach (Type pluggedMethodType in plugManager.PlugImpls.Keys)
{
string name = "";
if (pluggedMethodType.DeclaringType != null)
{
name += pluggedMethodType.DeclaringType.Name + ".";
}
name += pluggedMethodType.Name;
AddPlugEntry(name);
}
foreach (Type pluggedMethodType in plugManager.PlugImplsInhrt.Keys)
{
string name = "";
if (pluggedMethodType.DeclaringType != null)
{
name += pluggedMethodType.DeclaringType.Name + ".";
}
name += pluggedMethodType.Name;
AddPlugEntry(name);
}
foreach (Type pluggedFieldType in plugManager.PlugFields.Keys)
{
string name = "";
if (pluggedFieldType.DeclaringType != null)
{
name += pluggedFieldType.DeclaringType.Name + ".";
}
name += pluggedFieldType.Name;
AddPlugEntry(name);
}
}
catch(Exception ex)
{
AddPlugEntry("Error loading plugs: " + ex.Message);
}
finally
{
LoadingPlugs = false;
}
}
private void ScanMethod(MethodBase aMethod, bool aIsPlug, object sourceItem)
{
string name = "";
if (aMethod.DeclaringType != null)
{
name += aMethod.DeclaringType.Name + ".";
}
name += aMethod.Name;
AddPlugEntry(name);
}
private delegate void AddPlugEntryCallback(string text);
private void AddPlugEntry(string text)
{
if (this.InvokeRequired)
{
this.Invoke(new AddPlugEntryCallback(this.AddPlugEntry), new object[] { text });
}
else
{
this.PlugsListBox.Items.Add(text);
}
}
private delegate void AddExceptionEntryCallback(string text);
private void AddExceptionEntry(string text)
{
if (this.InvokeRequired)
{
this.Invoke(new AddExceptionEntryCallback(this.AddExceptionEntry), new object[] { text });
}
else
{
this.ExceptionsListBox.Items.Add(text);
}
}
}
}

View file

@ -48,6 +48,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssembliesPreloader.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
@ -81,6 +82,28 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\IL2CPU\Cosmos.IL2CPU.Plugs\Cosmos.IL2CPU.Plugs.csproj">
<Project>{c801f19c-a9d3-42d5-9a57-9ffdf9b4d05e}</Project>
<Name>Cosmos.IL2CPU.Plugs</Name>
</ProjectReference>
<ProjectReference Include="..\..\IL2CPU\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj">
<Project>{239e33a7-f0c3-4801-85ca-4d8f89a31dc0}</Project>
<Name>Cosmos.IL2CPU</Name>
</ProjectReference>
<ProjectReference Include="..\..\Kernel\Debug\Cosmos.Debug.Kernel.Plugs\Cosmos.Debug.Kernel.Plugs.csproj">
<Project>{b97a2956-c363-47f2-a6aa-b4fccff4d315}</Project>
<Name>Cosmos.Debug.Kernel.Plugs</Name>
</ProjectReference>
<ProjectReference Include="..\..\Kernel\Debug\Cosmos.Debug.Kernel\Cosmos.Debug.Kernel.csproj">
<Project>{61607f1e-58f9-41cf-972f-128384f3e115}</Project>
<Name>Cosmos.Debug.Kernel</Name>
</ProjectReference>
<ProjectReference Include="..\..\Kernel\System\Cosmos.System.Plugs.System\Cosmos.System.Plugs.System.csproj">
<Project>{7c64b97f-516d-4a6d-b9e1-3fe48f561409}</Project>
<Name>Cosmos.System.Plugs.System</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.