public ConsoleServer(Uri listenerUri) { _serverNode = new Node() { Name = "server", Domain = "limeprotocol.org", Instance = Environment.MachineName }; _listenerUri = listenerUri; _serverConnectedNodesDictionary = new Dictionary<Guid, IServerChannel>(); _identityInstanceSessionIdDictionary = new Dictionary<Identity, IDictionary<string, Guid>>(); _identityPasswordDictionary = new Dictionary<Identity, string> { { Identity.Parse("*****@*****.**") , "123456" }, { Identity.Parse("*****@*****.**") , "abcdef" }, { Identity.Parse("*****@*****.**") , "654321" }, { Identity.Parse("*****@*****.**") , "minerals" }, }; }
/// <summary> /// Tries to parse the string to a valid Node /// </summary> /// <param name="s">The s.</param> /// <param name="value">The value.</param> /// <returns></returns> public static bool TryParse(string s, out Node value) { try { value = Parse(s); return true; } catch { value = null; return false; } }
private async Task RegisterChannel(IServerChannel channel, Node node, CancellationToken cancellationToken) { IDictionary<string, Guid> instanceSessionDictionary; if (!_identityInstanceSessionIdDictionary.TryGetValue(node.ToIdentity(), out instanceSessionDictionary)) { instanceSessionDictionary = new Dictionary<string, Guid>(); _identityInstanceSessionIdDictionary.Add(node.ToIdentity(), instanceSessionDictionary); } instanceSessionDictionary.Add(node.Instance, channel.SessionId); await channel.SendEstablishedSessionAsync(node); var receiveMessageTask = this.ReceiveMessagesAsync(channel, cancellationToken); await channel.ReceiveFinishingSessionAsync(cancellationToken); await channel.SendFinishedSessionAsync(); instanceSessionDictionary.Remove(node.Instance); if (instanceSessionDictionary.Count == 0) { _identityInstanceSessionIdDictionary.Remove(node.ToIdentity()); } }
public Task SendTextMessageAsync(Node to, string text) { var message = new Message() { To = to, Content = new PlainText() { Text = text } }; return Channel.SendMessageAsync(message); }