private void ConfigureIoC() { Container = new WindsorContainer(); var documentStore = new EmbeddableDocumentStore { DataDirectory = "../data" }; documentStore.Initialize(); var connectionLookup = new ConnectionLookup(); var taskNotifier = new TaskNotifier(connectionLookup); var queueFactory = new DefaultQueueFactory(taskNotifier, documentStore); var userAccountService = new DummyUserAccountService(); var taskDistributor = new TaskDistributor(queueFactory, userAccountService); sessionTimeoutEventSink = taskDistributor; Container.Register(Component.For <IDocumentStore>().Instance(documentStore).LifestyleSingleton()); Container.Register(Component.For <INotifyUsersOfTasks>().Instance(taskNotifier).LifestyleSingleton()); Container.Register(Component.For <TaskDistributor, IReactToUserLoggedIn, IReactToUserLoggedOff>().Instance(taskDistributor).LifestyleSingleton()); Container.Register(Component.For <IControllerFactory>() .Instance(new MyControllerFactory(Container)) .LifeStyle.Is(Castle.Core.LifestyleType.Singleton)); Container.Register(AllTypes.FromThisAssembly().BasedOn <IController>().LifestyleTransient()); GlobalHost.DependencyResolver.Register(typeof(TaskDistributor), () => taskDistributor); GlobalHost.DependencyResolver.Register(typeof(ConnectionLookup), () => connectionLookup); GlobalHost.DependencyResolver.Register(typeof(IBus), () => Bus); GlobalHost.DependencyResolver.Register(typeof(UserTaskEndpoint), () => new UserTaskEndpoint(taskDistributor, connectionLookup, Bus)); }
/// <summary> /// Tries to get the connection for a certain remote endpoint. /// </summary> public bool TryGetConnection( IPEndPoint endPoint, [MaybeNullWhen(false)] out NetConnection?connection) { Debug.Assert(endPoint != null); return(ConnectionLookup.TryGetValue(endPoint, out connection)); }
/// <summary> /// Create a connection to a remote endpoint. /// </summary> public virtual NetConnection Connect(IPEndPoint remoteEndPoint, NetOutgoingMessage?hailMessage) { if (remoteEndPoint == null) { throw new ArgumentNullException(nameof(remoteEndPoint)); } if (Configuration.DualStack) { remoteEndPoint = NetUtility.MapToIPv6(remoteEndPoint); } if (Status == NetPeerStatus.NotRunning) { throw new LidgrenException("Must call Start() first."); } if (ConnectionLookup.ContainsKey(remoteEndPoint)) { throw new LidgrenException("Already connected to that endpoint!"); } if (Handshakes.TryGetValue(remoteEndPoint, out NetConnection? hs)) { // already trying to connect to that endpoint; make another try switch (hs.Status) { case NetConnectionStatus.InitiatedConnect: // send another connect hs._connectRequested = true; break; case NetConnectionStatus.RespondedConnect: // send another response hs.SendConnectResponse(NetTime.Now, false); break; default: // weird LogWarning(NetLogMessage.FromValues(NetLogCode.UnexpectedHandshakeStatus, value: (int)hs.Status)); break; } return(hs); } var conn = new NetConnection(this, remoteEndPoint); conn.Status = NetConnectionStatus.InitiatedConnect; conn.LocalHailMessage = hailMessage; // handle on network thread conn._connectRequested = true; conn._connectionInitiator = true; Handshakes.TryAdd(remoteEndPoint, conn); return(conn); }
public bool AddConnection([NotNull] IConnection connection) { if (ConnectionLookup.ContainsKey(connection.Guid)) { return(false); } ConnectionLookup.Add(connection.Guid, connection); return(true); }
public IConnection FindConnection(Guid guid) { if (ConnectionLookup.TryGetValue(guid, out var connection)) { return(connection); } Log.Diagnostic($"Could not find connection {guid}."); return(null); }
public void Dispose() { lock (this) { if (mDisposed) { return; } mDisposed = true; } if (!Disconnect(NetworkStatus.Quitting.ToString())) { Log.Error("Error disconnecting while disposing."); } mNetworkLayerInterfaces?.ForEach(networkLayerInterface => networkLayerInterface?.Dispose()); ConnectionLookup.Clear(); }
public bool RemoveConnection([NotNull] IConnection connection) { return(!connection.IsConnected && ConnectionLookup.Remove(connection.Guid)); }
public bool RemoveConnection(IConnection connection) => !connection.IsConnected && ConnectionLookup.Remove(connection.Guid);