static void CrossDomainLoadComponents()
        {
            var ctx = (CrossDomainContext)AppDomain.CurrentDomain.GetData("ctx");

            // Initialize the version resolver callback
            ConfuserEngine.Version.ToString();

            Assembly assembly = Assembly.LoadFile(ctx.PluginPath);

            foreach (var module in assembly.GetLoadedModules())
            {
                foreach (var i in module.GetTypes())
                {
                    if (i.IsAbstract || !PluginDiscovery.HasAccessibleDefConstructor(i))
                    {
                        continue;
                    }

                    if (typeof(Protection).IsAssignableFrom(i))
                    {
                        var prot = (Protection)Activator.CreateInstance(i);
                        ctx.AddProtection(Info.FromComponent(prot, ctx.PluginPath));
                    }
                    else if (typeof(Packer).IsAssignableFrom(i))
                    {
                        var packer = (Packer)Activator.CreateInstance(i);
                        ctx.AddPacker(Info.FromComponent(packer, ctx.PluginPath));
                    }
                }
            }
        }
Beispiel #2
0
        public void Discovery_should_monitors_that_cannot_be_instantiated()
        {
            var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) };

            var monitors = PluginDiscovery <IHealthMonitor> .DiscoverAll(
                typeof(BrokenMonitor).Assembly.Location,
                typeof(HttpMonitor).Assembly.Location);

            CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType()));
        }
Beispiel #3
0
        public void Discovery_should_scan_given_assembly_only_once()
        {
            var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) };

            var monitors = PluginDiscovery <IHealthMonitor> .DiscoverAll(
                typeof(HttpMonitor).Assembly.Location,
                typeof(HttpMonitor).Assembly.Location
                );

            CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType()));
        }
Beispiel #4
0
        public void Discovery_should_skip_assemblies_that_cannot_be_loaded()
        {
            var expected = new[] { typeof(HttpMonitor), typeof(HttpJsonMonitor) };


            var monitors = PluginDiscovery <IHealthMonitor> .DiscoverAll(
                "some_inexistent_assembly.dll",
                typeof(HttpMonitor).Assembly.Location);

            CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType()));
        }
Beispiel #5
0
        public void Discovery_should_load_and_instantiate_all_monitors()
        {
            var expected = new[]
            {
                typeof(HttpMonitor),
                typeof(HttpJsonMonitor),
                typeof(TestHealthMonitor),
                typeof(TestHealthMonitor2)
            };


            var monitors = PluginDiscovery <IHealthMonitor> .DiscoverAll(
                typeof(HttpMonitor).Assembly.Location,
                typeof(TestHealthMonitor).Assembly.Location);

            CollectionAssert.AreEquivalent(expected, monitors.Select(p => p.GetType()));
        }
Beispiel #6
0
 static void Main(string[] args)
 {
     Console.Clear();
     Console.Title = "UnSealer - v" + UnSealerVersion;
     Console.SetWindowSize(83, 33);
     Console.SetBufferSize(83, 9001);
     Banner();
     Protections = PluginDiscovery.GetCurrentDirPlugins(ConsoleLogger);
     if (args.Length <= 0)
     {
         Console.Write("[~] Enter Arguments : ");
         var pargs = Console.ReadLine() !.Replace("\"", string.Empty).Split(' ');
         Console.Clear();
         Banner();
         var ParsedArgs = new ArgumentsParser(Protections, pargs).Result;
         ExecuteEngine(ParsedArgs, ConsoleLogger);
     }
     else
     {
         var ArgsParsed = new ArgumentsParser(Protections, args).Result;
         ExecuteEngine(ArgsParsed, ConsoleLogger);
     }
 }
Beispiel #7
0
        private static void CrossDomainLoadComponents()
        {
            var      ctx      = (CrossDomainContext)AppDomain.CurrentDomain.GetData("ctx");
            Assembly assembly = Assembly.LoadFile(ctx.PluginPath);

            foreach (Type i in assembly.GetTypes())
            {
                if (i.IsAbstract || !PluginDiscovery.HasAccessibleDefConstructor(i))
                {
                    continue;
                }

                if (typeof(Protection).IsAssignableFrom(i))
                {
                    var prot = (Protection)Activator.CreateInstance(i);
                    ctx.AddProtection(Info.FromComponent(prot, ctx.PluginPath));
                }
                else if (typeof(Packer).IsAssignableFrom(i))
                {
                    var packer = (Packer)Activator.CreateInstance(i);
                    ctx.AddPacker(Info.FromComponent(packer, ctx.PluginPath));
                }
            }
        }
Beispiel #8
0
        private void ConfigureDependencies(HttpConfiguration config)
        {
            var builder = new ContainerBuilder();

            builder.RegisterAssemblyTypes(typeof(Program).Assembly).Where(t => typeof(ApiController).IsAssignableFrom(t)).AsSelf();
            builder.RegisterAssemblyTypes(typeof(EndpointRegistry).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterAssemblyTypes(typeof(CredentialsProvider).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterAssemblyTypes(typeof(SqlEndpointConfigurationRepository).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterAssemblyTypes(typeof(EndpointStatsManager).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance();

            builder.RegisterInstance <IEndpointMetricsForwarderCoordinator>(new EndpointMetricsForwarderCoordinator(PluginDiscovery <IEndpointMetricsForwarder> .DiscoverAllInCurrentFolder("*.Forwarders.*.dll")));
            builder.Register(ctx => ContinuousTaskExecutor <Endpoint> .StartExecutor(ctx.Resolve <ITimeCoordinator>())).AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <TimeCoordinator>().AsImplementedInterfaces().SingleInstance();
            var container = builder.Build();

            InstantiateBackroundServices(container);
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Beispiel #9
0
        private static IContainer StartHost()
        {
            var timeCoordinator    = new TimeCoordinator();
            var credentialProvider = new CredentialsProvider();
            var exchangeClient     = new HealthMonitorExchangeClient(ConfigurationManager.AppSettings["HealthMonitoringUrl"], timeCoordinator, credentialProvider);
            var settings           = LoadSettings(exchangeClient);

            var builder = new ContainerBuilder();

            builder.Register(ctx => ContinuousTaskExecutor <MonitorableEndpoint> .StartExecutor(ctx.Resolve <ITimeCoordinator>())).AsImplementedInterfaces().SingleInstance();
            builder.RegisterInstance(timeCoordinator).AsSelf().AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(typeof(HealthMonitorRegistry).Assembly).AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterInstance(exchangeClient).AsSelf().AsImplementedInterfaces();
            builder.RegisterInstance(settings.MonitorSettings).AsImplementedInterfaces();
            builder.RegisterInstance(settings.ThrottlingSettings).AsImplementedInterfaces();
            builder.RegisterInstance(AppSettingsDataExchangeConfigProvider.ReadConfiguration());

            builder.Register(c => new ThrottlingSampler(c.Resolve <HealthSampler>(), c.Resolve <IThrottlingSettings>())).AsImplementedInterfaces();

            builder.RegisterInstance <IHealthMonitorRegistry>(new HealthMonitorRegistry(PluginDiscovery <IHealthMonitor> .DiscoverAllInCurrentFolder("*.Monitors.*.dll")));
            builder.RegisterType <EndpointMonitor>().AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <MonitorDataExchange>().AsSelf().AsImplementedInterfaces().SingleInstance();

            var container = builder.Build();

            container.Resolve <EndpointMonitor>();
            return(container);
        }