Пример #1
0
        /// <summary>
        /// Scans the service interface and registers custom proxy class
        /// </summary>
        /// <typeparam name="T">Service interface, must equal server-side</typeparam>
        /// <returns>Proxy class for remote calls</returns>
        public void RegisterServiceProxy <T>(Proxy <T> customProxy)
        {
            // check if service implements interface
            if (customProxy.GetType().GetInterface(typeof(T).Name) == null)
            {
                throw new InvalidOperationException("Custom Proxy class does not implement service interface");
            }

            IpcStream.ScanInterfaceForTypes(typeof(T), KnownTypes);
        }
Пример #2
0
        /// <summary>
        /// Register a service interface on the server
        /// This is a one instance for all clients service
        /// </summary>
        /// <typeparam name="T">The interface of the service</typeparam>
        /// <param name="instance">Instance of a class implementing the service</param>
        public void RegisterService <T>(T instance)
        {
            if (!typeof(T).IsInterface)
            {
                throw new InvalidOperationException("Service Type is not an interface");
            }

            if (!(instance is T))
            {
                throw new InvalidOperationException("Instance must implement service interface");
            }

            services[typeof(T).Name] = instance;
            types[typeof(T).Name]    = typeof(T);

            IpcStream.ScanInterfaceForTypes(typeof(T), KnownTypes);
        }
Пример #3
0
        /// <summary>
        /// Register a service interface on the server that keeps its state for a connection
        /// This a one instance for one client/connection service
        /// </summary>
        /// <typeparam name="T">The interface of the service</typeparam>
        /// <param name="t">Type of the class implementing the service, should have a default constructor
        /// which will be called on connection of a new client</param>
        public void RegisterStatefulService <T>(Type t)
        {
            if (!typeof(T).IsInterface)
            {
                throw new InvalidOperationException("Service Type is not an interface");
            }

            // check if service implements interface
            if (t.GetInterface(typeof(T).Name) == null)
            {
                throw new InvalidOperationException("Instance must implement service interface");
            }

            // check for default constructor
            if (t.GetConstructor(Type.EmptyTypes) == null || t.IsAbstract)
            {
                throw new InvalidOperationException("Stateful service requires default constructor");
            }

            services[typeof(T).Name] = new StatefulProxy(t);
            types[typeof(T).Name]    = typeof(T);

            IpcStream.ScanInterfaceForTypes(typeof(T), KnownTypes);
        }
Пример #4
0
        /// <summary>
        /// Scans the service interface and builds proxy class
        /// </summary>
        /// <typeparam name="T">Service interface, must equal server-side</typeparam>
        /// <returns>Proxy class for remote calls</returns>
        public T GetServiceProxy <T>()
        {
            IpcStream.ScanInterfaceForTypes(typeof(T), KnownTypes);

            return((T) new ProxyGenerator().CreateInterfaceProxyWithoutTarget(typeof(T), new Proxy <T>(this)));
        }