SetLicense Method

Summary
Sets the license for the calling application.
Syntax
C#
C++/CLI
public void SetLicense( 
   string license, 
   string key, 
   int flags 
) 
public: 
void SetLicense(  
   String^ license, 
   String^ key, 
   int flags 
)  

Parameters

license
String containing the license or the path to the license file.

key
String containing the key or the path to the key file.

flags
Flags that specify which type of operation to perform. It is a bitwise OR of the SetLicenseFlags Enumeration Constants.

Remarks

This method will set the license for the entire application, and is only required to be called once. If the library is already licensed, any additional calls to this function will be ignored, unless Overwrite is specified.

If the method fails, an error is raised. For more information, refer to the Error Codes.

Example
C#
using Leadtools; 
using Leadtools.MediaStreaming; 
 
 
 
public class LicenseHolder 
{ 
   protected LicenseManager m_licmgr; 
   protected bool m_service; 
   protected bool m_verbose; 
   protected string m_title; 
 
   public LicenseHolder(bool verbose, string title, bool service) 
   { 
      m_service = service; 
      m_verbose = verbose; 
      m_title = title; 
   } 
   ~LicenseHolder() 
   { 
 
   } 
 
   protected bool IsDisplayEnabled() 
   { 
      return (m_verbose && !m_service); 
   } 
 
   protected DialogResult DisplayLicenseError(string message) 
   { 
      return MessageBox.Show(message, m_title, MessageBoxButtons.OK, MessageBoxIcon.Error); 
   } 
 
   public void LoadLicenseManager() 
   { 
      try 
      { 
         if (m_licmgr == null) 
         { 
            m_licmgr = new LicenseManager(); 
         } 
      } 
      catch (System.Exception ex) 
      { 
         if (IsDisplayEnabled()) 
         { 
            DisplayLicenseError("Can't instantiate LEAD Media Streaming License Manager"); 
         } 
 
         throw ex; 
      } 
   } 
 
   public void SetLicense(string license, string key, SetLicenseFlags flags) 
   { 
      LoadLicenseManager(); 
 
      try 
      { 
         // Sets the license for the calling application 
         m_licmgr.SetLicense(license, key, (int)flags); 
      } 
      catch (System.Exception ex) 
      { 
         if (IsDisplayEnabled()) 
         { 
            DisplayLicenseError("Your license file is missing, invalid or expired. The LEAD Media Streaming Library will not function. Please contact LEAD Sales for information on obtaining a valid license."); 
            Process.Start("https://www.leadtools.com/downloads/evaluation-form.asp?evallicenseonly=true"); 
         } 
 
         throw ex; 
      } 
   } 
   public void UnloadLicenseManager() 
   { 
      m_licmgr.Dispose(); 
      m_licmgr = null; 
   } 
 
} 
 
 
public Server _server = null; 
public bool _result = false; 
 
public void LicenseHolderExample() 
{ 
   try 
   { 
      // create an instance of the LicenseHolder class 
      LicenseHolder holder = new LicenseHolder(true, "Leadtools MediaStreaming Server", false); 
 
      // set the license 
      holder.SetLicense("%ltmsAppFolder%\\LEADTOOLS.LIC", "%ltmsAppFolder%\\LEADTOOLS.LIC.KEY", SetLicenseFlags.LicenseIsFile | SetLicenseFlags.KeyIsFile); 
 
      // create an instance of the server object 
      _server = new Leadtools.MediaStreaming.Server(); 
 
      // start the server 
      _server.Start(); 
 
      // confirm the running state for demonstration purposes 
      if (_server.State == State.Started) 
      { 
         // display a message that the server is running and wait for OK 
         MessageBox.Show("The server has started. Press OK to stop.", "LEADTOOLS Media Streaming Examples", MessageBoxButtons.OK, MessageBoxIcon.Information); 
      } 
 
      // stop the server 
      _server.Stop(); 
 
      // unload the license 
      holder.UnloadLicenseManager(); 
 
      _result = true; 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.MediaStreaming Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.