private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { try { session.IsAuthenticated = Channel.IsAuthenticated; if (session.IsAuthenticated) { IdentityDecoder decoder = new IdentityDecoder(session.Config.IdentityClaimType, context, session.Config.Indexes); session.Identity = decoder.Id; session.Indexes = decoder.Indexes; UserAuditRecord record = new UserAuditRecord(Channel.Id, session.Identity, session.Config.IdentityClaimType, Channel.TypeId, "MQTT", "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); } adapter = new OrleansAdapter(session.Identity, Channel.TypeId, "MQTT", graphManager, logger); adapter.OnObserve += Adapter_OnObserve; } catch (Exception ex) { logger?.LogErrorAsync(ex, $"MQTT adapter Channel_OnOpen error on channel '{Channel.Id}'.").GetAwaiter(); OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, ex)); } }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { if (!Channel.IsAuthenticated) { OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, new SecurityException("Not authenticated on WSN channel"))); Channel.CloseAsync().Ignore(); return; } adapter = new OrleansAdapter(identity, "WebSocket", "WSN", graphManager); adapter.OnObserve += Adapter_OnObserve; if (subscriptions != null) { foreach (var sub in subscriptions) { SubscriptionMetadata metadata = new SubscriptionMetadata { Identity = identity, Indexes = localIndexes, IsEphemeral = true }; adapter.SubscribeAsync(resource, metadata).GetAwaiter(); } } }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { AuditRecord record = new UserAuditRecord(Channel.Id, identity, config.ClientIdentityNameClaimType, Channel.TypeId, $"REST-{method}", "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); logger?.LogDebugAsync("REST adapter channel is open.").GetAwaiter(); }
private async void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { logger?.LogDebug($"Slave channel '{e.ChannelId} with Id = '{slave.UnitId}' opened."); if (lastMessage != null) { logger?.LogDebug($"Slave channel '{e.ChannelId}' with Id = '{slave.UnitId}' resending last message."); await channel.SendAsync(lastMessage); } logger?.LogDebug($"Slave channel '{e.ChannelId}' with Id = '{slave.UnitId}' receiving."); await channel.ReceiveAsync(); }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { session.IsAuthenticated = Channel.IsAuthenticated; logger?.LogDebugAsync( $"CoAP protocol channel opening with session authenticated '{session.IsAuthenticated}'.").GetAwaiter(); try { if (!Channel.IsAuthenticated && e.Message != null) { CoapMessage msg = CoapMessage.DecodeMessage(e.Message); CoapUri coapUri = new CoapUri(msg.ResourceUri.ToString()); session.IsAuthenticated = session.Authenticate(coapUri.TokenType, coapUri.SecurityToken); logger?.LogDebugAsync( $"CoAP protocol channel opening session authenticated '{session.IsAuthenticated}' by authenticator.") .GetAwaiter(); } if (session.IsAuthenticated) { IdentityDecoder decoder = new IdentityDecoder(session.Config.IdentityClaimType, context, session.Config.Indexes); session.Identity = decoder.Id; session.Indexes = decoder.Indexes; logger?.LogDebugAsync($"CoAP protocol channel opening with session identity '{session.Identity}'.") .GetAwaiter(); UserAuditRecord record = new UserAuditRecord(Channel.Id, session.Identity, session.Config.IdentityClaimType, Channel.TypeId, "COAP", "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); } } catch (Exception ex) { logger?.LogErrorAsync(ex, $"CoAP adapter opening channel '{Channel.Id}'.").GetAwaiter(); OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, ex)); } if (!session.IsAuthenticated && e.Message != null) { logger?.LogWarningAsync("CoAP adpater closing due to unauthenticated user."); Channel.CloseAsync().Ignore(); } else { dispatcher = new CoapRequestDispatcher(session, Channel, config, graphManager, logger); } }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { session.IsAuthenticated = Channel.IsAuthenticated; try { if (!Channel.IsAuthenticated && e.Message != null) { CoapMessage msg = CoapMessage.DecodeMessage(e.Message); CoapUri coapUri = new CoapUri(msg.ResourceUri.ToString()); session.IsAuthenticated = session.Authenticate(coapUri.TokenType, coapUri.SecurityToken); } if (session.IsAuthenticated) { IdentityDecoder decoder = new IdentityDecoder(session.Config.IdentityClaimType, context, session.Config.Indexes); session.Identity = decoder.Id; session.Indexes = decoder.Indexes; UserAuditRecord record = new UserAuditRecord(Channel.Id, session.Identity, session.Config.IdentityClaimType, Channel.TypeId, "COAP", "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); } } catch (Exception ex) { logger?.LogError(ex, $"CoAP adapter opening channel '{Channel.Id}'."); OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, ex)); } if (!session.IsAuthenticated && e.Message != null) { //close the channel logger?.LogInformation($"CoAP adapter user not authenticated; must close channel '{Channel.Id}'."); Channel.CloseAsync().Ignore(); } else { dispatcher = new CoapRequestDispatcher(session, Channel); } }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { if (!Channel.IsAuthenticated) { OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, new SecurityException("Not authenticated on WSN channel"))); Channel.CloseAsync().Ignore(); //shutdown channel immediately return; } //string uriString = HttpUtility.HtmlDecode(UriHelper.GetEncodedUrl(context.Request)); //MessageUri uri = new MessageUri(uriString); //IdentityDecoder decoder = new IdentityDecoder(config.ClientIdentityNameClaimType, context, config.GetClientIndexes()); //identity = decoder.Id; ////resource = uri.Resource; ////indexes = uri.Indexes == null ? null : new List<KeyValuePair<string, string>>(uri.Indexes); //var localIndexes = decoder.Indexes; adapter = new OrleansAdapter(identity, "WebSocket", "WSN", graphManager); adapter.OnObserve += Adapter_OnObserve; if (subscriptions != null) { foreach (var sub in subscriptions) { //subscribe SubscriptionMetadata metadata = new SubscriptionMetadata() { Identity = identity, Indexes = localIndexes, IsEphemeral = true }; adapter.SubscribeAsync(resource, metadata).GetAwaiter(); //SubscribeAsync(sub, metadata).GetAwaiter(); } } }
private async void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { logger?.LogInformation("SCADA client channel is open."); await channel.ReceiveAsync(); }
private static void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { Console.WriteLine("Channel is open"); }
private void Output_OnOpen(object sender, ChannelOpenEventArgs e) { OutputChannel.ReceiveAsync().GetAwaiter(); }
private static async void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { Console.WriteLine("channel open"); await channel.ReceiveAsync(); }
private static void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { Console.WriteLine("Channel is open"); channel.ReceiveAsync(); ican = true; }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs args) { }
private static void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Channel '{e.ChannelId}' is open"); Console.ResetColor(); }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { logger?.LogInformation($"Channel {address}:{port} '{e.ChannelId}' open."); }
private void Channel_OnOpen(object sender, ChannelOpenEventArgs e) { if (!Channel.IsAuthenticated) //requires channel authentication { OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, new SecurityException("Not authenticated."))); Channel.CloseAsync().Ignore(); return; } if (e.Message.Method != HttpMethod.Post && e.Message.Method != HttpMethod.Get) { Channel.CloseAsync().Ignore(); OnError?.Invoke(this, new ProtocolAdapterErrorEventArgs(Channel.Id, new SecurityException("Rest protocol adapter requires GET or POST only."))); } MessageUri uri = new MessageUri(e.Message); IdentityDecoder decoder = new IdentityDecoder(config.ClientIdentityNameClaimType, context, config.GetClientIndexes()); identity = decoder.Id; adapter = new OrleansAdapter(decoder.Id, "HTTP", "REST"); adapter.OnObserve += Adapter_OnObserve; HttpRequestMessage request = (HttpRequestMessage)e.Message; AuditRecord record = new UserAuditRecord(Channel.Id, identity, config.ClientIdentityNameClaimType, Channel.TypeId, String.Format("REST-{0}", request.Method.ToString()), "Granted", DateTime.UtcNow); userAuditor?.WriteAuditRecordAsync(record).Ignore(); if (request.Method == HttpMethod.Get) { foreach (var item in uri.Subscriptions) { Task t = Task.Factory.StartNew(async() => { await SubscribeAsync(item, decoder.Id, decoder.Indexes); }); t.LogExceptions(); } } if (request.Method == HttpMethod.Post) { byte[] buffer = request.Content.ReadAsByteArrayAsync().Result; Task t = Task.Factory.StartNew(async() => { EventMetadata metadata = await GraphManager.GetPiSystemMetadataAsync(uri.Resource); EventMessage message = new EventMessage(uri.ContentType, uri.Resource, ProtocolType.REST, buffer, DateTime.UtcNow, metadata.Audit); if (!string.IsNullOrEmpty(uri.CacheKey)) { message.CacheKey = uri.CacheKey; } List <KeyValuePair <string, string> > indexList = uri.Indexes == null ? null : new List <KeyValuePair <string, string> >(uri.Indexes); await PublishAsync(decoder.Id, message, indexList); await Channel.CloseAsync(); }); t.LogExceptions(); } }
private void Input_OnOpen(object sender, ChannelOpenEventArgs e) { logger?.LogInformation("Input channel open."); InputChannel.ReceiveAsync().GetAwaiter(); logger?.LogDebug("Input channel receiving."); }