public HttpInputConnector(string httpAddress, IProtocolFormatter protocolFormatter, int responseReceiverInactivityTimeout)
        {
            using (EneterTrace.Entering())
            {
                Uri aUri;
                try
                {
                    // just check if the channel id is a valid Uri
                    aUri = new Uri(httpAddress);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(httpAddress + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }
                myHttpListenerProvider = new HttpWebServer(aUri.AbsoluteUri);

                myProtocolFormatter = protocolFormatter;
                myResponseReceiverInactivityTimeout = responseReceiverInactivityTimeout;


                // Initialize the timer to regularly check the timeout for connections with duplex output channels.
                // If the duplex output channel did not poll within the timeout then the connection
                // is closed and removed from the list.
                // Note: The timer is set here but not executed.
                myResponseReceiverInactivityTimer = new Timer(OnConnectionCheckTimer, null, -1, -1);
            }
        }
Example #2
0
        public WebSocketOutputConnector(string inputConnectorAddress, string outputConnectorAddress, IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory,
                                        int connectTimeout,
                                        int sendTimeout,
                                        int receiveTimeout,
                                        int pingFrequency,
                                        int responseReceivingPort)
        {
            using (EneterTrace.Entering())
            {
                Uri aUri;
                try
                {
                    aUri = new Uri(inputConnectorAddress, UriKind.Absolute);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(inputConnectorAddress + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }

                myClient = new WebSocketClient(aUri, clientSecurityFactory);
                myClient.ResponseReceivingPort = responseReceivingPort;

                myOutputConnectorAddress = outputConnectorAddress;
                myProtocolFormatter      = protocolFormatter;
                myClient.ConnectTimeout  = connectTimeout;
                myClient.SendTimeout     = sendTimeout;
                myClient.ReceiveTimeout  = receiveTimeout;

                myPingFrequency = pingFrequency;
                myTimer         = new Timer(OnPing, null, -1, -1);
            }
        }
Example #3
0
        public TcpInputConnector(string ipAddressAndPort, IProtocolFormatter protocolFormatter, ISecurityFactory securityFactory,
                                 int sendTimeout,
                                 int receiveTimeout,
                                 int sendBuffer,
                                 int receiveBuffer,
                                 bool reuseAddressFlag,
                                 int maxAmountOfConnections)
        {
            using (EneterTrace.Entering())
            {
                Uri aUri;
                try
                {
                    aUri = new Uri(ipAddressAndPort);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(ipAddressAndPort + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }

                int aPort = (aUri.Port < 0) ? 0 : aUri.Port;
                myTcpListenerProvider   = new TcpListenerProvider(IPAddress.Parse(aUri.Host), aPort, reuseAddressFlag, maxAmountOfConnections);
                myProtocolFormatter     = protocolFormatter;
                mySecurityStreamFactory = securityFactory;
                mySendTimeout           = sendTimeout;
                myReceiveTimeout        = receiveTimeout;
                mySendBuffer            = sendBuffer;
                myReceiveBuffer         = receiveBuffer;

                // Check if protocol encodes open and close messages.
                myProtocolUsesOpenConnectionMessage = myProtocolFormatter.EncodeOpenConnectionMessage("test") != null;
            }
        }
Example #4
0
 /// <summary>
 /// Constructs the factory.
 /// </summary>
 /// <param name="protocolFormatter">formatter used to encode low-level messages between channels</param>
 public ThreadPoolMessagingSystemFactory(IProtocolFormatter protocolFormatter)
 {
     using (EneterTrace.Entering())
     {
         myDefaultMessagingFactory = new DefaultMessagingSystemFactory(new ThreadPoolMessagingProvider(), protocolFormatter);
     }
 }
        public UdpInputConnector(string ipAddressAndPort, IProtocolFormatter protocolFormatter, bool reuseAddress, short ttl,
                                 int maxAmountOfConnections)
        {
            using (EneterTrace.Entering())
            {
                if (string.IsNullOrEmpty(ipAddressAndPort))
                {
                    EneterTrace.Error(ErrorHandler.NullOrEmptyChannelId);
                    throw new ArgumentException(ErrorHandler.NullOrEmptyChannelId);
                }

                Uri anServiceUri;
                try
                {
                    // just check if the address is valid
                    anServiceUri = new Uri(ipAddressAndPort, UriKind.Absolute);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(ipAddressAndPort + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }

                myServiceEndpoint   = new IPEndPoint(IPAddress.Parse(anServiceUri.Host), anServiceUri.Port);
                myProtocolFormatter = protocolFormatter;
                myReuseAddressFlag  = reuseAddress;
                myTtl = ttl;
                myMaxAmountOfConnections = maxAmountOfConnections;
            }
        }
        public WebSocketInputConnector(string wsUriAddress, IProtocolFormatter protocolFormatter, ISecurityFactory securityFactory, int sendTimeout, int receiveTimeout,
                                       bool reuseAddressFlag,
                                       int maxAmountOfConnections)
        {
            using (EneterTrace.Entering())
            {
                Uri aUri;
                try
                {
                    aUri = new Uri(wsUriAddress);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(wsUriAddress + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }

                myProtocolFormatter           = protocolFormatter;
                myListener                    = new WebSocketListener(aUri, securityFactory);
                myListener.ReuseAddress       = reuseAddressFlag;
                myListener.MaxAmountOfClients = maxAmountOfConnections;

                mySendTimeout    = sendTimeout;
                myReceiveTimeout = receiveTimeout;

                // Check if protocol encodes open and close messages.
                myProtocolUsesOpenConnectionMessage = myProtocolFormatter.EncodeOpenConnectionMessage("test") != null;
            }
        }
 /// <summary>
 /// Constructs the factory representing the messaging system.
 /// </summary>
 /// <param name="protocolFormatter">formatter used to encode low-level messages between channels</param>
 public SynchronousMessagingSystemFactory(IProtocolFormatter protocolFormatter)
 {
     using (EneterTrace.Entering())
     {
         myDefaultMessagingFactory = new DefaultMessagingSystemFactory(new SynchronousMessagingProvider(), protocolFormatter);
     }
 }
        public TcpOutputConnector(string ipAddressAndPort, string outputConnectorAddress, IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory,
                                  int connectTimeout, int sendTimeout, int receiveTimeout, int sendBuffer, int receiveBuffer,
                                  bool reuseAddressFlag,
                                  int responseReceivingPort)
        {
            using (EneterTrace.Entering())
            {
                try
                {
                    myUri = new Uri(ipAddressAndPort, UriKind.Absolute);
                }
                catch (Exception err)
                {
                    EneterTrace.Error(ipAddressAndPort + ErrorHandler.InvalidUriAddress, err);
                    throw;
                }

                myOutputConnectorAddress = outputConnectorAddress;
                myClientSecurityFactory  = clientSecurityFactory;
                myProtocolFormatter      = protocolFormatter;
                myConnectTimeout         = (connectTimeout != 0) ? connectTimeout : -1;
                mySendTimeout            = sendTimeout;
                myReceiveTimeout         = receiveTimeout;
                mySendBuffer             = sendBuffer;
                myReceiveBuffer          = receiveBuffer;
                myReuseAddressFlag       = reuseAddressFlag;
                myResponseReceivingPort  = responseReceivingPort;
            }
        }
Example #9
0
 public HttpOutputConnectorFactory(IProtocolFormatter protocolFormatter, int pollingFrequency)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter = protocolFormatter;
         myPollingFrequency  = pollingFrequency;
     }
 }
Example #10
0
 public HttpInputConnectorFactory(IProtocolFormatter protocolFormatter, int responseReceiverInactivityTimeout)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter = protocolFormatter;
         myOutputConnectorInactivityTimeout = responseReceiverInactivityTimeout;
     }
 }
Example #11
0
 public DefaultInputConnectorFactory(IMessagingProvider messagingProvider, IProtocolFormatter protocolFormatter)
 {
     using (EneterTrace.Entering())
     {
         myMessagingProvider = messagingProvider;
         myProtocolFormatter = protocolFormatter;
     }
 }
 /// <summary>
 /// Constructs the messaging which communicates with Android via the USB cable.
 /// </summary>
 /// <remarks>
 /// The adb service typically starts automatically when you connect the Android device via the USB cable.
 /// </remarks>
 /// <param name="adbHostPort">Port where adb service is listening to commands. Default value is 5037.</param>
 /// <param name="protocolFormatter">Low level formatting used for encoding messages between channels.
 /// EneterProtocolFormatter() can be used by default.
 /// </param>
 public AndroidUsbCableMessagingFactory(int adbHostPort, IProtocolFormatter protocolFormatter)
 {
     using (EneterTrace.Entering())
     {
         myAdbHostPort            = adbHostPort;
         myUnderlyingTcpMessaging = new TcpMessagingSystemFactory(protocolFormatter);
     }
 }
 public DefaultInputConnector(string inputConnectorAddress, IMessagingProvider messagingProvider, IProtocolFormatter protocolFormatter)
 {
     using (EneterTrace.Entering())
     {
         myInputConnectorAddress = inputConnectorAddress;
         myMessagingProvider     = messagingProvider;
         myProtocolFormatter     = protocolFormatter;
     }
 }
Example #14
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
#if FULL_BUILD
            // write object and try to cache output if applicable
            Cache.WriteAndSave(((BodyHolder)obj).body, formatter);
#else
            MessageWriter.writeObject(((BodyHolder)obj).body, formatter);
#endif
        }
 public NamedPipeConnectorFactory(IProtocolFormatter protocolFormatter, int connectionTimeout, int numberOfListeningInstances, PipeSecurity security)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter          = protocolFormatter;
         myConnectionTimeout          = connectionTimeout;
         myNumberOfListeningInstances = numberOfListeningInstances;
         mySecurity = security;
     }
 }
 public NamedPipeInputConnector(string inputConnectorAddress, IProtocolFormatter protocolFormatter, int connectionTimeout, int numberOfListeningInstances, PipeSecurity security)
 {
     using (EneterTrace.Entering())
     {
         myInputConnectorAddress = inputConnectorAddress;
         myProtocolFormatter = protocolFormatter;
         myConnectionTimeout = connectionTimeout;
         myNumberOfListeningInstances = numberOfListeningInstances;
         mySecurity = security;
     }
 }
Example #17
0
        public static void SerializeResponse(Request message, Stream stream)
        {
            IProtocolFormatter formatter = message.GetFormatter();

            MessageWriter.writeObject(message, formatter);
            ProtocolBytes protocolBytes = formatter.GetBytes();

            formatter.Cleanup();
            stream.Write(protocolBytes.bytes, 0, protocolBytes.length);
            stream.Flush();
        }
 public NamedPipeOutputConnector(string inputConnectorAddress, string outputConnectorAddress, IProtocolFormatter protocolFormatter, int timeOut, PipeSecurity security)
 {
     using (EneterTrace.Entering())
     {
         myInputConnectorAddress  = inputConnectorAddress;
         myOutputConnectorAddress = outputConnectorAddress;
         myProtocolFormatter      = protocolFormatter;
         myTimeout  = timeOut;
         mySecurity = security;
     }
 }
Example #19
0
 public SharedMemoryConnectorFactory(IProtocolFormatter protocolFormatter, TimeSpan connectTimeout, TimeSpan sendTimeout, int maxMessageSize, MemoryMappedFileSecurity memoryMappedFileSecurity)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter = protocolFormatter;
         myConnectTimeout    = connectTimeout;
         mySendTimeout       = sendTimeout;
         myMaxMessageSize    = maxMessageSize;
         mySecurity          = memoryMappedFileSecurity;
     }
 }
        /// <summary>
        /// Constructs the factory specifying the number of processing threads in the input channel and the timeout
        /// for the output channel. It also allows to specify the security settings for the pipe.
        /// </summary>
        /// <remarks>
        /// Security settings can be needed, if communicating processes run under different integrity levels.
        /// E.g. If the service runs under administrator account and the client under some user account,
        /// then the communication will not work until the pipe security is not set.
        /// (Client will get access denied exception.)
        /// <example>
        /// The following example shows how to set the pipe security on the service running under administrator
        /// account to be accessible from client processes.
        /// <code>
        /// PipeSecurity aPipeSecurity = new PipeSecurity();
        ///
        /// // Set to low integrity level.
        /// aPipeSecurity.SetSecurityDescriptorSddlForm("S:(ML;;NW;;;LW)");
        ///
        /// SecurityIdentifier aSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
        /// ipeAccessRule aPipeAccessRule = new PipeAccessRule(aSid, PipeAccessRights.ReadWrite, AccessControlType.Allow);
        /// aPipeSecurity.AddAccessRule(aPipeAccessRule);
        ///
        /// // Create the messaging communicating via Named Pipes.
        /// IMessagingSystemFactory aMessagingSystem = new NamedPipeMessagingSystemFactory(10, 10000, aPipeSecurity);
        /// </code>
        /// </example>
        /// </remarks>
        /// <param name="numberOfPipeInstances">
        /// Number of clients that can be connected at the same time.
        /// The maximum number is 254. Many threads can increase the number of processing connections at the same time
        /// but it consumes a lot of resources.
        /// </param>
        /// <param name="pipeConnectionTimeout">
        /// The maximum time in miliseconds, the output channel waits to connect the pipe and sends the message.</param>
        /// <param name="protocolFormatter">formatter of low-level messages between channels</param>
        /// <param name="pipeSecurity">
        /// Pipe security.
        /// </param>
        public NamedPipeMessagingSystemFactory(int numberOfPipeInstances, int pipeConnectionTimeout,
                                               IProtocolFormatter protocolFormatter,
                                               PipeSecurity pipeSecurity)
        {
            using (EneterTrace.Entering())
            {
                myConnectorFactory = new NamedPipeConnectorFactory(protocolFormatter, pipeConnectionTimeout, numberOfPipeInstances, pipeSecurity);

                InputChannelThreading  = new SyncDispatching();
                OutputChannelThreading = InputChannelThreading;
            }
        }
 public void write(Object obj, IProtocolFormatter iProtocolFormatter)
 {
     try
     {
         Geometry geometry = (Geometry)obj;
         MessageWriter.writeObject(geometry.AsWKT(), iProtocolFormatter);
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #22
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            BackendlessUser user = (BackendlessUser)obj;

            Dictionary <string, object> props = user.Properties;

            if (!props.ContainsKey("___class"))
            {
                props.Add("___class", "Users");
            }

            MessageWriter.writeObject(props, writer);
        }
Example #23
0
        /// <summary>
        /// Constructs the factory that will create channel with specified settings.
        /// </summary>
        /// <remarks>
        /// The polling frequency and the inactivity time are used only by duplex channels.
        /// The polling frequency specifies how often the duplex output channel checks if there are pending response messages.
        /// The inactivity time is measured by the duplex input channel and specifies the maximum time, the duplex output channel
        /// does not have to poll for messages.
        /// If the inactivity time is exceeded, considers the duplex output channel as disconnected.
        /// </remarks>
        /// <param name="pollingFrequency">how often the duplex output channel polls for the pending response messages</param>
        /// <param name="inactivityTimeout">maximum time (measured by duplex input channel), the duplex output channel does not have to poll
        /// for response messages. If the time is exceeded, the duplex output channel is considered as disconnected.</param>
        /// <param name="protocolFormatter">formatter for low-level messages between duplex output channel and duplex input channel</param>
        public HttpMessagingSystemFactory(int pollingFrequency, int inactivityTimeout, IProtocolFormatter protocolFormatter)
        {
            using (EneterTrace.Entering())
            {
                myPollingFrequency  = pollingFrequency;
                myProtocolFormatter = protocolFormatter;

                InputChannelThreading  = new SyncDispatching();
                OutputChannelThreading = InputChannelThreading;

                myInputConnectorFactory = new HttpInputConnectorFactory(protocolFormatter, inactivityTimeout);
            }
        }
        public DefaultMessagingSystemFactory(IMessagingProvider messagingProvider, IProtocolFormatter protocolFromatter)
        {
            using (EneterTrace.Entering())
            {
                myOutputConnectorFactory = new DefaultOutputConnectorFactory(messagingProvider, protocolFromatter);
                myInputConnectorFactory  = new DefaultInputConnectorFactory(messagingProvider, protocolFromatter);

                NoDispatching aNoDispatching = new NoDispatching();
                InputChannelThreading  = aNoDispatching;
                OutputChannelThreading = aNoDispatching;

                myDispatcherAfterMessageDecoded = aNoDispatching.GetDispatcher();
            }
        }
Example #25
0
 public WebSocketInputConnectorFactory(IProtocolFormatter protocolFormatter, ISecurityFactory serverSecurityFactory, int sendTimeout, int receiveTimeout,
                                       bool reuseAddressFlag,
                                       int maxAmountOfConnections)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter      = protocolFormatter;
         myServerSecurityFactory  = serverSecurityFactory;
         mySendTimeout            = sendTimeout;
         myReceiveTimeout         = receiveTimeout;
         myReuseAddressFlag       = reuseAddressFlag;
         myMaxAmountOfConnections = maxAmountOfConnections;
     }
 }
Example #26
0
        public SharedMemoryInputConnector(string inputConnectorAddress, IProtocolFormatter protocolFormatter, TimeSpan sendResponseTimeout, int maxMessageSize, MemoryMappedFileSecurity memoryMappedFileSecurity)
        {
            using (EneterTrace.Entering())
            {
                myProtocolFormatter   = protocolFormatter;
                myMaxMessageSize      = maxMessageSize;
                mySendResponseTimeout = sendResponseTimeout;
                mySecurity            = memoryMappedFileSecurity;

                // Note: openTimeout is not used if SharedMemoryReceiver creates memory mapped file.
                TimeSpan aDummyOpenTimout = TimeSpan.Zero;
                myReceiver = new SharedMemoryReceiver(inputConnectorAddress, false, aDummyOpenTimout, myMaxMessageSize, mySecurity);
            }
        }
 /// <summary>
 /// Constructs the UDP messaging factory.
 /// </summary>
 /// <param name="protocolFromatter">formatter used for low-level messaging between output and input channels.</param>
 public UdpMessagingSystemFactory(IProtocolFormatter protocolFromatter)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter    = protocolFromatter;
         InputChannelThreading  = new SyncDispatching();
         OutputChannelThreading = InputChannelThreading;
         Ttl = 128;
         ResponseReceiverPort   = -1;
         UnicastCommunication   = true;
         MulticastLoopback      = true;
         MaxAmountOfConnections = -1;
     }
 }
Example #28
0
 public WebSocketOutputConnectorFactory(IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory,
                                        int connectionTimeout, int sendTimeout, int receiveTimeout,
                                        int pingFrequency,
                                        int responseReceivingPort)
 {
     using (EneterTrace.Entering())
     {
         myProtocolFormatter     = protocolFormatter;
         myClientSecurityFactory = clientSecurityFactory;
         myConnectionTimeout     = connectionTimeout;
         mySendTimeout           = sendTimeout;
         myReceiveTimeout        = receiveTimeout;
         myPingFrequency         = pingFrequency;
         myResponseReceivingPort = responseReceivingPort;
     }
 }
 public SharedMemoryOutputConnector(string inputConnectorAddress, string outputConnectorAddress,
                                    IProtocolFormatter protocolFormatter,
                                    TimeSpan connectTimeout,
                                    TimeSpan sendTimeout,
                                    int maxMessageSize, MemoryMappedFileSecurity memoryMappedFileSecurity)
 {
     using (EneterTrace.Entering())
     {
         myInputConnectorAddress  = inputConnectorAddress;
         myOutputConnectorAddress = outputConnectorAddress;
         myProtocolFormatter      = protocolFormatter;
         myConnectTimeout         = connectTimeout;
         mySendTimeout            = sendTimeout;
         myMaxMessageSize         = maxMessageSize;
         mySecurity = memoryMappedFileSecurity;
     }
 }
Example #30
0
        public override void write(object obj, IProtocolFormatter formatter)
        {
            JsonRPCFormatter jsonRPCFormatter = (JsonRPCFormatter)formatter;

            if (obj is int)
            {
                jsonRPCFormatter.WriteInteger((int)obj);
            }
            else if (obj is long)
            {
                jsonRPCFormatter.WriteLong((long)obj);
            }
            else
            {
                jsonRPCFormatter.WriteDouble((double)obj);
            }
        }