TX Text Control .NET for WPF

Application Licensing

Topic

Once a WPF application is built, its TX Text Control license is part of one of its assemblies. The people who install and run it need no serial number, no license file and no activation. What you decide as a developer is which assembly holds the license, which matters as soon as the TextControl lives in a user control library or ServerTextControl in a class library, and what stays out of the files you ship.

Where the License Lives

At build time, the license is compiled into your assembly: from txtextcontrol.wpf.license in .NET projects, and from licenses.licx in .NET Framework projects. Development Licenses covers both.

By default, TX Text Control checks the license in the application's executable assembly. That fits an application whose windows contain the controls directly. If TX Text Control is used in another assembly, such as a WPF user control library, a class library or a unit test project, the executable doesn't have the license, and TX Text Control has to be told where it is.

Applications built with TX Text Control .NET for WPF are royalty-free: you may distribute them to any number of users. See Licensing Overview.

User Controls and Class Libraries

Since version 32.0 with Service Pack 2, TX Text Control can run in a library that is called from assemblies without a license. Two static properties name the assembly with the license:

PropertySet it for
TextControl.EntryAssemblyThe WPF TextControl in TXTextControl.WPF
ServerTextControl.EntryAssemblyServerTextControl, which processes documents without a user interface

Both properties can only be set, at run time, and default to the application's executable assembly. A library that uses both types sets both.

A WPF User Control

A WPF user control library that references TXTextControl.TextControl.WPF.SDK contains an editor with a button bar. Its XAML, EditorControl.xaml, is:

<UserControl x:Class="MyControls.EditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF">
    <DockPanel>
        <WPF:ButtonBar x:Name="buttonBar1" DockPanel.Dock="Top" />
        <WPF:TextControl x:Name="textControl1" ButtonBar="buttonBar1" />
    </DockPanel>
</UserControl>

The code-behind, EditorControl.xaml.cs, sets the entry assembly before InitializeComponent creates the TextControl from the XAML:

using System.Windows.Controls;

namespace MyControls
{
    public partial class EditorControl : UserControl
    {
        public EditorControl()
        {
            // The license is compiled into this control library
            TXTextControl.WPF.TextControl.EntryAssembly = typeof(EditorControl).Assembly;

            InitializeComponent();
        }
    }
}

The code works as follows:

  • typeof(EditorControl).Assembly is the control library, into which the build compiled txtextcontrol.wpf.license.
  • The property is set in the constructor, before InitializeComponent, because the license is checked when the TextControl is created.
  • The type is written with its namespace, TXTextControl.WPF.TextControl, so the file needs no using directive for TX Text Control.

A Class Library With ServerTextControl

A class library that creates documents without a user interface sets ServerTextControl.EntryAssembly in the same way:

using TXTextControl;

namespace MyLibrary
{
    public class DocumentService
    {
        public DocumentService()
        {
            // The license is compiled into this class library
            ServerTextControl.EntryAssembly = typeof(DocumentService).Assembly;
        }

        public byte[] CreatePdf(string text)
        {
            using (ServerTextControl tx = new ServerTextControl())
            {
                tx.Create();
                tx.Text = text;

                byte[] pdf;
                tx.Save(out pdf, BinaryStreamType.AdobePDF);
                return pdf;
            }
        }
    }
}

The code works as follows:

  • The constructor names the library as the licensing assembly, before any ServerTextControl is created.
  • Create initializes the instance, Text sets its content, and Save with BinaryStreamType AdobePDF returns the document as PDF.

The WPF application that uses EditorControl or DocumentService references only your library. It needs no reference to TX Text Control and no license of its own. Unit test frameworks such as NUnit and MSTest, which run your tests from precompiled assemblies, are the other case the property was made for.

  • In .NET Framework projects with licenses.licx, and before version 32.0 with Service Pack 2, the license had to be in the calling executable. Add licenses.licx with the entries, and the references to TX Text Control, to the main project.
  • Don't rename an assembly after it is built. The license is stored in its resources and is not found under a new name. Change the assembly name in the project settings and rebuild instead.

The Edition at Run Time

A license covers the features of one edition. Code that uses a feature the licensed edition doesn't include throws a LicenseLevelException. Editions and Feature Availability lists the features per edition.

What Stays Out of Your Installer

Your application ships only the files Text Control designates as redistributable. Serial numbers, the license file txtextcontrol.wpf.license and a nuget.config with your API token must not reach your users; What Stays Out of the Installer in the Deployment Guide has the complete list, and Redistribution Overview lists the files to ship.