示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var obSettings = app.ApplicationServices.GetService <OpenBulletSettingsService>().Settings;

            if (RootChecker.IsRoot())
            {
                Console.WriteLine(RootChecker.RootWarning);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            if (obSettings.SecuritySettings.HttpsRedirect)
            {
                app.UseHttpsRedirection();
            }

            app.UseRequestLocalization();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action}");

                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });

            // Apply DB migrations or create a DB if it doesn't exist
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                context.Database.Migrate();
            }

            // Load the configs
            var configService = app.ApplicationServices.GetService <ConfigService>();

            configService.ReloadConfigs().Wait();

            // Initialize autocompletion
            AutocompletionProvider.Init(obSettings.GeneralSettings.CustomSnippets);
        }
        private void TextEntered(object sender, TextCompositionEventArgs e)
        {
            try
            {
                var offset       = editor.CaretOffset;
                var documentLine = editor.Document.GetLineByOffset(offset);
                var line         = editor.Document.GetText(documentLine.Offset, documentLine.Length);

                // Do not complete if we are not typing at the start of the line without spaces
                if (!string.IsNullOrWhiteSpace(line) && !line.Contains(' '))
                {
                    var snippets = AutocompletionProvider.GetSnippets()
                                   .Where(s => s.Id.StartsWith(line, StringComparison.OrdinalIgnoreCase));

                    // If there are no snippets, do not even open the completion window
                    if (!snippets.Any())
                    {
                        return;
                    }

                    // Open code completion:
                    completionWindow = new CompletionWindow(editor.TextArea)
                    {
                        Foreground = Brushes.Gainsboro,
                        Background = Helpers.Brush.FromHex("#222")
                    };

                    var data = completionWindow.CompletionList.CompletionData;

                    foreach (var snippet in snippets)
                    {
                        data.Add(new LoliCodeCompletionData(snippet.Id, snippet.Body, snippet.Description));
                    }

                    completionWindow.Show();
                    completionWindow.Closed += (_, _) => completionWindow = null;
                }
            }
            catch
            {
            }
        }
示例#3
0
        public App()
        {
            Dispatcher.UnhandledException         += OnDispatcherUnhandledException;
            TaskScheduler.UnobservedTaskException += OnTaskException;

            Directory.CreateDirectory("UserData");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IConfiguration>(_ => builder.Build());
            ConfigureServices(serviceCollection);
            serviceProvider = serviceCollection.BuildServiceProvider();
            SP.Init(serviceProvider);

            config = SP.GetService <IConfiguration>();
            var workerThreads   = config.GetSection("Resources").GetValue("WorkerThreads", 1000);
            var ioThreads       = config.GetSection("Resources").GetValue("IOThreads", 1000);
            var connectionLimit = config.GetSection("Resources").GetValue("ConnectionLimit", 1000);

            ThreadPool.SetMinThreads(workerThreads, ioThreads);
            ServicePointManager.DefaultConnectionLimit = connectionLimit;

            // Apply DB migrations or create a DB if it doesn't exist
            using (var serviceScope = serviceProvider.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                context.Database.Migrate();
            }

            // Load the configs
            var configService = serviceProvider.GetService <ConfigService>();

            configService.ReloadConfigs().Wait();

            AutocompletionProvider.Init();
        }