After you've created a new product, go to the version page of the product you will be adding licensing to. You will need to do 2 things:
You'll be including the TurboActivate.dat file in the same folder as the TurboFloat.dll file and you'll use the Version GUID in your code as part of integrating TurboFloat within your app.
For VB.NET projects we recommend you set the "Target CPU" to x86. If you do this, your app will be able to run on both 32-bit and 64-bit machines without having to do complex installation scripts.
To set the target CPU to x86 first click the "Project -> [Project Name] Properties" menu in Visual Studio. Click the "Compile" tab on the right hand side. Click the "Advanced Compile Options..." button. Then choose x86 from the "Target CPU" dropdown:
Make sure you set this for both your "Release" and "Debug" configurations.
If instead of the x86 "Target CPU" you would rather choose AnyCPU then you need to make a few changes. The first thing you need to do add a "custom constant"
TF_BOTH_DLL=TRUE (do this for both Debug and Release builds). Then you need to include both the x86 and x64 versions of TurboFloat with your binaries. So copy the TurboFloat.dll from the x86 folder and put it in the Debug & Release folders. In the x64 folder rename TurboFloat.dll to "TurboFloat64.dll".
Included in TurboFloat Library package is a simple example project. The TurboFloat.vb file contains all the functions you'll be using to add the floating licenses functionality to your app.
We're going to walk you through adding floating licensing to your app by using our VB.NET example application. If you haven't downloaded it already you can get the example app inside the TurboFloat Library package.
In the example "Text Editor" VB.NET application the "Form1.vb" file is the main UI for the app. That is, it's the entry point for the application. And because it's the entry point of the application it's where we'll be requesting the "license lease" from the TurboFloat Server.
First, create the TurboFloat instance as a private member in the class:
Public Class Form1 Private tf As TurboFloat
Then, in the constructor for the form, you'll actually create the new instance of the TurboFloat class. Paste the Version GUID you copied from earlier:
Public Sub New() InitializeComponent() Try 'TODO: goto the version page at LimeLM and paste this GUID here tf = New TurboFloat("PASTE-VERSION-GUID-HERE") Catch ex As TurboFloatException MessageBox.Show("Failed to get a lease from the floating license server: " & ex.Message) Close() Exit Sub End Try End Sub
Next, we'll actually request the lease from the TurboFloat Server:
Try 'TODO: goto the version page at LimeLM and paste this GUID here tf = New TurboFloat("PASTE-VERSION-GUID-HERE") tf.RequestLease()
The native TurboFloat library handles all the details about renewing leases, retrying, etc. All you have to do is handle the cases where TurboFloat talks to your app and tells it something has changed (license lease failing to be renewed or new license field data). To do this you need to handle the LeaseChange event. Here we add a new event handler before we request a lease:
Try 'TODO: goto the version page at LimeLM and paste this GUID here tf = New TurboFloat("PASTE-VERSION-GUID-HERE") AddHandler tf.LeaseChange, AddressOf TurboFloat_LeaseChange tf.RequestLease()
Then, add the "TurboFloat_LeaseChange()" function to handle notifications from the TurboFloat library:
Private Sub TurboFloat_LeaseChange(sender As Object, e As StatusArgs) If e.Status = TF_LeaseStatus.TF_CB_FEATURES_CHANGED Then 'TODO: if you're using feature values in your app ' you might want to reload them now. Else ' TF_CB_EXPIRED, TF_CB_EXPIRED_INET, and everything else ' Immediately disable the app and/or show a modal ' form that gives the user the option to Save / ' Save As the data (if applicable) and let the ' user re-try connecting to the server. Enabled = False 'Note: Don't just close your app. Your users will be ' rightfully ticked-off if you do something like that. ' Instead, we're showing a modal dialog that lets the ' user try to get a new lease from the server. Or, ' if they can't, then save their data. Dim frmLeaseExp As LeaseExpired = New LeaseExpired(Me.tf) If frmLeaseExp.ShowDialog(Me) = DialogResult.Cancel Then ' close the app Close() Exit Sub End If ' We've gotten a new lease, so re-enable the app. Enabled = True End If End Sub
Included in the example VB.NET app are 3 forms that you might want to copy to your own application:
LeaseExpired.vb: a form to show if the license lease has expired.
frmInternetErr.vb: a form to show if there's an internet error (that is, a server is specified, but your app couldn't connect to the server).
ServerConfig.vb: a form to allow the end-user to enter details about where their TurboFloat Server is located.
You've already seen example usage of the LeaseExpired form in the TurboFloat_LeaseChange() function. Here's an example usage of the ServerConfig and frmInternetErr forms. Its logic is fairly simple. First it tries to get a lease, and if that fails then it prompts the user for action:
Public Sub New() InitializeComponent() Try 'TODO: goto the version page at LimeLM and paste this GUID here tf = New TurboFloat("PASTE-VERSION-GUID-HERE") AddHandler tf.LeaseChange, AddressOf TurboFloat_LeaseChange tf.RequestLease() Catch ex As ServerException Dim srvConf As ServerConfig = New ServerConfig(tf) If srvConf.ShowDialog(Me) <> DialogResult.OK Then MessageBox.Show("You must specify the location of the floating license server to run YourApp.") Close() Exit Sub End If Catch ex As TurboFloatException ' Give the user an option to try another server if they ' couldn't connect to the first one, or if the first one ' is for a different product. If TypeOf ex Is wyDay.TF.InternetException Or _ TypeOf ex Is WrongServerProductException Or _ TypeOf ex Is UsernameNotAllowedException Then Dim inetErr As frmInternetErr = New frmInternetErr(tf) If inetErr.ShowDialog(Me) <> DialogResult.OK Then ' exit the app on failure Close() Exit Sub End If Else ' all other errors MessageBox.Show("Failed to get a lease from the floating license server: " & ex.Message) Close() Exit Sub End If End Try End Sub
After you've successfully requested a lease from the TurboFloat Server, the TurboFloat library integrated in your app takes care of renewing the leases automatically and silently. You'll only ever get a notification of something going wrong in the handler for the LeaseChange event that we covered in Step 3.
When your app is closing you should "drop" the lease using the
DropLease() method, and cleanup the memory using the
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed Try ' Drop the lease If tf.HasLease Then tf.DropLease() End If ' cleanup memory tf.Cleanup() Catch ex As Exception ' we're exiting anyway, just let the lease be a zombie. End Try End Sub
What this does is tell the TurboFloat Server that you're through using the lease in this instance of your app, and another instance of your app on another computer or another session can now use that "free slot".
If you can't drop the lease (because your app can't connect to the internet, or for any other reason), and you choose to exit your app anyway, then the "lease" on the TurboFloat Server will be a "zombie". The lease will expire eventually on the TurboFloat Server, and thus the free slot will open back up.
Testing requesting leases, dropping them, and everything else in the TurboFloat Library is intuitive: just call the function and it does the thing you want it to do. Testing the lease change event is, however, slightly less intuitive. Here's how you can test the lease change event:
If your app is open and has a lease, close your app and make sure it drops the license lease from the TurboFloat Server.
Stop the TurboFloat Server instance.
Save the changes you made to the configuration file.
Start your TurboFloat Server instance again.
Start your app again, and make sure it successfully gets a license lease from the TurboFloat Server.
Now, stop the TurboFloat Server instance, but leave your app running.
Within the next 30 seconds the lease change event will be called because the TurboFloat Library was not able to renew the license lease automatically.