public ReceiverChannel( IChannelInformation channelInformation, ITransport transport, IChannelCommandProcessor channelCommandProcessor, ICollection <IChannelModule <Message> > messageModules, ICollection <IChannelModule <Notification> > notificationModules, ICollection <IChannelModule <Command> > commandModules, Func <Exception, Task> exceptionHandler, int envelopeBufferSize, TimeSpan?consumeTimeout) { if (consumeTimeout != null && consumeTimeout.Value == default) { throw new ArgumentException("Invalid consume timeout", nameof(consumeTimeout)); } _channelInformation = channelInformation; _transport = transport; _channelCommandProcessor = channelCommandProcessor; _messageModules = messageModules; _notificationModules = notificationModules; _commandModules = commandModules; _exceptionHandler = exceptionHandler; _consumeTimeout = consumeTimeout; _sessionSemaphore = new SemaphoreSlim(1); _startStopSemaphore = new SemaphoreSlim(1); _consumerCts = new CancellationTokenSource(); _messageBuffer = ChannelUtil.CreateForCapacity <Message>(envelopeBufferSize, false, true); _notificationBuffer = ChannelUtil.CreateForCapacity <Notification>(envelopeBufferSize, false, true); _commandBuffer = ChannelUtil.CreateForCapacity <Command>(envelopeBufferSize, false, true); _sessionBuffer = ChannelUtil.CreateForCapacity <Session>(envelopeBufferSize, false, true); }
public SenderChannel( IChannelInformation channelInformation, ITransport transport, ICollection <IChannelModule <Message> > messageModules, ICollection <IChannelModule <Notification> > notificationModules, ICollection <IChannelModule <Command> > commandModules, Func <Exception, Task> exceptionHandler, int envelopeBufferSize, TimeSpan sendTimeout) { if (sendTimeout == default) { throw new ArgumentException("Invalid send timeout", nameof(sendTimeout)); } _channelInformation = channelInformation; _transport = transport; _messageModules = messageModules; _notificationModules = notificationModules; _commandModules = commandModules; _exceptionHandler = exceptionHandler; _sendTimeout = sendTimeout; _sessionSemaphore = new SemaphoreSlim(1); _startStopSemaphore = new SemaphoreSlim(1); _senderCts = new CancellationTokenSource(); _envelopeBuffer = ChannelUtil.CreateForCapacity <Envelope>(envelopeBufferSize, true, false); }
public override void ExceptionCaught(IChannelHandlerContext ctx, Exception cause) { Logger().LogError(cause, $"{FrameworkErrorCode.ExceptionCaught.GetErrCode()}:{Utils.NetUtil.ToStringAddress(ctx.Channel.RemoteAddress)} connect exception.{cause.Message}"); _outerInstance.clientChannelManager.ReleaseChannel(ctx.Channel, ChannelUtil.GetAddressFromChannel(ctx.Channel)).GetAwaiter().GetResult(); if (Logger().IsEnabled(LogLevel.Information)) { Logger().LogInformation($"remove exception rm channel:{ctx.Channel}"); } base.ExceptionCaught(ctx, cause); }
public T GetOrCreateSingletonService <T>(string assemblyName, bool ensureSecurity = false) { if (channel == null) { channel = ChannelUtil.RegisterIpcChannel("VsixTesting.ClientChannel", Guid.NewGuid().ToString(), ensureSecurity); remoteChannelPortName = Guid.NewGuid().ToString(); InvokeRemote(nameof(Remote.RegisterIpcChannel), "VsixTesting.ServerChannel", remoteChannelPortName, ensureSecurity); InvokeRemote(nameof(Remote.RegisterWellKnownServiceType), assemblyName, typeof(T).FullName, WellKnownObjectMode.Singleton); } return((T)RemotingServices.Connect(typeof(T), $"ipc://{remoteChannelPortName}/{typeof(T).FullName}")); }
private static void StartBackgroundCheckControlThreadStart() { int status = 0; while (LoopCheckModel.isLinked) { status = UsbIPUtil.isUsbLinked(); if (status == 0) { LoopCheckModel.isLinked = true; } else if (status == -1000 || status == -2000) { LoopCheckModel.isLinked = false; break; } Thread.Sleep(5000); } if (status == -1000) { if (ChannelUtil.pingRouterConnect()) { if (UsbIPUtil.isHostLinked()) { if (UsbIPUtil.isCableLinked()) { status = -1000; } else { status = -3000; } } else { status = -1002; } } else { status = -1001; } } else if (status == -2000) { UsbIPUtil.RebootService(); status = -1000; } AnimationModel.ConnectAnimateionPause(); LoopCheckModel.ControlInterrupt(status); }
public BufferedChannelListener( Func <Message, CancellationToken, Task <bool> > messageConsumer, Func <Notification, CancellationToken, Task <bool> > notificationConsumer, Func <Command, CancellationToken, Task <bool> > commandConsumer, int capacity = 1) { _messageConsumer = messageConsumer ?? throw new ArgumentNullException(nameof(messageConsumer)); _notificationConsumer = notificationConsumer ?? throw new ArgumentNullException(nameof(notificationConsumer)); _commandConsumer = commandConsumer ?? throw new ArgumentNullException(nameof(commandConsumer)); MessageBuffer = ChannelUtil.CreateForCapacity <Message>(capacity, singleWriter: true, singleReader: true); NotificationBuffer = ChannelUtil.CreateForCapacity <Notification>(capacity, singleWriter: true, singleReader: true); CommandBuffer = ChannelUtil.CreateForCapacity <Command>(capacity, singleWriter: true, singleReader: true); _syncRoot = new object(); }
/// <summary> /// Release. /// </summary> public virtual void Release() { int?clientPort = ChannelUtil.GetClientPortFromChannel(Channel); if (clientIDHolderMap != null) { clientIDHolderMap = null; } if (ResourceSets != null) { ResourceSets.Clear(); } }
private void checkRouterSSIDStart() { string SSID = ChannelUtil.getWifiSSID(); if (string.IsNullOrEmpty(SSID)) { this.CheckHostThreadStart(); return; } if ("TPCast_AP".Equals(SSID)) { this.CheckRouterSSIDFinish(false); return; } this.CheckHostThreadStart(); }
private void initCheckRouterSSIDThreadStart() { string SSID = ChannelUtil.getWifiSSID(); ConnectModel.log.Trace("ssid = " + SSID); if (string.IsNullOrEmpty(SSID)) { this.initCheckRouterFail(); return; } if ("TPCast_AP".Equals(SSID)) { this.initCheckRouterSSIDFinish(false); return; } this.initCheckRouterSSIDFinish(true); }
public AggregateTransportListener(IEnumerable <ITransportListener> transportListeners, int capacity = -1) { if (transportListeners == null) { throw new ArgumentNullException(nameof(transportListeners)); } _transportListeners = transportListeners.ToList(); if (_transportListeners.Count == 0) { throw new ArgumentException("The transport listeners enumerable is empty", nameof(transportListeners)); } ListenerUris = _transportListeners.SelectMany(t => t.ListenerUris).ToArray(); _transportChannel = ChannelUtil.CreateForCapacity <ITransport>(capacity); _listenerTasks = new List <Task>(); _cts = new CancellationTokenSource(); }
private void CheckControlReload() { bool isRouterConnected = false; this.abortRouter = false; while (!isRouterConnected) { if (this.abortRouter) { this.StopRouterTimer(); this.ReloadCheckError(-1001); return; } if (ChannelUtil.pingRouterConnect()) { this.RouterConnected(); this.HostThreadStart(); return; } Thread.Sleep(5000); } }
private void checkIsChannelSwitched() { bool isSwitched = false; this.abortSwitchChannel = false; while (!isSwitched) { if (this.abortSwitchChannel) { return; } this.switchedChannel = ChannelUtil.getWirelessChannel(); ConnectModel.log.Trace("switched channel = " + this.switchedChannel); if (this.switchedChannel != null && this.switchedChannel != this.currentChannel) { isSwitched = true; this.StopSwitchChannelTimer(); this.ChannelSwitchedFinish(); } Thread.Sleep(5000); } }
private void CheckRouter() { bool isCheckRouterConnected = false; this.abortCheckRouter = false; while (!isCheckRouterConnected) { if (this.abortCheckRouter) { this.StopCheckRouterTimer(); this.CheckControlError(-1001); return; } if (ChannelUtil.pingRouterConnect()) { this.CheckRouterConnected(); this.checkRouterSSIDStart(); return; } Thread.Sleep(5000); } }
private void getCurrentChannel() { ConnectModel.log.Trace("getCurrentChannel"); if (!ChannelUtil.pingRouterConnect()) { ConnectModel.log.Trace("ping 144.1 fail "); this.StopSwitchChannelTimer(); this.CheckRouterChannelFinish(false); return; } this.currentChannel = ChannelUtil.getWirelessChannel(); ConnectModel.log.Trace("current Channel = " + this.currentChannel); if (this.currentChannel != null) { ChannelUtil.switchWirelessChannel(); ConnectModel.log.Trace("switchWirelessChannel"); this.checkIsChannelSwitched(); return; } ConnectModel.log.Trace("other router or bad router"); this.StopSwitchChannelTimer(); this.CheckRouterChannelFinish(false); }
public void OnMessage(EventingBasicConsumer consumer, IModel sendModel, string message, Action <bool> call) { Captcha captcha = JsonConvert.DeserializeObject <Captcha>(message); // Checking rule if (captcha == null || captcha.Binary == null || !ChannelUtil.IsDefined(captcha.Channel)) { call(false); return; } // Resolve direction MessageSourceManager.Instance.NotifyAllDiscern(captcha, (code) => { if (code == null) { call(false); return; } // 发送扣费请求到队列中 /*var msg = JsonConvert.SerializeObject(new WalletReq() * { * channel = captcha.Channel, * token = captcha.Token * }); * var body = Encoding.UTF8.GetBytes(msg); * var properties = sendModel.CreateBasicProperties(); * properties.Persistent = true;// 确保消息是可靠持久的 * sendModel.BasicPublish(MultiQueue.Exchange, MultiQueue.Wallet, null, body); * Console.WriteLine($"Send deduction request: {msg}");*/ call(true); }); }
public static void RegisterIpcChannel(string name, string portName, bool ensureSecurity) => channel = ChannelUtil.RegisterIpcChannel(name, portName, ensureSecurity);
public FakeTransportListener(Uri[] listenerUris = null, int capacity = -1) { _channel = ChannelUtil.CreateForCapacity <ITransport>(capacity); ListenerUris = listenerUris ?? new Uri[0]; }