ComponentFactory.Krypton.Ribbon.EvaluationMonitor.EvaluationMonitor C# (CSharp) Method

EvaluationMonitor() public method

Initialize a new instance of the evaluation monitor.
The UsageCount is incremented each time a new evaluation monitor is instantiated for a product
public EvaluationMonitor ( string productID ) : System
productID string A string which uniquely identifies the product
return System
        public EvaluationMonitor(string productID)
        {
            _productData = Encrypt(productID);
            RegistryKey parentKey = null;

            // test whether we can write to HKEY_CLASSES_ROOT
            //
            try
            {
                RegistryKey key = Registry.ClassesRoot.CreateSubKey(productID);
                Registry.ClassesRoot.DeleteSubKey(productID, false);

                // if that succeeded then set up the keys appropriately
                //
                _rootKey = Registry.ClassesRoot;
                parentKey = _rootKey.OpenSubKey("CLSID", true);
                _usageKeyName = classUsageKey;
                _firstUseKeyName = classFirstUseKey;
                _lastUseKeyName = classLastUseKey;
            }
            catch (UnauthorizedAccessException)
            {
            }

            if (parentKey == null)
            {
                try
                {
                    // revert to using HKEY_CURRENT_USER
                    //
                    _rootKey = Registry.CurrentUser;
                    parentKey = _rootKey.OpenSubKey("Software", true);
                    _usageKeyName = userUsageKey;
                    _firstUseKeyName = userFirstUseKey;
                    _lastUseKeyName = userLastUseKey;
                }
                catch (UnauthorizedAccessException)
                {
                }
            }

            if (parentKey != null)
            {
                try
                {
                    // find the base key
                    //
                    _baseKey = FindBaseKey(parentKey);

                    // OK we couldn't find a key so create it
                    //
                    if (_baseKey == null)
                    {
                        _usageCount = 0;
                        _firstUseDate = DateTime.UtcNow;
                        _lastUseDate = DateTime.UtcNow;
                        CreateBaseKey(parentKey);
                    }
                    else
                    {
                        GetDateData();
                        GetUsageData();
                    }
                    parentKey.Close();
                }
                catch
                {
                    _invalid = true;
                }
            }
            else
            {
                _usageCount = 1;
                _firstUseDate = DateTime.UtcNow;
                _lastUseDate = DateTime.UtcNow;
            }
        }