Пример #1
0
        private static IServiceRemotingListener CreateServiceRemotingListener(
            ServiceContext serviceContext,
            object serviceImplementation)
        {
            var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType());
            var interfaceTypes         = serviceTypeInformation.InterfaceTypes;

            var provider = ServiceRemotingProviderAttribute.GetProvider(interfaceTypes);

            return(provider.CreateServiceRemotingListener(serviceContext, (IService)serviceImplementation));
        }
 /// <summary>
 /// Gets the Factory method that constructs a ServiceTypeInformation object from the given type.
 /// </summary>
 /// <param name="serviceType">Type to examine</param>
 /// <param name="serviceTypeInformation">The constructed ServiceTypeInformation</param>
 /// <returns>true if the specified serviceType is a service, false otherwise</returns>
 public static bool TryGet(Type serviceType, out ServiceTypeInformation serviceTypeInformation)
 {
     try
     {
         serviceTypeInformation = Get(serviceType);
         return(true);
     }
     catch (ArgumentException)
     {
         serviceTypeInformation = null;
         return(false);
     }
 }
        private static IServiceRemotingListener CreateServiceRemotingListener(
            ServiceContext serviceContext,
            object serviceImplementation)
        {
            var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType());
            var interfaceTypes         = serviceTypeInformation.InterfaceTypes;

            var provider = ServiceRemotingProviderAttribute.GetProvider(interfaceTypes);

            if (provider.RemotingListener.Equals(RemotingListener.V2Listener))
            {
                throw new NotSupportedException(
                          "This extension method doesnt support V2Listener or CompatListener. Use CreateServiceRemotingReplicaListeners for using V2Stack ");
            }
            return(provider.CreateServiceRemotingListener(serviceContext, (IService)serviceImplementation));
        }
Пример #4
0
        /// <summary>
        /// Instantiates the ServiceRemotingDispatcher that uses the given service context and
        /// dispatches messages to the given service implementation.
        /// </summary>
        /// <param name="serviceContext">Service context</param>
        /// <param name="service">Service implementation that implements interfaces of type <see cref="IService"/></param>
        public ServiceRemotingDispatcher(ServiceContext serviceContext, IService service)
        {
            Requires.ThrowIfNull(serviceContext, "serviceContext");

            this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId);

            this.methodDispatcherMap = new Dictionary <int, ServiceMethodDispatcherBase>();
            this.service             = service;

            if (service != null)
            {
                var serviceTypeInformation = ServiceTypeInformation.Get(service.GetType());
                foreach (var interfaceType in serviceTypeInformation.InterfaceTypes)
                {
                    var methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType);
                    this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher);
                }
            }
        }
        /// <summary>
        /// An extension method that creates an <see cref="IServiceRemotingListener"/>
        /// for a stateful service implementation.
        /// <typeparam name="TStatefulService">Type constraint on the service implementation. The service implementation must
        /// derive from <see cref="Microsoft.ServiceFabric.Services.Runtime.StatefulServiceBase"/> and implement one or more
        /// interfaces that derive from <see cref="Microsoft.ServiceFabric.Services.Remoting.IService"/> interface.</typeparam>
        ///</summary>
        /// <param name="serviceImplementation">A stateful service implementation.</param>
        /// <returns>A <see cref="IServiceRemotingListener"/> communication
        /// listener that remotes the interfaces deriving from <see cref="Microsoft.ServiceFabric.Services.Remoting.IService"/> interface.</returns>
        public static IEnumerable <ServiceReplicaListener> CreateServiceRemotingReplicaListeners <TStatefulService>(
            this TStatefulService serviceImplementation)
            where TStatefulService : StatefulServiceBase, IService

        {
            var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType());
            var interfaceTypes         = serviceTypeInformation.InterfaceTypes;
            var impl     = (IService)serviceImplementation;
            var provider = ServiceRemotingProviderAttribute.GetProvider(interfaceTypes);

#if !DotNetCoreClr
            if (provider.RemotingListener.Equals(RemotingListener.V2Listener))
            {
                return(new[]
                {
                    new ServiceReplicaListener(
                        (t) =>
                    {
                        return provider.CreateServiceRemotingListenerV2(serviceImplementation.Context, impl);
                    }, ServiceRemotingProviderAttribute.DefaultV2listenerName
                        )
                });
            }

            if (provider.RemotingListener.Equals(RemotingListener.CompatListener))
            {
                return(new[]
                {
                    new ServiceReplicaListener((t) =>
                    {
                        return provider.CreateServiceRemotingListener(serviceImplementation.Context, impl);
                    }
                                               ),
                    new ServiceReplicaListener(
                        (t) =>
                    {
                        return provider.CreateServiceRemotingListenerV2(serviceImplementation.Context, impl);
                    }, ServiceRemotingProviderAttribute.DefaultV2listenerName
                        )
                });
            }
            else
            {
                return(new[]
                {
                    new ServiceReplicaListener((t) =>
                    {
                        return provider.CreateServiceRemotingListener(serviceImplementation.Context, impl);
                    }
                                               )
                });
            }
#else
            return(new[]
            {
                new ServiceReplicaListener(
                    (t) =>
                {
                    return provider.CreateServiceRemotingListenerV2(serviceImplementation.Context, impl);
                }, ServiceRemotingProviderAttribute.DefaultV2listenerName
                    )
            });
#endif
        }