Smart client (SmartClient)
This paper mainly discusses the client application model based on the enterprise environment. Since I have worked in the development of the traditional client / server two-layer structure application and the development of multi-layer structural applications based on the .NET platform, this article will focus on .NET A smart client application model on the platform, and a more complete client software framework is constructed step by step according to the needs of the general enterprise application system.
Introduction The concept of smart clients is proposed as a characteristic of the Microsoft.Net platform. In fact, its many features already existed in traditional applications, just .NET platform provides support from system and language levels, making development intelligent customers End application is more convenient. This article will discuss the functions and features of the intelligent client from the perspective of the enterprise application system and how to implement it on the .NET platform.
Overview 1. The current client application model compares the current client application model is roughly divided into two: C / S (Client / Server Model) and B / S (Browser / Server Model). Software developers based on corporate environments, how to go to the browser-based thin client (Thin Client) application model, and how to go between the corresponding rich client (RICH Client), faced Difficult generation replacement. The advantages and disadvantages of browser-based applications:
Easy to install: You can be used in many tablets and have nothing to do with the operation platform of the client algorometer. Most computers have been installed by default (some application systems need IE, or need to install Java virtual machines, which is temporary and neglected). Easy to deploy and maintenance: just need to deploy and maintain on the server side. You must work online: work efficiency and network delay is related. The resources of the client computer cannot be fully utilized: can only render the user interface through a limited HTML language, and there is no use of the client computer's calculation processing power. You can only print the information using the browser's printing function, not applicable to the company's report printing. The network transmission is large: Since the client cannot save status data, the user interface content must be transmitted between the client and the server and the required data. The security is low. For the server, you can filter data through firewall software because all transfer content is based on HTTP ports. However, it is difficult to encrypt and sign the data to ensure integrity during transmission. (HTTPS does not seem to solve the problem) Applications suitable for e-commerce or do not require strict control of the client.
Frequently and disadvantages of rich client applications:
You can work offline: Prerequisites the ability to have cache data locally, which involves synchronization with server data. Take advantage of the resources of the client computer: You can provide users with a wealth of interface elements, you can access the native disks with the native application interface (API), and the speed is faster. The network transmission is small: just transfer data between the client and the server. The security is high. It can be convenient to perform encryption and decryption operations on the client and servers, and can also eliminate traditional applications such as firewalls and HTTP obstacles through Web Service. The installation, deployment and maintenance work is more cumbersome: there is a certain limit and requirements for the client computer on the operational platform and additional software. Suitable for enterprise internal applications.
Currently, there is another browser-based thin client application. They are provided to users through technology and tools such as Microsoft Terminal Server, Citrix System's Independent Computing Architecture and MetaFrame products. These types of solutions allow users to use the experience of fat clients and managed by centralized software installation and maintenance, which is very cost-effective to the company. The problem with this mode is that when the application is not connected to the application server, the user cannot be used. The client does not perform real processing, processing completely relying on the application server, which causes server performance issues and consumes the CPU cycle of desktop computers. In short, relative to rich clients, browser-based models is a great model for information technology (IT) system administrators, but there are many shortcomings for developers and users. Microsoft .NET Framework will meet the needs of these triples. Its intelligent client application model combines the powerful functionality and flexibility of rich client models, as well as easy deployment and stability based on browser-based models. 2, other functions that the client application should also have for the enterprise application system, the client application as the interactive interface of the entire system and the user, but also considers the following functions: security: The security here is mainly the application level Security, mainly through user permissions, role assignments. For client applications, a login form or login page is usually required to complete user identity. Applications with higher security requirements may also need to provide reliable security services for applications through public key infrastructure (PKI), and clients attach an encrypted signature module. Scalability: Client applications should have the ability to include a variety of different types of application modules, while also improving the entire system in the continuous increase in use during use. Therefore, the client application can be designed as a container, and each application module is dynamically loaded by the container as components. Configurability: Due to user permissions and user preferences, the client-loaded application components and presentations are different from person. It is necessary to pass the application system to the client, and the user's personalized configuration information is required to interpret and present the corresponding user interface.
In summary, we define the next general definition of the smart client application model: an extensible desktop application that integrates different applications, and has the following features:
None contact deployment: When installing, just download a main program file to the local, running directly, no need to change the registry or shared system component, other application components will be automatically downloaded at the first runtime. Automatic update: Simply publish the new version of the program on the server, automatically discover the latest version of the program and application components by the client, and automatically download and update. Application Offline: Allows the server to work with local client programs and application components. Dynamically loaded application components: Application software developers can develop according to the public interface of the enterprise application system, then publish the application component on the enterprise server, and the client application will automatically discover and load the application component. Personalized user interface: Users can set the client application according to the preferences, and the configuration information will be saved to the server.
Here we will describe the above features as an example to be described in detail with the .NET platform WinForms application.
.NET platform WinForms application example 1. System requirements 1, client software requirements
Any operating system that supports .NET Framework has installed SP1 .NET Framework Internet Explorer 5.0.1 or later
2, server software requires automatic release, update server: Microsoft .NET Framework, MDAC2.7, IIS
Second, the operation mode client application has two ways of operation. Different running methods will directly affect the subsequent assembly publish and updates. The following will explain the detailed explanation: 1. Network run .NET Framework installation provides a mount Internet Explorer 5.01 And higher versions to listen to the mechanism of the requested .NET assembly. During the request, the executable is downloaded to the disk called an assembly download cache (Windows2000 is: c: / documents and settings / administrator / local settings / application data / assembly in a subdirectories), The assembly itself and other related assemblies it references are also downloaded to the local IE cache (Windows2000 is: C: / Documents and Settings / Administrator / local settings / temporary Internet files). Then, the process named IEEXEC starts the application in an environment with limited security settings. For example: You can enter a .NET executable (http: //smartclient/myApplication.exe) published on the web server in the address bar of IE, IE does not prompt you as much as other files, and It is directly executed. In this way, the application runs with very limited security settings (INTERNET Rights Set), the permissions in this permissions include: Security, File dialog, print, independent storage file, user interface. Independent storage files allow your application to save some data (Windows2000 is: c: / documents and settings / administrator.tomato / local settings / application data / ISOLATEDSTINGS / Application Data / ISOLATEDSTINGS / Application Data / ISOLATEDSTINGER), the default storage space is 10MB), you You can save the data through the class in the system.io.isolatedStorage namespace without thriving. Example: // by user, domain, assemblies get isolated storage IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null); // create a directory isoStore.CreateDirectory ( "TestDir" ); // file IsolatedStorageFileStream isoStream1 = new IsolatedStorageFileStream create ( "TestDir // test.txt", FileMode.Create, isoStore); // write to file StreamWriter writer = null; writer = new StreamWriter (isoStream1); writer.WriteLine ( "Hello isolated"); Writer.close (); isostream1.close (); In order to make your smart application to run, you need to change some client security settings, essentially to notify the client runtime to believe your app . One way is to add a site with your assembly to the IE to trust the Site list, and then use the Microsoft .NET Framework Configuration tool installed in your management tool directory to modify the .NET Framework security settings.
Open the Framework Configuration tool, select Run Launch Security Policy, then select Adjust the security zone. For all sites specified in the trusted site, adjust the trust level to full trust. As a choice, you can also use the Framework Configurative tool to modify the security policy so that it trusts the individual assembly of your application. Right-click Run Launch Security Policy to select the level of trust in the assembly. Another optional method is to use the code group to help you improve the security settings of the application's assembly with the Framework Configuration tool. You need to make this change in desktop users using your application. To help complete this task, the Framework Configuration Tool can create a Microsoft Installer (MSI) deployment package that contains security policies. The MSI has installed the application loader to distribute the security policies and loader assembly you need for your application. Right-click Run Launch Security Policy to select Create a deployment package. In the network run, the automatic update is done with the Cache mechanism of IE. That is, when you need to download and run an application, IE sends an HTTP request to the web server. The request will get the latest update date of the program on the server, if the date is greater than the date of the local cache or the local cache If you exist, you download it from the server, otherwise the program directly uses the local cache. Therefore, for the version mechanism of the .NET itself, it cannot be used as a version update. Only when an assembly file is referenced to another assembly, it will determine the version number according to its own version of the machine. Note: This way of operation usually needs to set the security policy before running. When loading the application component, a complete URL address is required. If the application set needs to call the Web Service, the server address where the Web Service can only download the assembly, which can construct a redirection to resolve this issue. Some files may not be able to complete the version update by an automatic update mechanism, such as the configuration file for .config applications. If there is some correlation between the versions of some application set files, in some cases, in some cases (such as the network suddenly interrupted) may appear correctly to properly load and lead to an error in client applications. If the user clears the cache of IE, the client application will not be able to work offline.
2. Local run as the name suggests, this running method client application and other application components are not running in IE cache and .NET download cache, requiring users to download client assemblies and save them into a local directory and run. This client application and other application components have all local security privileges. Although not involving security issues, how does the application component and the automatic update of the program are implemented? This requires a separate component to complete these tasks. With this link address, you can download a very well-supported extensive automatic update component (http://www.gotdotnet.com/team/windowsformDater.zip), which provides source code, some examples, and documentation in this package file. This update component uses HTTP-DAV technology to complete the transfer between files and clients, so there is a certain limit on the web server, IIS5.0 and new version of Apache support this feature. For details, see the contents of the documentation. Precautions:
Since you need to implement your update and download, you will increase a certain amount of work. (That is to use third-party update components, it also needs to be improved to meet your own requirements) basically solve the shortcomings of network operation, but you need to re-download all files every time you update (if you use incremental updates, somewhere In the case, a version of the file is missing will appear), which will increase the network traffic. Updates and downloads should be performed in the background thread without affecting the user's normal operation. Third, create a program client application to perform steps:
log in system. You usually require a login form by entering the username and password or any other way. (This step requires the client application to execute online online, so you can consider providing a button that is offline on the form, and then directly uses the configuration file copy of the server when the last online login is used. This will trigger some security issues and Client data and server data synchronization issues.) After the application server verification, obtain the user's application component and its corresponding configuration information according to the user rights set by the system, and obtain the personalized configuration information of the user from the database. , Combine these configuration information into an XML configuration file stream to pass to the client application. This step is usually performed by a web service call. The client program parsed the configuration file stream, sets the main format according to the personalized configuration information, load the corresponding assembly file according to the application component configuration information. Save the configuration file to use it when you work from the line. (Local Operation Mode) Start the background update thread, the line is scheduled to search the update server has the latest version of the program, if there is, download and prompt the user update. The user interface to which the application component itself will be displayed in the client main form by clicking the button or menu of the appropriate application component.
The client application basically includes a login form, a main form, and an application component loader. There is an application component set class in the loader, and some methods are provided for communication between the main program and application components and between different application components, and some application components provide data as a public component to other applications, so it should pass Unified methods to get data. Precautions and recommendations: 1. For network operation mode, the program set is downloaded from the server to the local cache, while the download process of the local operation mode is executed by the update component, and the client main form is executed. Method for dynamically loaded an assembly in .NET: use system.reflection; // Network running mode, loaded assembly path to the URL address on the server AssemblyFileName = "http: //smartclient/appcomponent1.dll"; // Local Operation, loaded assembly paths are local directory path assemblyFileName = @ "c: /smartclient/appcomponent1.dll"; askLL "; assembly asm = askMBLY.LOADFROM (askMBLYFILENAME); 2, client application mainfield as an application component The container can display the user interface of the application component by two methods: The first way is to design the client application as a multi-document interface (MDI) application, each application component contains respective start-up main forms. When the client application executes each application component, the startup form type of the component will be constructed and displayed. The "Window" menu item containing the submenu is often switched between the main window or application. Another way is to reserve an application interface area in the primary window interface of the client application, and each application component is added to the control array of the application interface area as a user control. Application interface area is typically a panel (PANE) control, switches between the various applications by changing the Z order of the user control (Control. Bringtofront ()). 3. When the client application loads the appropriate application components based on the configuration information, you need to create the corresponding button and menu item on the toolbar or menu of the client main form, and add events to facilitate user operation. The client application and application components should be kept independent, reducing the association to reflect the client application structure clear and simple. This can be achieved through the callback (event delegate) in .NET. 4, .NET Due to the cause of the cache, the following problem occurs when the assembly is loaded: // Load assembly asm = askMBLY.LOADFROM (@ "c: /smartclient/appcomponent1.dll"; activator.createInstanceFrom (ASM) .Gettype ("AppComponent1.mainform"); // Loading a file name in different directories in different directories, different assemblies assembli, assembly, assembly, assembly, assembly, assembly, Assembly asmbly.loadFrom (@ "c: /test/appcomponent1.dll) Activator.createInstanceFrom (ASM.GETTYPE ("AppComponent1.mainform"); After the second load, there is no correctly constructed the form type in different directories, but used the first time in the cache. The type of constructor is loaded. In order to solve the above problems, these two types instance must be constructed in different application domains (Domain).
// Load a file name in different directories, the same content is the same, but the contents of the content, appdomain newdomain = Appdomain.createDomain ("newdomain"); newdomain.createInstanceFromandUnwrap (@ "c: /test/appcomponent1.dll", "appcomponent1 .Mainform "); Take note when using this method, if you constructed the type instance contains a parameter constructor, these parameter objects must be an object accessed across the application domain, ie a sequentially sequenceable object. You can set the survival policy of the remote object by inheriting the MarshalByrefObject object or using the [Serializable] feature tag class. Example: public class ParameterClass: MarshalByRefObject {public override Object InitializeLifetimeService () {// ILease lease lifetime lease objects defined remoting lifetime service used = (ILease) base.InitializeLifetimeService (); if (lease.CurrentState == LeaseState .Initial) {// Set the initial time of the lease. The lease will never expire, and the object associated with an infinite survival. Lease.initialLeasetime = Timespan.zero;}}} 4, Publisher 1. Set a virtual directory on the publish and update server (such as: smartclient) to place all files of the application component in the appropriate directory. Setting attributes in the virtual directory must include: read and directory browsing permissions, and execute the license as pure script. For local mode, you need to set multiple directories based on the version number of the client application, and all files of different versions are stored. (You can also store only updated files in the new version of the directory, but you need to modify the update component. When the user updates the version, you must download the files larger than all new version of the current version to prevent some cases. A version of the file is missing questions). In the local mode of operation, you will also need to maintain a newer list file in the root directory because it allows users to log in with an old version of the client application. 2, release a web service. The web service mainly completes the following tasks: Performing client users authentication from the security module of the entire application system allows the user to perform the list of application components, including the location of the application component, file name, and application components itself. information. (In the local mode of operation, the list is also related to the version) Get the user's personalized configuration information from the database, and the information obtained by the previous step is combined into an XML file stream. The configuration file stream is returned to the client application as the return parameter.
3. Place the client application in the virtual root directory as the loader of the application component assembly, and add a link to the client application on the enterprise internal website. For network operation, a link to the Security Policy Deployment Package (MSI) file will also be provided. User's first running steps network operation mode:
Download and Install the Security Policy Deployment Package by clicking on the link of the client application, download and execute the client application to your favorites or create a desktop shortcut to facilitate operation
Local Operation:
Do not directly click on the link to the client application, save this link to the user-selected directory to execute the client application in the resource manager to create a shortcut to the executable file in the desktop, so that you can run the five, update the program network operation The update step of the way is simpler, and only the updated file can be overwritten directly to the old file. Its disadvantage is that the reference files included with some assessments cannot be automatically downloaded new versions, and only updates can be implemented after emptying the client's IE cache. The update steps for local running methods are as follows:
In the server virtual root directory, create a directory named by the new version number, incremental updates simply copy the updated file to the directory, otherwise you need to copy all files to the directory. Modify the file that holds all versions of the list and indicates the latest version number of the current activity, and is used to make a version comparison with the client.
6. Extended application components In order to implement the scalability of enterprise application systems, through interface definitions, the application developers can make them easily add their application components to the client application by implementing these interfaces. The following describes the mainly included methods and properties in some interfaces.
Application Component Name Properties: Annotation Text for indicating the function of the application component. Application Components on the client application Each interface element property: refers to the toolbar, menu bar, drop-down menu item and list box, etc. on the client application, which requires the text provided by the application component. , Pictures, icons, menus, event processing methods, etc. Initialization: The method of executing when the client application loads the application component. When loading the application assembly, for the configuration information of each application component itself included by the configuration file, the client application is not parsed, but the configuration information is passed to the application component when initializing the application components. Increase flexibility. Get Application Component Loader Method: After obtaining the application component loader, you can get some of the shared data required by the application in which the public method included. Get the application component startup control: The startup control can be a form or user control. Close the method of the application component (optional): When the client application is turned off, the method is executed. The application component itself determines whether it can be turned off according to its own situation, and immediately release the system resources occupied by the component.