0

We are using preprocessor directives like trail and licensed, so we have two installers for trail and licensed. When the user want to upgrade from trail to licensed they have to uninstall trail and install Licensed and vice versa. Now we want to have only one installer that means we want to get rid of the process of reinstalling the application for trail to licensed and have only one installer which serves Trail and Licensed users.so my question is based on some license file that is DAT file, how we should change preprocessed code with C# code what are the alternatives to change code after user upgrades or degrades License. If there is any change in License then we need to come to Main method and reload session and all exception handlers, engines again with respective mode on. Please suggest how to code for this kind of challenge.

 class Program
    {
        static void Main(string[] args)
        {
#if Trail
        SomeStaticClass.PropertyId = "10023";
        //trail based code
#elif LICENSED
            SomeStaticClass.PropertyId = "10024";
            //licensed code
#endif

            //register some events based on trail and Licensed
            //create session based on trail and Licensed
            //license check is happening after all the sessions and environments are created 

        }
    }

    public static class SomeStaticClass
    {
        public static string PropertyId { get; set; }
    }
Gani.one
  • 53
  • 1
  • 5

1 Answers1

0

If downloading your trial version gives people all the compiled code of the licensed version, then some people may try to work out how your licensing test is implemented and break it.

I would instead refactor your application to create trial and licensed implementations of the same interfaces. Created from either a trial factory class or a licensed factory. With all the licensed classes in a separate assembly, which you do not ship with your trial version.

Your main method can then locate the licensed assembly, load it, and discover the factory class via reflection.

If you really want to ship only a single installer, I would ship the licensed assembly encrypted. Then your registration process can transmit and store the encryption key, so your main method can decrypt the assembly into memory and load it. Without the encryption key, the assembly would be completely useless.

Jeremy Lakeman
  • 9,515
  • 25
  • 29
  • Hi @jeremy,Thanks for the response. Our Customer want only one Installer to work with both trail and licensed versions. We don't have access to how License works ,that is from API service. For now we are thinking to implement it with Event handlers or implementing Polymorphism for trail and Licensed. But there is lot of code to be loaded which are having these Preprocessor #if blocks which in turn depend on checking the License, but to check license we need to load those first , so that is making this hard to implement. – Gani.one Sep 30 '21 at 06:18