Beispiel #1
0
 /*
  * public HomeController( ) {
  *  Console.WriteLine( "HomeController zonder parameter ");
  *  _service = new GpibService() ;
  * }
  */
 /*
  * public HomeController( IGpibService service ) {
  *  Console.WriteLine( "HomeController met IGpibService");
  *  _service = service ;
  *
  * }
  */
 // public HomeController(ILogger<HomeController> logger, IGpibService service, GpibContext db)
 public HomeController(ILogger <HomeController> logger, IGpibService service, GpibContext db)
 {
     Console.WriteLine("HomeController met ILogger en IGpibService en GpibContext");
     _db      = db;
     _logger  = logger;
     _service = service;
     // Console.WriteLine("TESTJE: " + service.dbConnection());
     _service.wsSendToAll("Dit is HomeController");
 }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IGpibService service)
        {
            Console.WriteLine("Configure");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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();
            }
            // app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            Console.WriteLine("add.UseWebSockets() ;");

            app.UseWebSockets();


            // Handle http upgrades to ws
            app.Use(async(context, next) =>
            {
                // A websocket endpoint in the application is /ws
                if (context.Request.Path == "/ws")
                {
                    // Check if the request is indead a Websocketrequest
                    if (context.WebSockets.IsWebSocketRequest)
                    {
                        // Do the ws-handshake to accept the connection
                        using (WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync())
                        {
                            // Generate a Unique Connection Id for administration purposes
                            var wsConnectionId = Guid.NewGuid();
                            // Register the connection Id
                            wsConnections.Add(wsConnectionId, webSocket);

                            // Console.WriteLine("New WebSocket client. Connection Id: " + wsConnectionId);

                            // Each connection has it's own Echo space
                            Console.WriteLine("Create here dhe await Echo....");
                            await service.Echo(webSocket, wsConnections);
                            // await Echo(context, webSocket);
                        }
                    }
                    else
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else
                {
                    // Pass to the next in the pipeline
                    await next();
                }
            });

            Console.WriteLine("ALLEEN NU GPIB  DEVICE STARTEN");
            service.AddGpibDevice(wsConnections);
            Console.WriteLine("GPIB  DEVICE IS NU GESTART IN BACKGROUND");

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