Esempio n. 1
0
		//Message responses are dispatched right after requests with this strategy. This is much different
		//than what is normally found in GladNet2 implementations.
		/// <summary>
		/// Creates a new <see cref="IWebRequestEnqueueStrategy"/> that handles requests on the calling thread
		/// and blocks.
		/// </summary>
		/// <param name="baseURL">Base string for the end-poind webserver. (Ex. www.google.com/)</param>
		/// <param name="deserializationService">Deserialization strategy for responses.</param>
		/// <param name="responseReciever">Message receiver service for dispatching recieved resposne messages.</param>
		public RestSharpCurrentThreadEnqueueRequestHandlerStrategy(string baseURL, IDeserializerStrategy deserializationService, ISerializerStrategy serializerStrategy, INetworkMessageReceiver responseReciever, int connectionAUID
#if !ENDUSER
			, INetworkMessageRouteBackService routebackService) //unfortunaly the single-threaded blocking enqueue strat needs the routeback service to function.
#endif
		{
			if (String.IsNullOrEmpty(baseURL))
				throw new ArgumentException($"Parameter {baseURL} is not valid. Either null or empty. Base URL must be the base URL of the web server. (Ex. www.google.com)");

			if (deserializationService == null)
				throw new ArgumentNullException(nameof(baseURL), $"Parameter {deserializationService} must not be null. Deserialization for incoming responses is required.");
#if !ENDUSER
			if (routebackService == null)
				throw new ArgumentNullException(nameof(routebackService), $"{nameof(RestSharpCurrentThreadEnqueueRequestHandlerStrategy)} requires {(nameof(INetworkMessageRouteBackService))} as it handles responses too.");
#endif
			serializer = serializerStrategy;
			deserializer = deserializationService;
			responseMessageRecieverService = responseReciever;

			restsharpMiddlewares = new List<IRestSharpMiddleWare>(2);

			ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
			System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

			httpClient = new RestClient(baseURL) { Timeout = 15000 };

#if !ENDUSER
			messageRoutebackService = routebackService;
#endif
		}
		public override bool TryDispatch(INetworkMessageReceiver reciever)
		{
			if (GeneratedNetworkMessage == null)
				return false;

			GeneratedNetworkMessage.Dispatch(reciever, this); //pass the reciever and this (message parameters).

			return true;
		}
		public override bool TryDispatch(INetworkMessageReceiver reciever)
		{
			if (GeneratedStatusMessage == null)
				return false;

			reciever.OnNetworkMessageReceive(GeneratedStatusMessage, this); //pass to the reciever the message and this (message parameters)

			return true;
		}
Esempio n. 4
0
        /// <summary>
        /// Dispatches the <see cref="EventMessage"/> (this) to the supplied <see cref="INetworkMessageReceiver"/>.
        /// </summary>
        /// <param name="receiver">The target <see cref="INetworkMessageReceiver"/>.</param>
        /// <exception cref="ArgumentNullException">Throws if either parameters are null.</exception>
        /// <param name="parameters">The <see cref="IMessageParameters"/> of the <see cref="EventMessage"/>.</param>
        public override void Dispatch(INetworkMessageReceiver receiver, IMessageParameters parameters)
        {
            Throw<ArgumentNullException>.If.IsNull(receiver)
                ?.Now(nameof(receiver), $"{nameof(INetworkMessageReceiver)} parameter is null in {this.GetType().Name}");

            Throw<ArgumentNullException>.If.IsNull(parameters)
                ?.Now(nameof(parameters), $"{nameof(IMessageParameters)} parameter is null in {this.GetType().Name}");

            receiver.OnNetworkMessageReceive(this, parameters);
        }
Esempio n. 5
0
        public override bool TryDispatch(INetworkMessageReceiver reciever)
        {
            if (GeneratedNetworkMessage == null)
            {
                return(false);
            }

            GeneratedNetworkMessage.Dispatch(reciever, this);             //pass the reciever and this (message parameters).

            return(true);
        }
		public GladNetClientPeer(InitRequest request, 
			INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, IDisconnectionServiceHandler disconnectionService)
			: base(request)
		{
			Throw<ArgumentNullException>.If.IsNull(reciever)?.Now(nameof(reciever));
			Throw<ArgumentNullException>.If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat));
			Throw<ArgumentNullException>.If.IsNull(disconnectionService)?.Now(nameof(disconnectionService));

			disconnectionServiceHandler = disconnectionService;
			networkReciever = reciever;
			deserializer = deserializationStrat;
		}
        public GladNetInboundS2SPeer(InitResponse response, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat,
                                     IDisconnectionServiceHandler disconnectionService)
            : base(response)
        {
            Throw <ArgumentNullException> .If.IsNull(reciever)?.Now(nameof(reciever));

            Throw <ArgumentNullException> .If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat));

            Throw <ArgumentNullException> .If.IsNull(disconnectionService)?.Now(nameof(disconnectionService));

            disconnectionServiceHandler = disconnectionService;
            networkReciever             = reciever;
            deserializer = deserializationStrat;
        }
        public override bool TryDispatch(INetworkMessageReceiver reciever)
        {
            if (reciever == null)
            {
                throw new ArgumentNullException(nameof(reciever));
            }
            if (GeneratedStatusMessage == null)
            {
                return(false);
            }

            reciever.OnNetworkMessageReceive(GeneratedStatusMessage, this);             //pass to the reciever the message and this (message parameters)

            return(true);
        }
		public GladNetOutboundS2SPeer(GladNetAppBase appBase, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat, 
			IDisconnectionServiceHandler disconnectionService)
				: base(appBase)
		{
			Throw<ArgumentNullException>.If.IsNull(appBase)?.Now(nameof(appBase));
			Throw<ArgumentNullException>.If.IsNull(reciever)?.Now(nameof(reciever));
			Throw<ArgumentNullException>.If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat));
			Throw<ArgumentNullException>.If.IsNull(disconnectionService)?.Now(nameof(disconnectionService));

			disconnectionServiceHandler = disconnectionService;
			networkReciever = reciever;
			deserializer = deserializationStrat;

			//Publish that we are connecting
			networkReciever.OnNetworkMessageReceive(new PhotonStatusMessageAdapter(NetStatus.Connecting), null);
		}
        public ClientSessionServiceContext(INetworkMessageRouterService sendService, INetworkMessageReceiver messageReceiver, INetPeer client)
        {
            if (sendService == null)
            {
                throw new ArgumentNullException(nameof(sendService));
            }
            if (messageReceiver == null)
            {
                throw new ArgumentNullException(nameof(messageReceiver));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            SendService     = sendService;
            MessageReceiver = messageReceiver;
            ClientNetPeer   = client;
        }
Esempio n. 11
0
        public GladNetOutboundS2SPeer(GladNetAppBase appBase, INetworkMessageReceiver reciever, IDeserializerStrategy deserializationStrat,
                                      IDisconnectionServiceHandler disconnectionService)
            : base(appBase)
        {
            Throw <ArgumentNullException> .If.IsNull(appBase)?.Now(nameof(appBase));

            Throw <ArgumentNullException> .If.IsNull(reciever)?.Now(nameof(reciever));

            Throw <ArgumentNullException> .If.IsNull(deserializationStrat)?.Now(nameof(deserializationStrat));

            Throw <ArgumentNullException> .If.IsNull(disconnectionService)?.Now(nameof(disconnectionService));

            disconnectionServiceHandler = disconnectionService;
            networkReciever             = reciever;
            deserializer = deserializationStrat;

            //Publish that we are connecting
            networkReciever.OnNetworkMessageReceive(new PhotonStatusMessageAdapter(NetStatus.Connecting), null);
        }
 public abstract bool TryDispatch(INetworkMessageReceiver reciever);
		public ClientSessionServiceContext(INetworkMessageRouterService sendService, INetworkMessageReceiver messageReceiver, INetPeer client)
		{
			SendService = sendService;
			MessageReceiver = messageReceiver;
			ClientNetPeer = client;
		}
		public abstract bool TryDispatch(INetworkMessageReceiver reciever);