public static ValueConverter <T> Create(Encoding encoding = null) { var type = typeof(T); if (type == typeof(string)) { if (encoding == null) { encoding = Encoding.Default; } ValueConverter <string> client = new ValueConverterOfString(encoding); return(__refvalue(__makeref(client), ValueConverter <T>)); } else if (type == typeof(byte[])) { ValueConverter <byte[]> client = new ValueConverterOfByteArray(); return(__refvalue(__makeref(client), ValueConverter <T>)); } else { throw new NotSupportedException("Only string and byte array are supported."); } }
/// <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."); } }