.NET Framework gives an application a license (on)

zhaozj2021-02-11  177

.NET Framework gives the application a license

Http://www.codeguru.com/net_framework/licensedapps.html

Translation: Zou Jianqiang by kenn scribner

Translator Note: Perhaps some terms are inconsistent with you, then please refer to it; if some statement is wrong, please refer to it, thank you

If you are reading this article, there is no doubt that you are a developer of a Windows platform software. If you are a developer of Windows software, you write the software perhaps because you are full of passion over the software. I am happy to write code all day because I think this is a kind of enjoyment. I believe that you feel the same as me in many ways. This is perhaps a good way to live.

But this is something that can be encountered. If you don't consider the economic factors of writing software, we will encounter a simple and trial: when we work hard, we have to support the family, pay the dead bill, frankly, we still want the whole family Go out to a holiday. After all, many people who use our software may be the same as our attitude towards us, but people's views in daily life are unfair. They work and want to pay for their diligence work, and even the hearts of them love them and engage in things.

The problem is that when the end user gets the software, the software often has a unclear thing. All what they see is just the application itself, even, this program will only have a short time in computer memory when there is electricity. It seems that it is difficult to see that this is a product that spends hundreds of hours to develop tested products, or at least a physical intuitive thing such as a car and refrigerator. Straight, diligent computer users will never think of stealing a car or a electric refrigerator, but they will often exchange software with friends, and they even know that this is a licensing agreement with violations. But the software is just a digital to the CD, right, will it have to pass the software to a friend or brother?

Yes, you know what this answer is - the user doesn't pay for your efforts. According to commercial terms, you have no income. If you don't have enough income, as a merchant, you can't maintain your business. As an individual, you may not bear your financial expenditure (your payment bill). So you or to find a fast food chain, or announce bankrupt and live in the cardboard room under a highway bridge. As far as I said, I would rather believe that users will pay for the software, will pay for my design, development, testing, market propaganda, distribution software.

Solution is the software license license. As an industry, many people try to solve this problem in a variety of ways. In the past, software is a prevention medium (remember to be on a floppy disk with excess magnetic tracks. Translator Note: There are also people who have a bad area in the disk). The usual practice now is to ask you to type a string key to make the package normally used. Microsoft recently started the Internet-based online software authorization for their high-end operating systems and products (such as Office, which may be the most frequently pirated software). In .NET Framework, there is also such a technique, you can use it to issue your software authorization license, this is exactly what I want to show now.

Control license

Almost you read the .NET license everything is binding two licenses concepts. An control license concept, another idea is that the control license assembled by the control developer can be performed during design or during runtime. When license occurs, you can apply Framework Licensing to any class derived from System.Windows.Forms.Control, which contains the entire Windows Forms application, but I will start with the control itself. Figure 1 shows the basic control chart of the license UML static class.

Figure 1. License static class .NET control chart

In Figure 2 (a UML sequential chart) is a usual execution order. A license for license managers (License = licenseManager.validate (TypeOf (MylicensedControl), this);

In this case, the constructor is used for the control license and implemented in the MylicensedControl. The eye is that you may not need to do anything on your handle object itself (depending on your license implementation), in addition to properly arrange additional addresses. From this dark box, the important steps we take is to call, the license manager applies for a license. If the license is not received by some reason, Validate () calls will throw a failure, if the exception wants to be. Conversely, if an abnormality is suppressed, an empty license is returned. (LicenseProvider.getlicense () control calls, and the default Framework implementation allows exceptions.)

Figure 2. Control license order

The license manager calls the GetLicense () method of the control license provider. License managers, one .NET Framework component, how is the license provider used? After all, you have provided license providers ... The answer is metadata in the traditional .NET method, through the properties:

[LicenseProvider (TypeOf (MylicenseProvider)]]

Public class mylicensedControl: system.windows.forms.control

{

...

}

The license manager will find the licenseProvider property of the attached license control class. Since the licenseProvider property puts the type of license provider when the type of constructor is used, the license manager can shoot this information when the license manager is required to verify this license. Your license provider must derive self-class LicenseProvider, you must overload getLicense (), this is a method (Mustoverride for VB users):

Public Class MylicenseProvider:

System.componentmodel.licenseProvider

{

...

Public Override license getLicense

LicenseContext context,

Type Type,

Object Instance,

Bool allowexceptions)

{

...

}

}

In the .NET environment, the magic that allows authorized recognition constitutes the procedure I just described. But in the end, the real license magic is encoded in the getLinCense () method.

Before we are too much to imagine, you should understand that Microsoft uses frames to assemble a basic license provider called licfilelicenseProvider. I will completely describe how you use licfilelicenseProvider, and I also believe that anyone who sends their software licenses, which is likely to avoid such a simple solution, so that they are themselves. More constructive solutions, I will introduce one of them after describing LicfilelicenseProvider.

LicfilelicenseProvider

LicfilelicenseProvider is simple, it will check the existence of the license file. If the file exists, check if the file content is legal. This file may be saved on a disk with the program, or may be encoded into an application resource file, you need to write some code to read it. If the file exists and the content is legal, the license provider will issue a license to the license manager and eventually issued to this control. Otherwise, the license provider will throw a licenseException exception, and your control process will block and die. LicfilelicenseProvider Reserved getLicense () method, which is necessary, but also provides two additional virtual methods, iskeyvalid () and getKey (). Using licfilelicenseProvider, when implemented in the framework, getKey () is looking for a file in the execution directory of the assembly, the file name format is {full name} .lic, here {full name} is the full type name of the license control class The comparative representative format is {assembly name}. {Class name}. If the assembly MyControlAssembly declares that the license we have already used, the license file in this file will be named:

MyControlAssembly.mylicensedControl.lic

The iskeyvalid () method is compared with the contents of this file and string "{licensed class} is a licensed component." (Including a period). In the example, the file MyControlssembly.mylicensedControl.Lic accounted for this string "MyControl ISEMBLY.MYLICENSEDCONTROL IS A LICENSED Component." If this license file is lost, or the content is incorrect, the legitimacy check failed, and This control will not be instantiated. I've include the Downloadable Samples Solution AN Example That Has A licensed version of the MSDN Sample Color-Picker ComboBox Control. I have provided a downloadable sample solution, this example is the MSDN color pickup combination box control, this It is a licensed version.

Since IsKeyValid () and getKey () are virtual methods, you can easily derive a new class. This new class is presented in other places, or checks a different string (perhaps an encrypted string, or a string that simply uses different phrases). In any case, since the base class has declared such a function, a "good" method realize it still substantially handles these license files. If you would rather use a completely different way to implement a license program, a license provider derived directly from LicenseProvider is a good choice. Since I am very confident about everyone's IQ, I don't intend to provide an example of providing a derived license file provider. Instead, I will describe some optional license schemes.

转载请注明原文地址:https://www.9cbs.com/read-5935.html

New Post(0)