internal static bool IsFeatureEnabled(string featureId) { object value = RegistryHelpers.GetSetting("Feature_" + featureId, null); if (value != null) { return(true); //todo: to prevent registry tampering, we should retrieve the activation key and check with the server that it is ok. } else { return(false); } }
public static bool IsTheKeyValid(string featureId) { string value = RegistryHelpers.GetSetting("Validity_" + featureId, null); double valueAsDouble; if (value != null && double.TryParse(value.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out valueAsDouble)) // Note: the "Replace" method is here only for backward compatibility, due to the fact that up to Beta 5 included, we didn't store the value with "InvariantCulture". { DateTime validityDate = DateTime.FromOADate(valueAsDouble); if (DateTime.Today <= validityDate) { return(true); //the key is still valid } else { return(false); //the key is no longer valid } } else { return(true); //We cannot know whether the key is valid or not so we consider that it is (permanent versions). } }
public static TrialStatus IsTrial(string featureId, out int numberOfDaysLeft) { numberOfDaysLeft = 0; string value = RegistryHelpers.GetSetting("Trial_" + TRIAL_VERSION_IDENTIFIER + "_" + featureId, null); double valueAsDouble; if (value != null && Double.TryParse(value.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out valueAsDouble)) // Note: the "Replace" method is here only for backward compatibility, due to the fact that up to Beta 5 included, we didn't store the value with "InvariantCulture". { DateTime initialDate = DateTime.FromOADate(valueAsDouble); numberOfDaysLeft = TRIAL_DURATION_IN_DAYS - ((int)(DateTime.Now - initialDate).TotalDays); if (numberOfDaysLeft > 0) { return(TrialStatus.Running); } else { return(TrialStatus.Expired); } } else { return(TrialStatus.NotStarted); } }