Practical basic skills (14) -------- plug-in development of WPF, practical practices -------- wpf

Source: Internet
Author: User

Practical basic skills (14) -------- plug-in development of WPF, practical practices -------- wpf
I. Solution Manager

Ii. Simple Functions

IMsg defines an interface. MYPlugin1 implements the interface function. "plug-in-type development" calls non-referenced dll files when the program is running, and calls the dll method implementation function.

Iii. Code for IMsg, MYPlugin1 (class1 and class2), and plug-in development
Using System; using System. collections. generic; using System. linq; using System. text; namespace IMsg {// <summary> // This is the interface that the plug-in must implement and the only interface for communication between the main program and the plug-in. // In other words, the main program only recognizes these methods in the plug-in. // </summary> public interface IMsgPlug {void OnShowDlg (); string OnShowInfo ();}}
Using System; using System. collections. generic; using System. text; using IMsg; namespace MYPlugin1 {public class myConsole: IMsgPlug {# region IMsgPlug member public void OnShowDlg () {Console. writeLine ("OnShowDlg method for calling INS in the console");} public string OnShowInfo () {return "myConsole" ;}# endregion }}
Using System; using System. collections. generic; using System. text; using System. windows. forms; using IMsg; namespace MYPlugin1 {public class MYDlg: Form, IMsgPlug {# region IMsgPlug member public void OnShowDlg () {this. text = "ins subforms"; this. showDialog (); // call the ShowDialog of Form to display the Form} public string OnShowInfo () {return "MyDlg" ;}# endregion }}
Main and important code of the program
Using System; using System. collections. generic; using System. linq; using System. text; using System. windows; using System. windows. controls; using System. windows. data; using System. windows. documents; using System. windows. input; using System. windows. media; using System. windows. media. imaging; using System. windows. navigation; using System. windows. shapes; using System. collections; using System. IO; using System. reflecti On; namespace plug-in-type development {// <summary> // MainWindow. interaction logic of xaml // </summary> public partial class MainWindow: Window {// set of plug-ins for private ArrayList plugins = new ArrayList (); public MainWindow () {InitializeComponent () ;}/// <summary> /// load all plug-ins /// </summary> private void LoadAllPlugs () {// obtain the plug-in directory (plugins) all files under // string [] files = Directory. getFiles (Application. resourceAssembly + @ "\ plugins"); // str Ing str6 = AppDomain. currentDomain. setupInformation. applicationBase; // get the debug folder // str6 = System. diagnostics. process. getCurrentProcess (). mainModule. fileName; // obtain the exe file // str6 = System. environment. currentDirectory; // get the debug folder // str6 = System. IO. directory. getCurrentDirectory (); // get the debug folder // str6 = System. appDomain. currentDomain. baseDirectory; // get the debug folder // str6 = System. appDomain. currentDo Main. setupInformation. applicationBase; // get the debug folder // str6 = System. windows. forms. application. startupPath; // get the debug folder // string [] files = Directory. getFiles (AppDomain. currentDomain + "plugins"); string [] files = Directory. getFiles (@ "E: \ exercise code \ IMsg \ plug-in-type development \ plugins"); // obtain the path of the dll file foreach (string file in files) {if (file. toUpper (). endsWith (". DLL ") // if the file ends with dll {try {// load dll Assembly AB = Assembly. LoadFrom (file); // Type [] types = AB. getTypes (); // Type array foreach (Type t in types) {// if some classes implement predefined IMsg. the IMsgPlug interface is considered to be compatible with the main program (the main program plug-in) if (t. getInterface ("IMsgPlug ")! = Null) {plugins. add (AB. createInstance (t. fullName); // Add the instantiated dll to the lstWays in the generic set. items. add (t. fullName); // displayed in listbox} catch (Exception ex) {MessageBox. show (ex. message) ;}}}// form loading event private void Window_Loaded (object sender, RoutedEventArgs e) {LoadAllPlugs ();} // call the plug-in method private void btnGetIn_Click (object sender, RoutedEventArgs e) {if (this. lstWays. selectedIndex =-1) return; object selObj = this. plugins [this. lstWays. selectedIndex]; Type t = selObj. getType (); MethodInfo OnShowDlg = t. getMethod ("OnShowDlg"); // obtain the method MethodInfo OnShowInfo = t in the dll file. getMethod ("OnShowInfo"); // obtain the OnShowDlg method in the dll file. invoke (selObj, null); // method call parameter object returnValue = OnShowInfo. invoke (selObj, null );}}}
Iv. Postscript

When talking about plug-ins, we first think of firefox. Anyone who has used firefox knows that it is a plug-in program. When a function is required, you can download a plug-in from the Internet and restart it. This feature brings us a lot of convenience, which is the benefit of plug-in programs.
The essence of the plug-in is to expand and strengthen the software functions without modifying the program entity (Platform). When the plug-in interface is published, any company or individual can create their own plug-ins to solve some operational inconvenience or add new features, that is, to truly implement "plug-and-play" software development.
The Platform + plug-in software structure divides a target software to be developed into two parts: the main body or framework of the software, which can be defined as a platform. This is a pre-compiled program. The other part is a function or supplementary module, which can be defined as a plug-in. This is the plug-in program to be installed later.
Assume that your program has been deployed on your computer and runs properly. But one day, the user calls-they need to add new features. After determining the user's requirements, you can find that the original software architecture is no longer qualified for new tasks-you need to redesign this application! But the problem is that even if you use another development cycle to complete the applications required by the user, there is no guarantee that the user's requirements will not change again. That is to say, the possibility of spreading demand still exists. Therefore, the plug-in architecture can better demonstrate its superiority in this case.
It can be said that it can bring convenience, and it is also very easy to develop. In addition, such a main program does not need to be modified at all. You can use the plug-in when you need it. When the plug-in is updated, you only need to update the plug-in.
From the perspective of program development, it is generally to first develop the main program, decide which functions are completed by the main program, and then create an interface to declare the interface content, these contents determine the extension and direction of the plug-in functions. These are pre-prepared by the main program developers. The plug-in developer obtains the interface content from the main program developer, and writes classes that inherit these interfaces to complete specific functions.


Where is the Repository project development (Repository mode) course sharing based on aspnet wpf technology and MVP mode?

This course is divided into five parts: 1. use ADO. NET to Operate Excel table 2. Using WPF special effects and animation technology to build a superb Interface 3. Using WPF controls for Data Binding 4. Using Repository mode, MVP and MVVM frameworks to build a system architecture 5. IOC injection objects. Course outline: 1st: project requirement analysis 2nd Lecture: Project Database File design 3rd Lecture: Data File Access Technology for Construction Projects-excel operation technology 4th Lecture: Project multi-layer architecture design 5th Lecture: build a project's data file access layer 1-IDAL 6th lecture: Build a project's data file access layer 2-reflection 7th lecture: Build a project's data file access Layer 3-Repository mode 8th Lecture: model layer 9th of project construction: Project Interface Structure Design Technology 1-layout painter 10th: Project Interface Structure Design Technology 2-resource use 11th: project UI Structure Design Technology 3-animation 12th Lecture: Project login implementation 13th Lecture: MVP mode login 14th Lecture: Project dialog box implementation 15th Lecture: Project main interface implementation 16th Lecture: project main interface implementation-use Viewport2DVisual3D control 17th Lecture: customer Basic Information Management Module-add and query 18th Lecture: Customer Basic Information Management Module-menu, modify, delete 19th Lecture: MVVM mode for customer query 20th Lecture: Customer Financial Information Management Module 21st Lecture: Customer insurance record information management module 22nd Lecture: customer Family Information Management Module 23rd Lecture: Visiting customer record module 24th Lecture: IOC framework Autofac 25th: Project Development Summary

Does vs2008 need to install sdks and WPF plug-ins? Is it integrated?

The sdk must be installed in some special libraries.
WPF is no longer needed
Because Vs2008 has completely installed WPF

There is also the current Vs2008, the development of SL and F # is not complete, other can

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.