博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

How To: Use SC-SF with Enterprise Library 4(转)

Posted on 2008-05-18 16:11  江南白衣  阅读(944)  评论(0编辑  收藏  举报

原文:http://www.codeplex.com/smartclient/Wiki/View.aspx?title=HowTo%20SC-SF%20EntLib4&referringTitle=Others

Prerequisites

The procedures described in this document assume that you have installed the Smart Client Software Factory April 2008 and Enterprise Library 4.

Summary of Steps

  1. Rebuilding the Block Assemblies
  2. Updating the Guidance Package
  3. Updating Existing Smart Client Solutions
  4. Updating the QuickStarts and Reference Implementation (optional)
Note: If you want to use Enterprise Library 4.0 on new projects, you only need to perform steps 1 and 2.

Rebuilding the Block Assemblies

The first step consists of rebuilding the Smart Client Software Factory blocks to use Enterprise Library 4.0. These steps are needed only if you are updating an existing Smart Client Software Factory solution that uses the Offline capabilities or if you are going to customize the Guidance Package to make it generate new solutions that use Enterprise Library 4.0.
  • 1. Extract the Smart Client Software Factory Source Code.
  • 2. Open the SmartClient.Offline solution located at the source code installation folder.
  • 3. Remove from the SmartClient.EnterpriseLibrary and SmartClient.EnterpriseLibrary.Tests projects the references to the following assemblies:
    • Microsoft.Practices.EnterpriseLibrary.Common
    • Microsoft.Practices.EnterpriseLibrary.Data
    • SmartClient.EnterpriseLibrary.Data.SqlCe
  • 4. Add, In the SmartClient.EnterpriseLibrary and SmartClient.EnterpriseLibrary.Tests projects, references to the following Enterprise Library assemblies (located at Enterprise Library assemblies located at %Enterprise Library 4 installation folder%\Bin):
    • Microsoft.Practices.EnterpriseLibrary.Common.dll
    • Microsoft.Practices.EnterpriseLibrary.Data.dll
    • Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.dll
  • 5. In the SmartClient.EnterpriseLibrary project, open SmartClientDatabase.cs file and replace the following using statement:
using Microsoft.Practices.SmartClient.EnterpriseLibrary.Data.SqlCe;
  • With this:
using Microsoft.Practices.EnterpriseLibrary.Data.SqlCe;
  • 6. Build the solution.
Note: Since Enterprise Library 4 already includes a provider for Sql CE 3.5, SmartClient.EnterpriseLibrary project no longer needs to use the custom provider included in the SmartClient.EnterpriseLibrary.Data.SqlCe assembly. In the previous steps, the SmartClient.EnterpriseLibrary project was modified to work with the new provider supplied by Enterprise Library 4.

Updating the Guidance Package

The following steps describe how to customize the Guidance Package to make it generate solutions that use Enterprise Library 4.0.
  • 1. Follow the steps described in the section Rebuilding the Block Assemblies.
  • 2. Open the GuidancePackage solution located at the SC-SF source folder.
  • 3. Open the App.config.template located under the folders located at Templates\Solutions\Projects\Shell.*.* (Shell.Basic.CS, Shell.Basic.VB, Shell.Extended.CS and Shell.Extended.VB) in the SmartClientFactoryPackage project.
  • 4. Find and replace on each App.config.template file the string “Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” with “Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”.
  • 5. Create a folder to store the new assemblies (e.g. at %SC-SF installation folder%\Lib with EntLib 4.0). In this folder, copy the Enterprise Library 4.0 assemblies and the Smart Client assemblies generated in Step 1. You should have the same assemblies you have at %SC-SF installation folder%\Lib but updated to use Enterprise Library 4.0.
  • 6. Open the file CreateSmartClientFactorySolutionCommon.xml file located at Recipes\Common folder of the SmartClientFactoryPackage project. You will change the path where the Create Solution recipe looks for the required assemblies by default.
  • 7. Find the SupportLibrariesPath argument and replace it with the following:
<Argument Name="SupportLibrariesPath" Required="true" Type="System.String">
<ValueProvider Type="Evaluator"
Expression="
</ValueProvider>
</Argument>
  • 8. Save all.
  • 9. Register the custom Guidance Package. To do this, right click the SmartClientFactoryPackage project and select Register Guidance Package.
Note: If the Register Guidance Package doesn’t appear, you have to enable Guidance Package Development. To do this, go to the Tools menu, select Guidance Package Manager, click Enable / Disable packages, select Guidance Package Development, click OK, and Close.

Updating an Existing Smart Client Solution

The following steps describe how to make an existing Smart Client Software Factory solution consume Enterprise Library 4.0.
  • 1. If your solution uses the Microsoft.Practices.SmartClient.EnterpriseLibrary.dll assembly, follow the steps described in the Rebuilding the Block Assemblies section to update this assembly and perform the following sub-steps:
    1. Find the Microsoft.Practices.SmartClient.EnterpriseLibrary.dll generated assembly located at %Source code installation folder%\Blocks\Offline\Source\DataAccess.EnterpriseLibrary\bin\Debug.
    2. Copy the previous assembly and replace them in the Lib folder of your solution.
    3. Update the references of your projects to use the updated Microsoft.Practices.SmartClient.EnterpriseLibrary.dll assembly
    4. Remove the reference to Microsoft.Practices.SmartClient.EnterpriseLibrary.Data.SqlCe.dll**(it was replaced with the one provided by Enterprise Library 4) and add a reference to Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.dll assembly located at %Enterprise Library 4 installation folder%\Bin.
  • 2. Copy the Enterprise Library 4.0 assemblies (located at %Enterprise Library 4 installation folder%\Bin) and replace them in the Lib folder of your solution.
  • 3. Update the references to the Enterprise Library assemblies in all the projects in your solution using the new assemblies copied into the Lib folder.
  • 4. Open the App.config file and find and replace the string “Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”__with “Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”.
  • 5. Save all.
Note: It is possible that you’ll get exceptions related to changes in the new version of the Enterprise Library. Use the Enterprise Library Changes Log to review the changes and update your code.

Updating the QuickStarts and Reference Implementation

If you want to update the QuickStarts and the Reference Implementation to use Enteprise Library 4.0, you can follow the steps described in the section Updating an Existing Smart Client Solution.

NOTE:    
    Before I get into this, I do want to applaud the team for coming up with these instructions.  It took good, hard work, investigation, experimentation, and testing to get this figured out.  It is important that users and customers have the option to upgrade to Enterprise Library 4, if they choose to.

With the release of these instructions, I feel that I owe it to you (our customers and users of SCSF) to ask you to consider "do you really need to upgrade?"  Sure EntLib 4 has a bunch of fantastic new features, is built on Unity (which rocks), and has some bug fixes.  However, there are complications that will come up with the upgrade at an architectural level that you need to consider.  Since these instructions do not include rewriting SCSF to use Unity, there will be two completely different and separate containers available.  From the stand point of code/dll bloat, separation of concerns, and learning curve this is a bad thing.  Myself, I would wonder "Which container should I use?"  for different types of things.  On one hand, the Unity container is great, fast, and the API is simple.  On the other hand, the framework that you are building on does not use this new container, and will not have knowledge of it nor access to it. There is also now a ton of duplicate code that you will need to ship (OB and OB2, CAB and Unity).  Do you mind shipping 2 pairs of dlls that do effectively the same thing?  How do you have your team use the two containers?  Is it worth it to do a re-write?  Is it worth figuring this all out so you can use EntLib 4 on your project?  If so, then by all means do so.  If not, then consider carefully before upgrading.

Michael Puleio - patterns & practices
Blog - http://blogs.msdn.com/mpuleio