Dotfuscator User's Guide
Expiration and Warning Actions

Users can specify what action results when expiration or warning occur via configuration or custom attribute. If the user selects the default action, the application exits upon expiration and takes no action during the warning period.  The InsertShelfLife attribute can be used to inject code to perform a call back to a user-specified method when a Shelf Life warning or expiration occurs.

Expiration Notification

To accomplish this, the InsertShelfLife attribute is used to specify an ExpirationNotificationSink, which Dotfuscator uses to generate code that communicates the results of the shelf life expiration check back to the application. The ExpirationNotificationSink may be a writeable boolean valued property or field, or it may be a method or delegate with the signature void(bool) or void(string,string). After a shelf life expiration check, the generated code sets the boolean value to true if the application is expired; false if not. If using a method or delegate sink with a void(string,string) signature, the generated code will call this sink and will pass in the warning date and the expiration date as the string arguments, in that order. The application is free to react in any way in response to a shelf life expiration notification.  The InsertShelfLife attribute defines three properties for specifying an ExpirationNotificationSink:

These properties are described in detail in the InsertShelfLifeAttribute section of the custom attribute reference.

The expiration notification sink settings are optional. If they are omitted, the application is not notified when the expiration check is executed.

If the ExpirationNotificationSinkElement is set to DefaultAction, Dotfuscator injects code that exits the application if shelf life expiration is detected. 

Warning Notification

To accomplish this, the InsertShelfLife attribute is used to specify a WarningNotificationSink, which Dotfuscator uses to generate code that communicates the results of the shelf life warning check back to the application. The WarningNotificationSink may be a writeable boolean valued property or field, or it may be a method or delegate with the signature void(bool) or void(string,string). After a shelf life warning check, the generated code sets the boolean value to true if the application is in its warning period; false if it is not. If using a method or delegate sink with a void(string,string) signature, the generated code will call this sink and will pass in the warning date and the expiration date as the string arguments, in that order. The application is free to react in any way in response to a shelf life warning notification. The InsertShelfLife attribute defines three properties for specifying a WarningNotificationSink:

These properties are described in detail in the InsertShelfLifeAttribute section of the custom attribute reference.

The warning notification sink settings are optional. If they are omitted, the application is not notified when the warning check is executed.

If the WarningNotificationSinkElement is set to DefaultAction, Dotfuscator does not inject any code to handle the warning notification.  

 

Sample InsertShelfLife attribute usage with ExpirationNotificationSink and WarningNotificationSink as instance fields defined in the same class as the attributed method:

InsertShelfLife Attribute Usage with WarningNotificationSink and ExpirationNotificationSink
Copy Code
class ShelfLifeSample {
   bool instanceShelfLifeExpirationFlag;
    
   [PreEmptive.Attributes.InsertShelfLife(
      ActivationKeyFile = "C:\\shelflife.slkey",
      ExpirationDate = "2009-11-05",
      ExpirationNotificationSinkElement = SinkElements.Field,
      ExpirationNotificationSinkName = "instanceShelfLifeExpirationFlag",
      WarningDate = "2009-07-04",
      WarningNotificationSinkElement = SinkElements.Method,
      WarningNotificationSinkName = "CheckShelfLifeWarning"
   )]
   private void Verify() {
     // Dotfuscator will add Shelf Life expiration and warning detection and notification code here
   }
   private CheckShelfLifeExpirationState() {
      if ( instanceShelfLifeExpirationFlag ) {
         // app has expired
      }
      else {
         // app has not expired
      }
   }
   private CheckShelfLifeWarning(string warnDate, string expDate) {
      // use date strings directly
      Console.WriteLine("MyApp expires on " + expDate);
     
      // or parse to datetime to do calculations
      int daysLeft = DateTime.Parse(expDate).Subtract(DateTime.Now);
      Console.WriteLine("MyApp will expire in " + daysLeft + " days");
   }
}
See Also

References

 

 


© 2016 PreEmptive Solutions, LLC. All Rights Reserved.

www.preemptive.com