Esempio n. 1
0
        //prevents inherting from this class: http://stackoverflow.com/questions/1244953/internal-abstract-class-how-to-hide-usage-outside-assembly
        internal GladNetAppBase()
            : base()
        {
            //sets up logging
            AppLogger = SetupLogging();             //needed for the services below

            //These new services are required for the GladNet2 2.x routeback feature
            auidMapService   = new AUIDServiceCollection <INetPeer>(100);
            routebackService = new DefaultNetworkMessageRouteBackService(auidMapService, AppLogger);
        }
		//prevents inherting from this class: http://stackoverflow.com/questions/1244953/internal-abstract-class-how-to-hide-usage-outside-assembly
		internal GladNetAppBase()
			: base()
		{
			//sets up logging
			AppLogger = SetupLogging(); //needed for the services below

			//These new services are required for the GladNet2 2.x routeback feature
			auidMapService = new AUIDServiceCollection<INetPeer>(100);
			routebackService = new DefaultNetworkMessageRouteBackService(auidMapService, AppLogger);
		}
Esempio n. 3
0
        /// <inheritdoc />
        public ClientPeerSession Create(IConnectionDetails connectionDetails, NetConnection connection)
        {
            if (connectionDetails == null)
            {
                throw new ArgumentNullException(nameof(connectionDetails));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            //Build the message router service
            LidgrenNetworkMessageRouterService    routerService         = new LidgrenServerNetworkMessageRouterService(new LidgrenNetworkMessageFactory(), connection, Serializer);
            NetworkMessagePublisher               basicMessagePublisher = new NetworkMessagePublisher();
            DefaultNetworkMessageRouteBackService routebackService      = new DefaultNetworkMessageRouteBackService(NetPeerAUIDService, PeerLogger);
            DefaultDisconnectionServiceHandler    disconnectionHandler  = new DefaultDisconnectionServiceHandler();

            //TODO: Clean this up
            disconnectionHandler.DisconnectionEventHandler += () => PeerServiceCollection.Remove(connectionDetails.ConnectionID);

            //Try to create the incoming peer; consumers of the library may reject the connection.
            ClientPeerSession session = ManagedSessionFactory.CreateIncomingPeerSession(routerService, connectionDetails, basicMessagePublisher, disconnectionHandler, routebackService);

            if (session == null)
            {
                return(null);
            }

            if (session.PeerDetails.ConnectionID == 0)
            {
                throw new InvalidOperationException("Generated peer has an unset connection ID.");
            }

            //Create a service context for the server.
            ClientSessionServiceContext serviceContext = new ClientSessionServiceContext(routerService, basicMessagePublisher, session);

            //Enter AUID lock
            PeerServiceCollection.syncObj.EnterWriteLock();
            try
            {
                PeerServiceCollection.Add(session.PeerDetails.ConnectionID, serviceContext);
            }
            finally
            {
                PeerServiceCollection.syncObj.ExitWriteLock();
            }

            return(session);
        }