public void AfterCreationTest()
        {
            LicenseTraceSource _tracer = LicenseTraceSource.This;

            Assert.IsNotNull(_tracer);

            //Listeners
            Assert.AreEqual(1, _tracer.Listeners.Count);
            Dictionary <string, TraceListener> _listeners = _tracer.Listeners.Cast <TraceListener>().ToDictionary <TraceListener, string>(x => x.Name);

            Assert.IsTrue(_listeners.ContainsKey("LogFile"));
            TraceListener _listener = _listeners["LogFile"];

            Assert.IsNotNull(_listener);
            Assert.IsInstanceOfType(_listener, typeof(AdvancedDelimitedListTraceListener));
            AdvancedDelimitedListTraceListener _advancedListener = _listener as AdvancedDelimitedListTraceListener;

            Assert.AreEqual <string>(ExpectedFileName, _advancedListener.GetFileName());

            //Filter
            Assert.IsNotNull(_advancedListener.Filter);
            Assert.IsInstanceOfType(_advancedListener.Filter, typeof(EventTypeFilter));
            EventTypeFilter _eventTypeFilter = _advancedListener.Filter as EventTypeFilter;

            Assert.AreEqual(SourceLevels.All, _eventTypeFilter.EventType);

            //Test Switch
            Assert.IsNotNull(_tracer.Switch);
            Assert.AreEqual <string>("CAS.CodeProtect.TraceSource.Switch", _tracer.Switch.DisplayName);
            Assert.AreEqual <SourceLevels>(SourceLevels.All, _tracer.Switch.Level);

            //Trace
            Assert.IsFalse(Trace.Listeners.Cast <TraceListener>().Where <TraceListener>(x => x.Name == "LogFile").Any <TraceListener>());
        }
Exemple #2
0
        /// <summary>
        /// It is called by the constructor at the end of the license validation process if a proper license file can be opened.
        /// By default it traces the information about the license to the <see cref="LicenseTraceSource"/> as verbose message.
        /// If implemented by the derived class the current license can be used to get more information from it.
        /// </summary>
        /// <param name="license">The current license for temporal use. The current license is disposed just after returning from this method
        /// </param>
        /// <remarks>
        /// Because the current license is disposed in the base class just after returning from this method, it must not be
        /// assigned locally to keep it for future use. To keep it for future use the derived class must make a local copy.
        /// </remarks>
        protected virtual void TraceCurrentLicense(LicenseFile license)
        {
            string format = "Obtained valid license for {0}, runtime={1}, volume={2}";
            string msg    = string.Format(format, typeof(type).FullName, license.RunTimeConstrain, license.VolumeConstrain);

            LicenseTraceSource.TraceVerbose(0, msg);
        }
Exemple #3
0
 internal static void InstallLicense(string user, string company, string email, bool loadLicenseFromDefaultContainer, string alternativeProductName, string licenseUnlockCode, Assembly assembly)
 {
     if (assembly == null)
     {
         throw new ArgumentNullException(nameof(assembly), $"Entring {nameof(InstallLicense)} with null argument.");
     }
     LicenseTraceSource.TraceVerbose(39, $"Entering InstallLicense {user}, {company}, {email}");
     ManifestManagement.WriteDeployManifest(assembly, alternativeProductName);
     LicenseFile.Install(user, company, email, FileNames.LicenseFilePath, loadLicenseFromDefaultContainer, licenseUnlockCode);
 }
        public void LogFileTest()
        {
            LicenseTraceSource _tracer = LicenseTraceSource.This;

            Assert.IsNotNull(_tracer);
            _tracer.TraceEvent(TraceEventType.Error, 0, "Test message");
            _tracer.Flush();
            FileInfo _logFile = new FileInfo(ExpectedFileName);

            Assert.IsTrue(_logFile.Exists);
            Assert.IsTrue(_logFile.Length > 10);
        }
Exemple #5
0
        /// <summary>
        /// It is called by the constructor if a warning appears after reading a license
        /// By default it traces the information about the warnings to the <see cref="LicenseTraceSource"/> as information message.
        /// If implemented by the derived class allows caller to show warning or write it to a log.
        /// </summary>
        protected virtual void TraceWarning(List <string> warning)
        {
            string msg = "After loading a license the following warning appeared: {0}.";

            LicenseTraceSource.TraceInformation(0, String.Format(msg, string.Concat(warning.ToArray())));
        }
Exemple #6
0
        /// <summary>
        /// It is called by the constructor if a proper license file cannot be opened.
        /// By default it traces the information about the problem to the <see cref="LicenseTraceSource"/> as error message.
        /// If implemented by the derived class allows caller to write license failure reason to a log.
        /// </summary>
        protected virtual void TraceNoLicenseFile(string reason)
        {
            string msg = "No license has been found, because: {0}.";

            LicenseTraceSource.TraceError(0, String.Format(msg, reason));
        }
Exemple #7
0
        /// <summary>
        /// It is called by the constructor at the end of the license validation process if a proper license file can be opened
        /// but the license is invalid for the provided <typeparamref name="type"/>.
        /// By default it traces the information about the problem to the <see cref="LicenseTraceSource"/> as warning message.
        /// If implemented by the derived class
        /// allows caller to write license failure reason to a log.
        /// </summary>
        /// <param name="reason">The reason of the license failure.</param>
        protected virtual void TraceFailureReason(string reason)
        {
            string msg = "Cannot activate program feature because: {0}.";

            LicenseTraceSource.TraceWarning(0, String.Format(msg, reason));
        }