MSDN Magazine - July 2008 - (Page 22) Writing the Add-In Once the pipeline is in place, I can write add-ins against the addin view. Writing the add-in is as simple as possible. All an add-in developer needs to do is to create a class that inherits from the addin view, and mark the add-in implementation with the AddIn attribute. The rest of the code can be written almost as if there were no pipeline between the host and the add-in. There are a couple of caveats, however. One is the object identity issue I discussed earlier, and the second is performance, depending on what isolation boundary is used. For performance benchmarks, see go.microsoft.com/ fwlink/?LinkId=117527. Currently, add-ins cannot directly display Windows Forms controls on the host application’s forms. However, they can use any of the following three methods: they can display their own forms (note that if the add-in is running in some partial trust scenarios— like the Internet trust level—the user will see a security warning on the add-in form when it is loaded); they can display Windows Presentation Foundation (WPF) controls directly on the host application’s forms (please see go.microsoft.com/fwlink/?LinkId=117528); and they can use Windows Forms controls that are wrapped in WPF containers (see go.microsoft.com/fwlink/?LinkId=117529). Windows Forms have some threading requirements that must be met. For example, an add-in extending a command-line application must create a new thread to construct a form and process its events. This is because command-line applications use the multithreaded apartment (MTA) model by default, and Windows Forms require the single-threaded apartment (STA) model for UI threads. The solution is simple: add-ins extending a Windows Forms application can just include two lines to display forms (given the add-in is activated and used from the host’s UI thread), like so: AddInForm form = new AddInForm(); form.Show(); Figure 9 Path Taken by an Event through the Collaboration Add-In Figure 10 Three Instances of the ShapeApp Connected Together Using the exposed interface, one can create really powerful addins. One example is the collaboration add-in included with this sample. It allows two users of the ShapeApp using two different machines to edit a drawing together in real time. The collaboration add-ins connect to each other through Windows Communication Foundation (WCF), allowing this interaction to work globally over the Internet. A screenshot of the connect screen can be seen in Figure 8. Once two add-ins are connected to each other, any new documents created or opened on either end are shared; that is, changes on one machine are sent in real time to the other. This is accomplished using events. When the collaboration add-in is loaded, it subscribes to all the application’s events. When a new drawing is created, the CreatedDrawing event is fired. The add-in receives this event and subscribes to all events for the new drawing. Similarly, it subscribes to all shape-related events when shapes are created. This allows the add-in to track all user actions and propagate them over to its peer. Figure 9 shows the path taken by an event through the collaboration add-in. On Machine 1, the user performs an action (such 22 msdn magazine The Collaboration Add-In as changing the position of a shape). This makes the host fire an event, and the collaboration add-in receives it. The collaboration add-in creates a message and sends it through WCF to the add-in on Machine 2. This add-in then performs the same action on the host. Note that it temporarily unhooks event handlers when performing actions on the host. This prevents the event from coming back to the add-in, which would result in an infinite cycle. More interesting scenarios are made possible by using WCF. Since the collaboration add-in hosts a service, any number of clients can connect to it. This allows more than two people to work on a drawing together, seamlessly. Figure 10 shows the connections among three machines. The collaboration add-in on each machine is connected to all the others. Wrap-Up Now you’ve seen how the ShapeApp is adapted to host addins using the .NET add-in framework. You should have a good idea of the capabilities of the add-in framework and how it can be used to create an add-in that seamlessly turns the ShapeApp into a real-time collaborative editor. Please feel free to leave feedback or ask questions on the Add-In Team Blog at go.microsoft.com/ fwlink/?LinkId=117530. Mueez Siddiqui is a Software Development Engineer in the CLR security and extensibility team at Microsoft. CLR Inside Out http://go.microsoft.com/fwlink/?LinkId=117527 http://go.microsoft.com/fwlink/?LinkId=117527 http://go.microsoft.com/fwlink/?LinkId=117528 http://go.microsoft.com/fwlink/?LinkId=117529 http://go.microsoft.com/fwlink/?LinkId=117530 http://go.microsoft.com/fwlink/?LinkId=117530
Table of Contents Feed for the Digital Edition of MSDN Magazine - July 2008 MSDN Magazine - July 2008 Contents Toolbox CLR Inside Out Flex Your Data Data Points Advanced Basics Office Space Cutting Edge Data Services ADO.NET Data and WPF Transactions WCF P2P Test Run Security Briefs Foundations .NET Matters {End Bracket} MSDN Magazine - July 2008 MSDN Magazine - July 2008 - (Page Intro) MSDN Magazine - July 2008 - Contents (Page Cover1) MSDN Magazine - July 2008 - Contents (Page Cover2) MSDN Magazine - July 2008 - Contents (Page 1) MSDN Magazine - July 2008 - Contents (Page 2) MSDN Magazine - July 2008 - Contents (Page 3) MSDN Magazine - July 2008 - Contents (Page 4) MSDN Magazine - July 2008 - Contents (Page 5) MSDN Magazine - July 2008 - Contents (Page 6) MSDN Magazine - July 2008 - Contents (Page 7) MSDN Magazine - July 2008 - Contents (Page 8) MSDN Magazine - July 2008 - Contents (Page 9) MSDN Magazine - July 2008 - Contents (Page 10) MSDN Magazine - July 2008 - Toolbox (Page 11) MSDN Magazine - July 2008 - Toolbox (Page 12) MSDN Magazine - July 2008 - Toolbox (Page 13) MSDN Magazine - July 2008 - Toolbox (Page 14) MSDN Magazine - July 2008 - Toolbox (Page 15) MSDN Magazine - July 2008 - Toolbox (Page 16) MSDN Magazine - July 2008 - CLR Inside Out (Page 17) MSDN Magazine - July 2008 - CLR Inside Out (Page 18) MSDN Magazine - July 2008 - CLR Inside Out (Page 19) MSDN Magazine - July 2008 - CLR Inside Out (Page 20) MSDN Magazine - July 2008 - CLR Inside Out (Page 21) MSDN Magazine - July 2008 - CLR Inside Out (Page 22) MSDN Magazine - July 2008 - CLR Inside Out (Page 23) MSDN Magazine - July 2008 - CLR Inside Out (Page 24) MSDN Magazine - July 2008 - Data Points (Page 25) MSDN Magazine - July 2008 - Data Points (Page 26) MSDN Magazine - July 2008 - Data Points (Page 27) MSDN Magazine - July 2008 - Data Points (Page 28) MSDN Magazine - July 2008 - Data Points (Page 29) MSDN Magazine - July 2008 - Data Points (Page 30) MSDN Magazine - July 2008 - Data Points (Page 31) MSDN Magazine - July 2008 - Data Points (Page 32) MSDN Magazine - July 2008 - Data Points (Page 33) MSDN Magazine - July 2008 - Data Points (Page 34) MSDN Magazine - July 2008 - Advanced Basics (Page 35) MSDN Magazine - July 2008 - Advanced Basics (Page 36) MSDN Magazine - July 2008 - Advanced Basics (Page 37) MSDN Magazine - July 2008 - Advanced Basics (Page 38) MSDN Magazine - July 2008 - Advanced Basics (Page 39) MSDN Magazine - July 2008 - Advanced Basics (Page 40) MSDN Magazine - July 2008 - Advanced Basics (Page 41) MSDN Magazine - July 2008 - Advanced Basics (Page 42) MSDN Magazine - July 2008 - Office Space (Page 43) MSDN Magazine - July 2008 - Office Space (Page 44) MSDN Magazine - July 2008 - Office Space (Page 45) MSDN Magazine - July 2008 - Office Space (Page 46) MSDN Magazine - July 2008 - Office Space (Page 47) MSDN Magazine - July 2008 - Office Space (Page 48) MSDN Magazine - July 2008 - Office Space (Page 49) MSDN Magazine - July 2008 - Office Space (Page 50) MSDN Magazine - July 2008 - Cutting Edge (Page 51) MSDN Magazine - July 2008 - Cutting Edge (Page 52) MSDN Magazine - July 2008 - Cutting Edge (Page 53) MSDN Magazine - July 2008 - Cutting Edge (Page 54) MSDN Magazine - July 2008 - Cutting Edge (Page 55) MSDN Magazine - July 2008 - Cutting Edge (Page 56) MSDN Magazine - July 2008 - Cutting Edge (Page 57) MSDN Magazine - July 2008 - Data Services (Page 58) MSDN Magazine - July 2008 - Data Services (Page 59) MSDN Magazine - July 2008 - Data Services (Page 60) MSDN Magazine - July 2008 - Data Services (Page 61) MSDN Magazine - July 2008 - Data Services (Page 62) MSDN Magazine - July 2008 - Data Services (Page 63) MSDN Magazine - July 2008 - Data Services (Page 64) MSDN Magazine - July 2008 - Data Services (Page 65) MSDN Magazine - July 2008 - Data Services (Page 66) MSDN Magazine - July 2008 - Data Services (Page 67) MSDN Magazine - July 2008 - Data Services (Page 68) MSDN Magazine - July 2008 - Data Services (Page 69) MSDN Magazine - July 2008 - ADO.NET (Page 70) MSDN Magazine - July 2008 - ADO.NET (Page 71) MSDN Magazine - July 2008 - ADO.NET (Page 72) MSDN Magazine - July 2008 - ADO.NET (Page 73) MSDN Magazine - July 2008 - ADO.NET (Page 74) MSDN Magazine - July 2008 - ADO.NET (Page 75) MSDN Magazine - July 2008 - ADO.NET (Page 76) MSDN Magazine - July 2008 - ADO.NET (Page 77) MSDN Magazine - July 2008 - Data and WPF (Page 78) MSDN Magazine - July 2008 - Data and WPF (Page 79) MSDN Magazine - July 2008 - Data and WPF (Page 80) MSDN Magazine - July 2008 - Data and WPF (Page 81) MSDN Magazine - July 2008 - Data and WPF (Page 82) MSDN Magazine - July 2008 - Data and WPF (Page 83) MSDN Magazine - July 2008 - Data and WPF (Page 84) MSDN Magazine - July 2008 - Data and WPF (Page 85) MSDN Magazine - July 2008 - Data and WPF (Page 86) MSDN Magazine - July 2008 - Data and WPF (Page 87) MSDN Magazine - July 2008 - Data and WPF (Page 88) MSDN Magazine - July 2008 - Data and WPF (Page 89) MSDN Magazine - July 2008 - Data and WPF (Page 90) MSDN Magazine - July 2008 - Transactions (Page 91) MSDN Magazine - July 2008 - Transactions (Page 92) MSDN Magazine - July 2008 - Transactions (Page 93) MSDN Magazine - July 2008 - Transactions (Page 94) MSDN Magazine - July 2008 - Transactions (Page 95) MSDN Magazine - July 2008 - Transactions (Page 96) MSDN Magazine - July 2008 - Transactions (Page 97) MSDN Magazine - July 2008 - Transactions (Page 98) MSDN Magazine - July 2008 - Transactions (Page 99) MSDN Magazine - July 2008 - Transactions (Page 100) MSDN Magazine - July 2008 - Transactions (Page 101) MSDN Magazine - July 2008 - Transactions (Page 102) MSDN Magazine - July 2008 - Transactions (Page 103) MSDN Magazine - July 2008 - Transactions (Page 104) MSDN Magazine - July 2008 - WCF P2P (Page 105) MSDN Magazine - July 2008 - WCF P2P (Page 106) MSDN Magazine - July 2008 - WCF P2P (Page 107) MSDN Magazine - July 2008 - WCF P2P (Page 108) MSDN Magazine - July 2008 - WCF P2P (Page 109) MSDN Magazine - July 2008 - WCF P2P (Page 110) MSDN Magazine - July 2008 - Test Run (Page 111) MSDN Magazine - July 2008 - Test Run (Page 112) MSDN Magazine - July 2008 - Test Run (Page 113) MSDN Magazine - July 2008 - Test Run (Page 114) MSDN Magazine - July 2008 - Test Run (Page 115) MSDN Magazine - July 2008 - Test Run (Page 116) MSDN Magazine - July 2008 - Security Briefs (Page 117) MSDN Magazine - July 2008 - Security Briefs (Page 118) MSDN Magazine - July 2008 - Security Briefs (Page 119) MSDN Magazine - July 2008 - Security Briefs (Page 120) MSDN Magazine - July 2008 - Security Briefs (Page 121) MSDN Magazine - July 2008 - Security Briefs (Page 122) MSDN Magazine - July 2008 - Foundations (Page 123) MSDN Magazine - July 2008 - Foundations (Page 124) MSDN Magazine - July 2008 - Foundations (Page 125) MSDN Magazine - July 2008 - Foundations (Page 126) MSDN Magazine - July 2008 - Foundations (Page 127) MSDN Magazine - July 2008 - Foundations (Page 128) MSDN Magazine - July 2008 - Foundations (Page 129) MSDN Magazine - July 2008 - Foundations (Page 130) MSDN Magazine - July 2008 - .NET Matters (Page 131) MSDN Magazine - July 2008 - .NET Matters (Page 132) MSDN Magazine - July 2008 - .NET Matters (Page 133) MSDN Magazine - July 2008 - .NET Matters (Page 134) MSDN Magazine - July 2008 - .NET Matters (Page 135) MSDN Magazine - July 2008 - {End Bracket} (Page 136) MSDN Magazine - July 2008 - {End Bracket} (Page Cover3) MSDN Magazine - July 2008 - {End Bracket} (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.