public OM2MCseServiceImpl(OM2MCseConfig cseConfig) { CseConfig = cseConfig; m_cseBasePattern = new Regex($"^/{Regex.Escape(CseConfig.CseBaseId)}$"); m_acpPattern = new Regex($"^/{Regex.Escape(CseConfig.CseBaseId)}/acp-{IdPattern}$"); m_aePattern = new Regex($"^(?:/{Regex.Escape(CseConfig.CseBaseId)}/C{IdPattern})|(?:/S{IdPattern})$"); m_cntPattern = new Regex($"^/{Regex.Escape(CseConfig.CseBaseId)}/cnt-{IdPattern}$"); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); CseConfig = new OM2MCseConfig(); CseConfig.CseBaseId = "in-cse"; CseConfig.CseBaseName = "in-cse"; CseConfig.CseType = OM2MCseTypeID.InCSE; CseService = new OM2MCseServiceImpl(CseConfig); CseService.Initialize(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseWebSockets(); app.Use(async(http, next) => { string org = "guest:guest"; Microsoft.Extensions.Primitives.StringValues vals; if (http.Request.Query.TryGetValue("org", out vals)) { org = vals[0]; } if (http.WebSockets.IsWebSocketRequest) { var webSocket = await http.WebSockets.AcceptWebSocketAsync(); var originator = new OM2MOriginatorWebSocket(CseService, org, webSocket); while (webSocket.State == WebSocketState.Open) { var token = CancellationToken.None; var buffer = new ArraySegment <Byte>(new byte[64 * 1024]); var received = await webSocket.ReceiveAsync(buffer, token); try { switch (received.MessageType) { case WebSocketMessageType.Text: var message = Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count); await originator.ProcessMessageAsync(message); break; } } catch (Exception ex) { Console.Error.WriteLine(ex); } } } else { await next(); } }); app.Run(async(context) => { await context.Response.WriteAsync("Hello World!"); }); }