private static HandshakeDelegate BuildHandshakeDelegateForDispatcher(IServiceDispatcher dispatcher) { var be = dispatcher.Binding.CreateBindingElements(); var mebe = be.Find <MessageEncodingBindingElement>(); MessageEncoderFactory mefact = mebe.CreateMessageEncoderFactory(); var tbe = be.Find <TransportBindingElement>(); int maxReceivedMessageSize = (int)Math.Min(tbe.MaxReceivedMessageSize, int.MaxValue); var bufferManager = BufferManager.CreateBufferManager(tbe.MaxBufferPoolSize, maxReceivedMessageSize); var upgradeBindingElements = (from element in be where element is StreamUpgradeBindingElement select element).Cast <StreamUpgradeBindingElement>().ToList(); StreamUpgradeProvider streamUpgradeProvider = null; ISecurityCapabilities securityCapabilities = null; if (upgradeBindingElements.Count > 1) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.MultipleStreamUpgradeProvidersInParameters)); } // TODO: Limit NamedPipes to prevent it using SslStreamSecurityUpgradeProvider else if ((upgradeBindingElements.Count == 1) /*&& this.SupportsUpgrade(upgradeBindingElements[0])*/) { var bindingContext = new BindingContext(new CustomBinding(dispatcher.Binding), new BindingParameterCollection()); streamUpgradeProvider = upgradeBindingElements[0].BuildServerStreamUpgradeProvider(bindingContext); streamUpgradeProvider.OpenAsync().GetAwaiter().GetResult(); securityCapabilities = upgradeBindingElements[0].GetProperty <ISecurityCapabilities>(bindingContext); } return((connection) => { connection.MessageEncoderFactory = mefact; connection.StreamUpgradeAcceptor = streamUpgradeProvider?.CreateUpgradeAcceptor(); connection.SecurityCapabilities = securityCapabilities; connection.ServiceDispatcher = dispatcher; connection.BufferManager = bufferManager; return Task.CompletedTask; }); }
/// <summary> /// Initializes new instance of <see cref="LazyController"/>. /// </summary> /// <param name="convertor">Instance of <see cref="IResponseConversionProvider{TConvertedResponse}"/>.</param> /// <param name="logger"></param> protected LazyController(IResponseConversionProvider <IHttpActionResult> convertor, ILogProvider logger) { Dispatcher = ServiceDispatcherFactory <IHttpActionResult> .Create( convertor ?? new ResponseConversionProvider(this), logger ?? new NullLogProvider()); }
public ViewModel3(IServiceDispatcher serviceDispatcher) { this.serviceDispatcher = serviceDispatcher; Title = "ViewModel3"; OpenDetailCommand = new Command(OpenDetail); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Detail 1", Order = ToolbarItemOrder.Primary, Command = OpenDetailCommand }); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Detail 2", Order = ToolbarItemOrder.Primary, Command = OpenDetailCommand }); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Detail 3", Order = ToolbarItemOrder.Secondary, Command = OpenDetailCommand }); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Detail 4", Order = ToolbarItemOrder.Secondary, Command = OpenDetailCommand }); }
public RequestDelegateHandler(IServiceDispatcher serviceDispatcher, IServiceScopeFactory servicesScopeFactory) { _serviceDispatcher = serviceDispatcher; _timeouts = _serviceDispatcher.Binding; _servicesScopeFactory = servicesScopeFactory; BuildHandler(); }
public SecurityServiceDispatcher(BindingContext context, IServiceDispatcher serviceDispatcher) { InnerServiceDispatcher = serviceDispatcher; _bindingContext = context; // this.securityProtocolFactory = securityProtocolFactory; // we set it later from TransportSecurityBindingElement // this.settingsLifetimeManager = new SecurityListenerSettingsLifetimeManager(this.securityProtocolFactory, this.sessionServerSettings, this.sessionMode, this.InnerChannelListener); }
public async Task DispatchAsync(Message message) { if (message == null) //0 bytes { //We have already closed all channels, return. (Couldn't use DoneReceivingInCurrentState()) if (_channel.State == CommunicationState.Closed || _channel.State == CommunicationState.Closing || _channel.State == CommunicationState.Closed) { return; } else { await _serviceChannelDispatcher.DispatchAsync(message); return; } } IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(message); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, message.Headers.Action)), message); await _demuxer.EndpointNotFoundAsync((IDuplexSessionChannel)_channel, message); return; } _serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await _serviceChannelDispatcher.DispatchAsync(message); }
public void AddServiceDispatcher(IServiceDispatcher <ConnectionContext <C>, string> serviceDispatcher) { if (_started) { throw new Exception("Dispatchers should be all added before starting the server."); } _dispatcher.Register(serviceDispatcher); }
public MasterViewModel(IServiceDispatcher serviceDispatcher) { this.serviceDispatcher = serviceDispatcher; Title = "Menu"; Items = new ObservableCollection <MenuItem>(); }
public IServiceDispatcher AddServiceDispatcher <TChannel>(IServiceDispatcher innerDispatcher) where TChannel : class, IChannel { if (!_isChannelDemuxerRequired) { throw new Exception("ChannelDemuxerRequired is set to false"); } return(ChannelDemuxer.CreateServiceDispatcher <TChannel>(innerDispatcher, BindingParameters)); }
public IServiceDispatcher AddServiceDispatcher <TChannel>(IServiceDispatcher innerDispatcher, ChannelDemuxerFilter filter) where TChannel : class, IChannel { if (!isChannelDemuxerRequired) { throw new Exception("ChannelDemuxerRequired is set to false"); } return(channelDemuxer.CreaterServiceDispatcher <TChannel>(innerDispatcher, filter)); }
public Context() { Dispatcher dispatcher = new Dispatcher(this); processDispatcher = dispatcher; serviceDispatcher = dispatcher; deviceManager = new DeviceManager(); }
public void Release() { processDispatcher = null; serviceDispatcher = null; deviceManager = null; processes = null; services = null; }
public override IServiceDispatcher AddDispatcher(IServiceDispatcher innerDispatcher, ChannelDemuxerFilter filter) { lock (ThisLock) { _filterTable.Add(filter.Filter, innerDispatcher, filter.Priority); } return(this); }
public MapViewModel(IServiceDispatcher serviceDispatcher) { this.serviceDispatcher = serviceDispatcher; serviceDispatcher.Subscribe <IMapService>(this); MapType = MapType.Roads; Markers = new ObservableCollection <Marker>(); TileOverlays = new ObservableCollection <TileOverlay>(); }
public SplashViewModel1(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { HasNavigationBar = false; Title = "SplashViewModel1"; this.serviceDispatcher = serviceDispatcher; this.platformProvider = platformProvider; Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() => serviceDispatcher.Dispatch <INavigationService>(ShellNames.SplashScreen, n => n.Push <SplashViewModel2>(replace: true)))); }
public ShellViewModel(IServiceDispatcher serviceDispatcher, IViewModelFactory viewModelFactory) { this.serviceDispatcher = serviceDispatcher; this.viewModelFactory = viewModelFactory; serviceDispatcher.Subscribe <INavigationService>(this); serviceDispatcher.Subscribe <IDetachService>(this); Items = new ObservableCollection <IViewModel>(); DetachedItems = new ObservableCollection <IViewModel>(); }
public TileOverlayMapViewModel(IServiceDispatcher serviceDispatcher) : base(serviceDispatcher) { MapType = MapType.None; TileOverlays.Add(HighDpiTileOverlay); ToolbarItems.Add(new ToolbarItemViewModel() { Command = new Command(SwitchTileOverlay), Title = "Switch" }); }
public bool Register(IServiceDispatcher <C, D> dispatcher) { var svc = dispatcher.GetSupportedService(); if (services.ContainsKey(svc)) { return(false); } services.Add(svc, dispatcher); return(true); }
public DetailViewModel(IServiceDispatcher serviceDispatcher) { this.serviceDispatcher = serviceDispatcher; Title = "DetailViewModel"; CloseCommand = new Command(Close); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Close", Command = CloseCommand }); }
public ViewModel1(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { Title = "ViewModel1"; this.serviceDispatcher = serviceDispatcher; this.platformProvider = platformProvider; IsLoading = true; LoadingText = "Loading for 3 seconds..."; Task.Delay(3000).ContinueWith(t => IsLoading = false); OpenViewModel2Command = new Command(OpenViewModel2); ShowMessageCommand = new Command(ShowMessage); }
protected IServiceDispatcher MatchDispatcher(Message message) { IServiceDispatcher matchingDispatcher = null; lock (ThisLock) { if (_filterTable.GetMatchingValue(message, out matchingDispatcher)) { return(matchingDispatcher); } } return(null); }
public virtual IServiceDispatcher BuildServiceDispatcher <TChannel>(Uri listenUriBaseAddress, string listenUriRelativeAddress, BindingParameterCollection parameters, IServiceDispatcher dispatcher) where TChannel : class, IChannel { EnsureInvariants(); BindingContext context = new BindingContext(new CustomBinding(this), parameters, listenUriBaseAddress, listenUriRelativeAddress); IServiceDispatcher serviceDispatcher = context.BuildNextServiceDispatcher <TChannel>(dispatcher); context.ValidateBindingElementsConsumed(); // TODO: Work out how to validate security capabilities //this.ValidateSecurityCapabilities(serviceDispatcher.GetProperty<ISecurityCapabilities>(), parameters); return(serviceDispatcher); }
public ViewModel2(IServiceDispatcher serviceDispatcher) { Title = "ViewModel2"; this.serviceDispatcher = serviceDispatcher; OpenMasterDetailViewModelCommand = new Command(OpenMasterDetailViewModel); BackCommand = new Command(Back); ToolbarItems.Add(new ToolbarItemViewModel() { Title = "Open", Command = OpenMasterDetailViewModelCommand }); }
public IServiceDispatcher BuildServiceDispatcher <TChannel>(BindingContext context, IServiceDispatcher innerDispatcher) where TChannel : class, IChannel { if (this.context != null) { IServiceDispatcher listener = this.context.BuildNextServiceDispatcher <TChannel>(innerDispatcher);// .BuildInnerChannelListener<TChannel>(); // this.listenUri = listener.Uri; this.context = null; return(listener); } else { return(this.binding.BuildServiceDispatcher <TChannel>(this.bindingParameters, innerDispatcher)); } }
public SplashViewModel2(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { HasNavigationBar = false; Title = "SplashViewModel2"; this.serviceDispatcher = serviceDispatcher; this.platformProvider = platformProvider; Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() => { serviceDispatcher.Dispatch <IShellNavigationService>(n => n.Push <StackShellViewModel>(new { Name = ShellNames.Stack })); serviceDispatcher.Dispatch <INavigationService>(ShellNames.Stack, n => n.Push <ViewModel1>(replace: true)); })); }
public virtual void Initialize() { CurrentPlatform = Container.GetInstance <IPlatformProvider>().GetPlatform(); Container.GetInstance <IViewModelFactory>().Initialize(); Container.GetInstance <IViewFactory>().Initialize(); Container.GetInstance <IServiceDispatcher>().Initialize(); pluginProvider = Container.GetInstance <IPluginProvider>(); serviceDispatcher = Container.GetInstance <IServiceDispatcher>(); serviceDispatcher.Subscribe <IShellNavigationService>(this); Run(); }
public async Task DispatchAsync(RequestContext context) { // TODO: Find way to avoid instantiating a new ServiceChannelDispatcher each time IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(context.RequestMessage); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, context.RequestMessage.Headers.Action)), context.RequestMessage); } // TODO: if serviceDispatcher == null, use the EndpointNotFound code path IServiceChannelDispatcher serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await serviceChannelDispatcher.DispatchAsync(context); }
internal static UriPrefixTable <HandshakeDelegate> BuildAddressTable(IServiceProvider services) { ILogger <NetMessageFramingConnectionHandler> logger = services.GetRequiredService <ILogger <NetMessageFramingConnectionHandler> >(); IServiceBuilder serviceBuilder = services.GetRequiredService <IServiceBuilder>(); IDispatcherBuilder dispatcherBuilder = services.GetRequiredService <IDispatcherBuilder>(); var addressTable = new UriPrefixTable <HandshakeDelegate>(); foreach (Type serviceType in serviceBuilder.Services) { List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(serviceType); foreach (IServiceDispatcher dispatcher in dispatchers) { if (dispatcher.BaseAddress == null) { // TODO: Should we throw? Ignore? continue; } // TODO: Limit to specifically TcpTransportBindingElement if net.tcp etc BindingElementCollection be = dispatcher.Binding.CreateBindingElements(); ConnectionOrientedTransportBindingElement cotbe = be.Find <ConnectionOrientedTransportBindingElement>(); if (cotbe == null) { // TODO: Should we throw? Ignore? continue; } IServiceDispatcher _serviceDispatcher = null; var _customBinding = new CustomBinding(dispatcher.Binding); if (_customBinding.Elements.Find <ConnectionOrientedTransportBindingElement>() != null) { var parameters = new BindingParameterCollection(); if (_customBinding.CanBuildServiceDispatcher <IDuplexSessionChannel>(parameters)) { _serviceDispatcher = _customBinding.BuildServiceDispatcher <IDuplexSessionChannel>(parameters, dispatcher); } } _serviceDispatcher = _serviceDispatcher ?? dispatcher; HandshakeDelegate handshake = BuildHandshakeDelegateForDispatcher(_serviceDispatcher); logger.LogDebug($"Registering URI {dispatcher.BaseAddress} with NetMessageFramingConnectionHandler"); addressTable.RegisterUri(dispatcher.BaseAddress, cotbe.HostNameComparisonMode, handshake); } } return(addressTable); }
public static void BuildDispatcherWithConfiguration_XmlSerializer() { string serviceAddress = "http://localhost/dummy"; var services = new ServiceCollection(); services.AddLogging(); services.AddServiceModelServices(); IServer server = new MockServer(); services.AddSingleton(server); services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>)); services.RegisterApplicationLifetime(); ServiceProvider serviceProvider = services.BuildServiceProvider(); IServiceBuilder serviceBuilder = serviceProvider.GetRequiredService <IServiceBuilder>(); serviceBuilder.BaseAddresses.Add(new Uri(serviceAddress)); serviceBuilder.AddService <SimpleXmlSerializerService>(); var binding = new CustomBinding("BindingName", "BindingNS"); binding.Elements.Add(new MockTransportBindingElement()); serviceBuilder.AddServiceEndpoint <SimpleXmlSerializerService, ISimpleXmlSerializerService>(binding, serviceAddress); serviceBuilder.OpenAsync().GetAwaiter().GetResult(); IDispatcherBuilder dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>(); System.Collections.Generic.List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(typeof(SimpleXmlSerializerService)); Assert.Single(dispatchers); IServiceDispatcher serviceDispatcher = dispatchers[0]; Assert.Equal("foo", serviceDispatcher.Binding.Scheme); Assert.Equal(serviceAddress, serviceDispatcher.BaseAddress.ToString()); IChannel mockChannel = new MockReplyChannel(serviceProvider); IServiceChannelDispatcher dispatcher = serviceDispatcher.CreateServiceChannelDispatcherAsync(mockChannel).Result; var requestContext = XmlSerializerTestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext).Wait(); Assert.True(requestContext.WaitForReply(TimeSpan.FromSeconds(5)), "Dispatcher didn't send reply"); requestContext.ValidateReply(); }
public NavigationMasterViewModel(IServiceDispatcher serviceDispatcher) : base(serviceDispatcher) { Items.Add(new ViewModelMenuItem("View 3", new TypeConfiguration(typeof(ViewModel3))) { Icon = "Icon16.png" }); Items.Add(new ViewModelMenuItem("View 4", new TypeConfiguration(typeof(ViewModel4))) { Icon = "Icon24.png" }); Items.Add(new ViewModelMenuItem("View 5", new TypeConfiguration(typeof(ViewModel5))) { Icon = "Icon32.png" }); Items.Add(new CommandMenuItem("Back", new Command(Back)) { Icon = "Icon48.png" }); }