浏览代码

整理了一下之前的Reflection工具,可以加载约定好的dll

yuzhengyang 8 年之前
父节点
当前提交
a97590e8ce

+ 17 - 0
Fork.Net/Waka.Lego.Baidu/LegoRun.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Waka.Lego.Baidu
+{
+    public class LegoRun
+    {
+        public Form1 Run()
+        {
+            Form1 form = new Form1();
+            return form;
+        }
+    }
+}

+ 5 - 1
Fork.Net/Waka.Lego.Baidu/Waka.Lego.Baidu.csproj

@@ -5,7 +5,7 @@
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProjectGuid>{5BD7BF2A-5FFA-45CB-AA5D-25345C77D964}</ProjectGuid>
-    <OutputType>WinExe</OutputType>
+    <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Waka.Lego.Baidu</RootNamespace>
     <AssemblyName>Waka.Lego.Baidu</AssemblyName>
@@ -32,6 +32,9 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject />
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -52,6 +55,7 @@
     <Compile Include="Form1.Designer.cs">
       <DependentUpon>Form1.cs</DependentUpon>
     </Compile>
+    <Compile Include="LegoRun.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Form1.resx">

+ 13 - 0
Fork.Net/Waka.Lego.Icon/Form1.Designer.cs

@@ -33,6 +33,7 @@
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
             this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
             this.webBrowser1 = new System.Windows.Forms.WebBrowser();
+            this.button1 = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.SuspendLayout();
             // 
@@ -62,11 +63,22 @@
             this.webBrowser1.TabIndex = 1;
             this.webBrowser1.Url = new System.Uri("http://fm.baidu.com/", System.UriKind.Absolute);
             // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(224, 9);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(75, 23);
+            this.button1.TabIndex = 2;
+            this.button1.Text = "button1";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(345, 327);
+            this.Controls.Add(this.button1);
             this.Controls.Add(this.webBrowser1);
             this.Controls.Add(this.pictureBox1);
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
@@ -83,6 +95,7 @@
         private System.Windows.Forms.PictureBox pictureBox1;
         private System.Windows.Forms.NotifyIcon notifyIcon1;
         private System.Windows.Forms.WebBrowser webBrowser1;
+        private System.Windows.Forms.Button button1;
     }
 }
 

+ 5 - 0
Fork.Net/Waka.Lego.Icon/Form1.cs

@@ -27,5 +27,10 @@ namespace Waka.Lego.Icon
         {
             Close();
         }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            new Form2().Show();
+        }
     }
 }

+ 38 - 0
Fork.Net/Waka.Lego.Icon/Form2.Designer.cs

@@ -0,0 +1,38 @@
+namespace Waka.Lego.Icon
+{
+    partial class Form2
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.Text = "Form2";
+        }
+
+        #endregion
+    }
+}

+ 20 - 0
Fork.Net/Waka.Lego.Icon/Form2.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Waka.Lego.Icon
+{
+    public partial class Form2 : Form
+    {
+        public Form2()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 17 - 0
Fork.Net/Waka.Lego.Icon/LegoRun.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Waka.Lego.Icon
+{
+    public class LegoRun
+    {
+        public Form1 Run()
+        {
+            Form1 form = new Form1();
+            return form;
+        }
+    }
+}

+ 11 - 1
Fork.Net/Waka.Lego.Icon/Waka.Lego.Icon.csproj

@@ -5,7 +5,7 @@
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProjectGuid>{328B6806-CC39-4232-AE51-13AABF9A583B}</ProjectGuid>
-    <OutputType>WinExe</OutputType>
+    <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Waka.Lego.Icon</RootNamespace>
     <AssemblyName>Waka.Lego.Icon</AssemblyName>
@@ -35,6 +35,9 @@
   <PropertyGroup>
     <ApplicationIcon>pa.ico</ApplicationIcon>
   </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject />
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -55,6 +58,13 @@
     <Compile Include="Form1.Designer.cs">
       <DependentUpon>Form1.cs</DependentUpon>
     </Compile>
+    <Compile Include="Form2.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form2.Designer.cs">
+      <DependentUpon>Form2.cs</DependentUpon>
+    </Compile>
+    <Compile Include="LegoRun.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Form1.resx">

+ 17 - 0
Fork.Net/Waka.Lego.Music/LegoRun.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Waka.Lego.Music
+{
+    public class LegoRun
+    {
+        public Form1 Run()
+        {
+            Form1 form = new Form1();
+            return form;
+        }
+    }
+}

+ 5 - 1
Fork.Net/Waka.Lego.Music/Waka.Lego.Music.csproj

@@ -5,7 +5,7 @@
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProjectGuid>{B4E47708-0D92-4308-B605-1B9657B308CF}</ProjectGuid>
-    <OutputType>WinExe</OutputType>
+    <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Waka.Lego.Music</RootNamespace>
     <AssemblyName>Waka.Lego.Music</AssemblyName>
@@ -32,6 +32,9 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject />
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -52,6 +55,7 @@
     <Compile Include="Form1.Designer.cs">
       <DependentUpon>Form1.cs</DependentUpon>
     </Compile>
+    <Compile Include="LegoRun.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Form1.resx">

+ 20 - 18
Fork.Net/Waka.Lego/Views/MainForm.Designer.cs

@@ -28,9 +28,9 @@
         /// </summary>
         private void InitializeComponent()
         {
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
             this.dataGridView1 = new System.Windows.Forms.DataGridView();
             this.PluginList = new System.Windows.Forms.DataGridViewTextBoxColumn();
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
@@ -43,29 +43,31 @@
             this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.PluginList});
-            this.dataGridView1.Location = new System.Drawing.Point(12, 12);
+            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.dataGridView1.Location = new System.Drawing.Point(0, 0);
             this.dataGridView1.Name = "dataGridView1";
             this.dataGridView1.ReadOnly = true;
-            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.dataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle5;
+            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.dataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle2;
             this.dataGridView1.RowHeadersVisible = false;
-            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle6;
+            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.dataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle3;
             this.dataGridView1.RowTemplate.Height = 23;
-            this.dataGridView1.Size = new System.Drawing.Size(415, 328);
+            this.dataGridView1.Size = new System.Drawing.Size(894, 534);
             this.dataGridView1.TabIndex = 0;
+            this.dataGridView1.DoubleClick += new System.EventHandler(this.dataGridView1_DoubleClick);
             // 
             // PluginList
             // 
             this.PluginList.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
-            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.PluginList.DefaultCellStyle = dataGridViewCellStyle4;
+            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.PluginList.DefaultCellStyle = dataGridViewCellStyle1;
             this.PluginList.HeaderText = "插件列表";
             this.PluginList.Name = "PluginList";
             this.PluginList.ReadOnly = true;
@@ -74,7 +76,7 @@
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(439, 352);
+            this.ClientSize = new System.Drawing.Size(894, 534);
             this.Controls.Add(this.dataGridView1);
             this.Name = "MainForm";
             this.Text = "MainForm";

+ 27 - 8
Fork.Net/Waka.Lego/Views/MainForm.cs

@@ -4,16 +4,23 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using Waka.Lego.Commons;
 using Y.Utils.IOUtils.LogUtils;
+using Y.Utils.ReflectionUtils.ReflectionCoreUtils;
 
 namespace Waka.Lego.Views
 {
     public partial class MainForm : Form
     {
+        string[] plugins = new string[] {
+                @"D:\CoCo\GitHub\Fork\Fork.Net\Waka.Lego\bin\Debug\Bin\Plugins\Waka.Lego.Baidu\Waka.Lego.Baidu.dll" ,
+                @"D:\CoCo\GitHub\Fork\Fork.Net\Waka.Lego\bin\Debug\Bin\Plugins\Waka.Lego.Icon\Waka.Lego.Icon.dll",
+                @"D:\CoCo\GitHub\Fork\Fork.Net\Waka.Lego\bin\Debug\Bin\Plugins\Waka.Lego.Music\Waka.Lego.Music.dll"};
+
         public MainForm()
         {
             InitializeComponent();
@@ -21,15 +28,27 @@ namespace Waka.Lego.Views
 
         private void MainForm_Load(object sender, EventArgs e)
         {
-            R.Log.IsWriteFile = true;
-            R.Log.LogLevel = LogLevel.Warning | LogLevel.Debug;
-            Log.AllocConsole();
 
-            R.Log.v("this is v 啰嗦");
-            R.Log.d("this is d 调试");
-            R.Log.i("this is i 重要");
-            R.Log.w("this is w 警告");
-            R.Log.e("this is e 错误");
+
+            foreach (var p in plugins)
+            {
+                Assembly ass = Assembly.LoadFile(p);
+                dataGridView1.Rows.Add(string.Format("Name:{0}, Path:{1}", ass.FullName, p));
+            }
+        }
+
+        private void dataGridView1_DoubleClick(object sender, EventArgs e)
+        {
+            if (dataGridView1.CurrentRow != null && dataGridView1.CurrentRow.Index < plugins.Count())
+            {
+                try
+                {
+                    SimpleReflection sr = new SimpleReflection();
+                    Form form = sr.Do<Form>(plugins[dataGridView1.CurrentRow.Index], "LegoRun", "Run", null, null);
+                    form.Show();
+                }
+                catch { }
+            }
         }
     }
 }

+ 10 - 0
Fork.Net/Y.Utils/IOUtils/LogUtils/Log.cs

@@ -2,6 +2,16 @@
 //      https://github.com/yuzhengyang
 //      author:yuzhengyang
 //############################################################
+
+//R.Log.IsWriteFile = true;
+//R.Log.LogLevel = LogLevel.Warning | LogLevel.Debug;
+//Log.AllocConsole();
+//R.Log.v("this is v 啰嗦");
+//R.Log.d("this is d 调试");
+//R.Log.i("this is i 重要");
+//R.Log.w("this is w 警告");
+//R.Log.e("this is e 错误");
+
 using System;
 using System.Runtime.InteropServices;
 using Y.Utils.IOUtils.PathUtils;

+ 5 - 5
Fork.Net/Y.Utils/ReflectionUtils/ReflectionCoreUtils/SimpleReflection.cs

@@ -22,20 +22,20 @@ namespace Y.Utils.ReflectionUtils.ReflectionCoreUtils
         //{
         //    return SearchAssembly(AssemblyPath, args.Name);
         //}
+
         private Assembly SearchAssembly(string path, string name)
         {
-            try
+            List<string> dlls = FileTool.GetFile(path, "*.dll");
+            foreach (var dll in dlls)
             {
-                List<string> dlls = FileTool.GetFile(path, "*.dll");
-                foreach (var dll in dlls)
+                try
                 {
                     Assembly ass = Assembly.LoadFile(dll);
                     if (ass.FullName == name)
                         return ass;
                 }
+                catch { }
             }
-            catch (Exception e)
-            { }
             return null;
         }