Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command1"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private Command1(AsyncPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                _configuration = new ConfigurationBuilder()
                                 .SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
                                 .AddXmlFile(@"_settings.config", optional: false)
                                 .Build();

                // create service collection
                var services = new ServiceCollection();
                ConfigureServices(services);

                _serviceProvider = services.BuildServiceProvider();
                ServiceLocator.SetLocatorProvider(_serviceProvider);

                _serviceProvider.GetRequiredService <DbUpdater>().UpdateDb();
                _serviceProvider.GetRequiredService <HistoryPlugin>().Register();
                _serviceProvider.GetRequiredService <SearchPlugin>().Register();
                _serviceProvider.GetRequiredService <DocumentPlugin>().Register();
                _serviceProvider.GetRequiredService <PreferencesUI>().Register();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetFullStackTraceWithMessage(), "Could not Load SSMSPlus");
                _serviceProvider.GetRequiredService <ILogger <Command1> >().LogCritical(ex, "Critical Error when starting pluging");

                throw;
            }
        }
 public CommandHandler(DiscordSocketClient client, CommandService commands, Microsoft.Extensions.DependencyInjection.ServiceProvider services, OpenDotaApi openDota)
 {
     _commandService = commands;
     _client         = client;
     _openDota       = openDota;
     _services       = services;
 }
        private static Microsoft.Extensions.DependencyInjection.ServiceProvider SetUpServiceProvider()
        {
            IConfiguration     configuration     = GetConfiguration();
            IServiceCollection serviceCollection = GetServiceCollection(configuration);

            Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider =
                serviceCollection.BuildServiceProvider();

            return(serviceProvider);
        }
        public static T Get <T>()
        {
            if (_provider == null)
            {
                _provider = SetUpServiceProvider();
            }

            T service = _provider.GetService <T>();

            return(service);
        }
        protected override void SetUp()
        {
            _busMock = new Mock <IBus>
            {
                DefaultValue = DefaultValue.Mock
            };

            _busStarterMock = new Mock <IBusStarter>();
            _busStarterMock.SetReturnsDefault(_busMock.Object);

            _serviceProvider = new ServiceCollection()
                               .AddRebus(c => c)
                               .Replace(ServiceDescriptor.Singleton(_busStarterMock.Object))
                               .BuildServiceProvider();

            Using(_serviceProvider);
        }
 public ServiceProviderRootResolver(Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider,
                                    IServiceCollection serviceCollection)
     : base(serviceProvider, serviceCollection)
 {
 }
Exemple #7
0
        } // End Task RunAsPlatformIndependentService

        // static async System.Threading.Tasks.Task MainTask(string[] args)
        static async System.Threading.Tasks.Task RunAsWindowsService(string[] args)
        {
            Microsoft.Extensions.DependencyInjection.IServiceCollection services =
                new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            // Create configuration builder
            Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder =
                new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                .SetBasePath(System.IO.Directory.GetCurrentDirectory())
                // .AddIniFile(@"D:\inetpub\LdapService\LdapService.ini")
                //.AddJsonFile("appsettings.json")
            ;

            // Inject configuration
            services.AddSingleton <Microsoft.Extensions.Configuration.IConfiguration>(provider =>
            {
                return(configurationBuilder.Build());
            });


            // Inject Serilog
            services.AddLogging(options =>
            {
                options.SetMinimumLevel(LogLevel.Information);
                options.AddFilter(x => x >= LogLevel.Trace);

                options.AddConsole();
                options.AddDebug();

                /*
                 * options.AddSerilog(
                 *  new LoggerConfiguration()
                 *             .ReadFrom.Configuration(configurationBuilder.Build())
                 *             .CreateLogger()
                 *  );
                 */
            });


            // Inject common service
            services.AddSingleton(typeof(ICommonService), typeof(CommonSampleService));

            // Inject concrete implementation of the service
            services.AddSingleton(typeof(System.ServiceProcess.ServiceBase), typeof(GenericService));

            // My configuration
            services.AddSingleton(new MyConfig());

            services.Configure <SmtpConfig>(
                delegate(SmtpConfig config)
            {
                config.Server = "hello world";
                return;
            }
                );


            /*
             * // IConfiguration Configuration = null;
             *
             * // services.Configure<SmtpConfig>(Configuration.GetSection("Smtp"));
             * // IConfiguration iconf = Configuration.GetSection("Smtp");
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<SmtpConfig>(
             *  services, iconf
             * );
             */


            // Build DI provider
            Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider = services.BuildServiceProvider();


            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Console Debug mode

                /*
                 * try
                 * {
                 *  IConfiguration confy = serviceProvider.GetService<IConfiguration>();
                 *  System.Console.WriteLine(confy);
                 *  // var sec = confy.GetSection("ErrorMail2");
                 *  // https://stackoverflow.com/questions/39169701/how-to-extract-a-list-from-appsettings-json-in-net-core
                 *  // foreach (var section in confy.GetChildren()) section.GetChildren();
                 *
                 *
                 *  // Fixes to IniStreamConfigurationProvider.cs:if (separator < 0)
                 *  var jobs = confy.GetSection("Jobs").Get<System.Collections.Generic.Dictionary<string, string>>();
                 *  var sec = confy.GetSection("ErrorMail2").Get<System.Collections.Generic.Dictionary<string, string>>();
                 *
                 *  // sec.Keys, sec.Values
                 *
                 *  System.Console.WriteLine(sec);
                 *  System.Console.WriteLine(jobs);
                 *
                 *
                 * }
                 * catch (System.Exception ex)
                 * {
                 *  System.Console.WriteLine(ex.Message);
                 * }
                 */



                GenericService svc = serviceProvider.GetService <System.ServiceProcess.ServiceBase>() as GenericService;
                svc.StartService(args);

                // System.Console.ReadLine();

                System.ConsoleKey cc = default(System.ConsoleKey);
                do
                {
                    // THIS IS MADNESS!!!   Madness huh?   THIS IS SPARTA!!!!!!!
                    while (!System.Console.KeyAvailable)
                    {
                        // System.Threading.Thread.Sleep(100);
                        await System.Threading.Tasks.Task.Delay(100);
                    }

                    cc = System.Console.ReadKey().Key;

                    if (cc == System.ConsoleKey.C)
                    {
                        System.Console.Clear();
                    }
                } while (cc != System.ConsoleKey.Enter);

                svc.Stop();
            }
            else
            {
                // Start service
                System.ServiceProcess.ServiceBase[] servicesToRun;
                servicesToRun = new System.ServiceProcess.ServiceBase[]
                {
                    serviceProvider.GetService <System.ServiceProcess.ServiceBase>()
                };

                System.ServiceProcess.ServiceBase.Run(servicesToRun);
            } // End else of if (System.Diagnostics.Debugger.IsAttached)

            // await System.Threading.Tasks.Task.CompletedTask;
        } // End Task RunAsWindowsService
 public virtual void Build()
 {
     _provider?.Dispose();
     _provider = Services.BuildServiceProvider();
 }
 public ActivatedContainer(Microsoft.Extensions.DependencyInjection.ServiceProvider provider)
 {
     _provider = provider;
 }