Skip to content

Commit

Permalink
(GH-584) Load licensed version
Browse files Browse the repository at this point in the history
If the license is found to be a licensed version, attempt to load the
assembly and register the components provided by the licensed version.
Provide helpful error messages when loading the assembly fails for some
reason.
  • Loading branch information
ferventcoder committed Jan 30, 2016
1 parent 434043f commit 16d197b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace chocolatey.console
using infrastructure.configuration;
using infrastructure.extractors;
using infrastructure.filesystem;
using infrastructure.information;
using infrastructure.licensing;
using infrastructure.logging;
using infrastructure.registration;
using infrastructure.services;
using resources;
using Console = System.Console;
using Environment = System.Environment;
Expand All @@ -53,6 +53,29 @@ private static void Main(string[] args)
Bootstrap.startup();

var license = LicenseValidation.validate();
if (license.is_licensed_version())
{
try
{
var licensedAssembly = Assembly.LoadFile(ApplicationParameters.LicensedAssemblyLocation);
license.AssemblyLoaded = true;
license.Version = VersionInformation.get_current_informational_version(licensedAssembly);
Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: true, ignoreCase: true);
SimpleInjectorContainer.add_component_registry_class(licensedComponent);
}
catch (Exception ex)
{
"chocolatey".Log().Error(
@"Error when attempting to load chocolatey licensed assembly. Ensure
that chocolatey.licensed.dll exists at
'{0}'.
The error message itself may be helpful as well:{1} {2}".format_with(
ApplicationParameters.LicensedAssemblyLocation,
Environment.NewLine,
ex.Message
));
}
}
var container = SimpleInjectorContainer.Container;

var config = container.GetInstance<ChocolateyConfiguration>();
Expand Down

0 comments on commit 16d197b

Please sign in to comment.