public void GetArgumentsCommandLineTest() { Assert.Inconclusive("Fakes doesn't work"); string[] _arguments = CodeProtectHelpers.GetArguments(); Assert.IsNotNull(_arguments); Assert.AreEqual <int>(3, _arguments.Length); Assert.IsTrue(_arguments[0].ToLower().Contains("c:\\program files (x86)\\microsoft"), _arguments[0].ToLower()); Assert.IsTrue(_arguments[1].Contains(@"/parentProcessId"), _arguments[1].ToLower()); Assert.IsTrue(int.Parse(_arguments[2]) > -1, _arguments[2]); }
/// <summary> /// Gets a license for an instance or type of component, when given a context and whether the denial of a license /// throws an exception. This is responsible for obtaining the license or reporting the error if non is found. /// </summary> /// <param name="context">A <see cref="System.ComponentModel.LicenseContext"/> that specifies where you can use the licensed object.</param> /// <param name="type">A <see cref="System.Type"/> that represents the component requesting the license.</param> /// <param name="instance">An object that is requesting the license.</param> /// <param name="allowExceptions">true if a <see cref="System.ComponentModel.LicenseException"/> should be thrown when the /// component cannot be granted a license; otherwise, false..</param> /// <returns> /// A valid <see cref="System.ComponentModel.License"/>. /// </returns> /// <exception name="LicenseException"> /// <p>The reason the validation failed.</p> /// </exception> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { Assembly protectedAss = null; LicenseFile currentLicense = null; try { Debug.WriteLine("OpenLicenseProvider: GetLicense Function"); if (context == null) { throw new ArgumentNullException(Resources.LicenseFileErrorContext); } if (type == null) { throw new ArgumentNullException(Resources.LicenseFileErrorType); } protectedAss = Assembly.GetAssembly(type); if (protectedAss == null) { throw new LicenseFileException(string.Format(Resources.LicenseFileErrorAssembly, type.ToString())); } RSACryptoServiceProvider key = null; try { key = CodeProtectHelpers.ReadKeysFromProtectedArea(CodeProtectHelpers.GetEntropy()); } catch (Exception ex) { throw new LicenseFileException(Resources.LicenseFileErrorRSA, ex); } currentLicense = GetLicense(type, key); if (!currentLicense.ValidateLicense(type)) { if (String.IsNullOrEmpty(currentLicense.FailureReason)) { currentLicense.FailureReason = Resources.LicMessageFunctionNoReason; } throw new LicenseFileException(currentLicense.FailureReason); } if ((currentLicense.Statistics.DateTimeLastAccessed.Ticks > 0) && (currentLicense.Statistics.DateTimeLastAccessed.CompareTo(DateTime.Now) > 0)) { currentLicense.FailureReason = Resources.LicMessageFunctionDataTime; throw new LicenseFileException(currentLicense.FailureReason); } //Ok we have a valid license now... //Lets update the stats and save this file... currentLicense.Statistics.UpdateLastAccessDate(); currentLicense.Statistics.IncrementDaysUsed(); currentLicense.Statistics.IncrementAccessCount(); currentLicense.Statistics.IncrementUsageUsed(); currentLicense.Statistics.IncrementHitCount(); Save(type, currentLicense, key); return(currentLicense); } catch (Exception ex) { OpeningError = BuildExceptionString(type, protectedAss, ex); if (allowExceptions) { throw new LicenseException(type, instance, OpeningError); } else { return(currentLicense); } } }