Пример #1
0
 /// <summary>
 /// Initializes an instance of RemoteHubSwitchDirect.
 /// </summary>
 /// <param name="clientId">Client id of the local RemoteHub.</param>
 /// <param name="onMessageReceivedCallback">The callback to be used for dealing received private message.</param>
 /// <param name="encoding">The encoder for converting between string and byte array. Default value is Encoding.Default. Will be ignored if type is not string.</param>
 public RemoteHubSwitchDirect(Guid clientId, OnMessageReceivedCallback <T> onMessageReceivedCallback, Encoding encoding = null)
 {
     this.clientId = clientId;
     clientTable.AddOrUpdate(clientId);
     clientSidePrivateMessageCallbackHelper  = new PrivateMessageCallbackHelper <T>(onMessageReceivedCallback);
     adapterSidePrivateMessageCallbackHelper = new PrivateMessageCallbackHelper <byte[]>(null);
     valueConverter = ValueConverter <T> .Create(encoding);
 }
Пример #2
0
        /// <summary>
        /// Initializes an instance of RedisAdapter.
        /// </summary>
        /// <param name="redisConfiguration">The string configuration to use for Redis multiplexer.</param>
        /// <param name="onMessageReceivedCallback">The callback to be used for dealing received private message. Default value is null.</param>
        /// <param name="mainChannelName">Main channel name. Default value is "RemoteHub".</param>
        /// <param name="privateChannelNamePrefix">Prefix in naming of the private channel. Default value is "RemoteHubPrivate_".</param>
        /// <param name="redisDb">The id to get a database for. Used in getting Redis database. Default value is 0.</param>
        /// <param name="clientTimeToLive">Time to live (TTL) value of the host in seconds. Any records of hosts expired will be removed. Default value is 30 seconds.</param>
        /// <param name="clientRefreshingInterval">Interval between refresh command sending operations in seconds. Default value is 15 seconds.</param>
        public RedisAdapter(string redisConfiguration, OnMessageReceivedCallback <T> onMessageReceivedCallback = null,
                            string mainChannelName = "RemoteHub", string privateChannelNamePrefix = "RemoteHubPrivate_", int redisDb = 0,
                            int clientTimeToLive   = 30, int clientRefreshingInterval = 15)
            : base(redisConfiguration, mainChannelName, privateChannelNamePrefix, redisDb, clientTimeToLive, clientRefreshingInterval)
        {
            privateMessageCallbackHelper = new PrivateMessageCallbackHelper <T>(onMessageReceivedCallback);

            var type = typeof(T);

            if (type == typeof(string))
            {
                ValueConverter <string> client = new ValueConverterOfString();
                valueConverter = __refvalue(__makeref(client), ValueConverter <T>);
            }
            else if (type == typeof(byte[]))
            {
                ValueConverter <byte[]> client = new ValueConverterOfByteArray();
                valueConverter = __refvalue(__makeref(client), ValueConverter <T>);
            }
            else
            {
                throw new NotSupportedException("Only string and byte array are supported.");
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes an instance of StreamAdapter.
 /// </summary>
 /// <param name="inputStream">Stream for reading.</param>
 /// <param name="outputStream">Stream for writing.</param>
 /// <param name="onMessageReceivedCallback">The callback to be used for dealing received private message. Default value is null.</param>
 /// <param name="refreshingIntervalInSeconds">The interval in seconds before sending a data package for keeping it alive when streams are idle. Default value is 60 seconds.</param>
 /// <param name="encoding">The encoder for converting between string and byte array. Default value is Encoding.Default. Will be ignored if type is not string.</param>
 public StreamAdapter(Stream inputStream, Stream outputStream, OnMessageReceivedCallback <T> onMessageReceivedCallback = null, int refreshingIntervalInSeconds = 60, Encoding encoding = null)
     : base(inputStream, outputStream, refreshingIntervalInSeconds)
 {
     privateMessageCallbackHelper = new PrivateMessageCallbackHelper <T>(onMessageReceivedCallback);
     valueConverter = ValueConverter <T> .Create(encoding);
 }