public override async ValueTask ConnectAsync() { _cts = new CancellationTokenSource(); if (_client == null) { Func <TransportContext> getCtx = () => _context; _client = new EasyClient <ReceivedPackage>(ServiceProvider.CreateInstance <ReceivedPackageFilter>(getCtx), new ChannelOptions() { MaxPackageLength = 1024 * 1024 * 1024 }); } _client.Closed += async(o, e) => { await DisconnectAsync(); }; if (await _client.ConnectAsync(new IPEndPoint(IPAddress.Parse(ConnectionAddress.IPAddress), ConnectionAddress.Port))) { IsConnected = true; DoReceive(); } else { await DisconnectAsync(); } }
private static IVsThreadedWaitDialog2 CreateProgressDialog() { IVsThreadedWaitDialog2 dialog; var oleServiceProvider = Package.GetGlobalService(typeof(IServiceProvider)) as IServiceProvider; var dialogFactory = new ServiceProvider(oleServiceProvider) .GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory; dialogFactory.CreateInstance(out dialog); return(dialog); }
/// <summary>运行 /// </summary> public override async Task ConnectAsync() { if (_channel != null && _channel.Registered) { Logger.LogInformation($"Client is running! Don't run again! ChannelId:{_channel.Id.AsLongText()}"); return; } try { _group = new MultithreadEventLoopGroup(); _bootStrap = new Bootstrap(); _bootStrap .Group(_group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Option(ChannelOption.WriteBufferHighWaterMark, 16777216) .Option(ChannelOption.WriteBufferLowWaterMark, 8388608) //.Option(ChannelOption.SoReuseaddr, tcpSetting.SoReuseaddr) .Option(ChannelOption.AutoRead, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new LoggingHandler(typeof(DotNettyConnection))); pipeline.AddLast("fdfs-write", new ChunkedWriteHandler <IByteBuffer>()); pipeline.AddLast("fdfs-decoder", ServiceProvider.CreateInstance <FastDFSDecoder>(new Func <TransportContext>(GetContext))); pipeline.AddLast("fdfs-read", ServiceProvider.CreateInstance <FastDFSHandler>(new Action <ReceivedPackage>(SetResponse))); //重连 if (Option.EnableReConnect) { //Reconnect to server pipeline.AddLast("reconnect", ServiceProvider.CreateInstance <ReConnectHandler>(Option, new Func <Task>(DoReConnectIfNeed))); } })); await DoConnect(); IsRunning = true; Logger.LogInformation($"Client Run! serverEndPoint:{_channel.RemoteAddress.ToStringAddress()},localAddress:{_channel.LocalAddress.ToStringAddress()}"); } catch (Exception ex) { Logger.LogError(ex.Message); await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); } }
private IVsThreadedWaitDialog2 ShowProgressDialog(string caption, string message) { IOleServiceProvider oleServiceProvider = dteObject as IOleServiceProvider; IVsThreadedWaitDialogFactory dialogFactory = new ServiceProvider(oleServiceProvider).GetService( typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory; if (dialogFactory == null) { throw new InvalidOperationException("The IVsThreadedWaitDialogFactory object could not be retrieved."); } IVsThreadedWaitDialog2 vsThreadedWaitDialog = null; ErrorHandler.ThrowOnFailure(dialogFactory.CreateInstance(out vsThreadedWaitDialog)); ErrorHandler.ThrowOnFailure(vsThreadedWaitDialog.StartWaitDialog(caption, message, null, null, String.Empty, 0, false, true)); return(vsThreadedWaitDialog); }
/// <summary>运行 /// </summary> public override async ValueTask ConnectAsync() { if (_channel != null && _channel.Registered) { Logger.LogInformation($"Client is running! Don't run again! ChannelId:{_channel.Id.AsLongText()}"); return; } try { _group = new MultithreadEventLoopGroup(); _bootStrap = new Bootstrap(); _bootStrap .Group(_group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, _dotNettyOption.TcpNodelay) .Option(ChannelOption.WriteBufferHighWaterMark, _dotNettyOption.WriteBufferHighWaterMark) .Option(ChannelOption.WriteBufferLowWaterMark, _dotNettyOption.WriteBufferLowWaterMark) .Option(ChannelOption.SoReuseaddr, _dotNettyOption.SoReuseaddr) .Option(ChannelOption.AutoRead, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new LoggingHandler(typeof(DotNettyConnection))); pipeline.AddLast("fdfs-write", new ChunkedWriteHandler <IByteBuffer>()); pipeline.AddLast("fdfs-decoder", ServiceProvider.CreateInstance <FastDFSDecoder>(new Func <TransportContext>(() => _context))); pipeline.AddLast("fdfs-handler", ServiceProvider.CreateInstance <FastDFSHandler>(new Action <ReceivedPackage>(HandleReceivedPack), new Func <Exception, Task>(HandleExceptionCaught))); })); _channel = await _bootStrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(ConnectionAddress.IPAddress), ConnectionAddress.Port)); IsConnected = true; Logger.LogInformation($"Client connect! serverEndPoint:{_channel.RemoteAddress.ToStringAddress()},localAddress:{_channel.LocalAddress.ToStringAddress()}"); } catch (Exception ex) { Logger.LogError(ex.Message); IsConnected = false; await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override object Create(ControllerContext context) { var appContext = new AppContext(); if (AppContextHelper.Context == null) { AppContextHelper.Context = new Stack <IAppContext>(); } AppContextHelper.Context.Push(appContext); if (context.ActionDescriptor.ControllerTypeInfo.DeclaringType.IsAppService()) { //自定义工厂实现激活器 return(ServiceProvider.CreateInstance(context.ActionDescriptor.ControllerTypeInfo.DeclaringType)); } else { return(base.Create(context)); } }
public void Test() { var item = _service.CreateInstance <TestServiceActivator>(); item.Should().NotBeNull(); }