Пример #1
0
        /// <summary>
        /// Erzeugt im Server-Prozess eine neue Instanz einer bestimmten Komponente und gibt einen Proxy dafür zurück.
        /// </summary>
        /// <typeparam name="T">Typ der öffentlichen Schnittstelle der zu konsumierenden Komponente</typeparam>
        /// <param name="implicitTransactionTransfer">Implizite Transaktionsübertragung</param>
        /// <returns>Proxy</returns>
        public T CreateProxy <T>(bool implicitTransactionTransfer)
        {
            // Typeninformationen lesen
            Type interfaceType = typeof(T);

            // Schnittstellenname lesen
            string interfaceName = interfaceType.FullName;

            // Wenn keine Schnittstelle angegeben wurde ...
            if (!interfaceType.IsInterface)
            {
                // Ausnahme werfen
                throw new ApplicationException(string.Format("Der angegebene Typ '{0}' ist keine Schnittstelle! Für die Erzeugung einer entfernten Komponenteninstanz, wird deren öffentliche Schnittstelle benötigt!", interfaceName));
            }

            // Komponenteninformation abrufen
            ComponentInfo info = (from entry in _registeredComponents
                                  where entry.InterfaceName.Equals(interfaceName)
                                  select entry).FirstOrDefault();

            // Wenn für die Schnittstelle auf dem verbundenen Server keine Komponente registriert ist ...
            if (info == null)
            {
                // Ausnahme werfne
                throw new ApplicationException(string.Format("Für Schnittstelle '{0}' ist auf dem Server '{1}' keine Komponente registriert.", interfaceName, _serverUrl));
            }

            // Proxy erzeugen
            ZyanProxy proxy = new ZyanProxy(typeof(T), this, implicitTransactionTransfer, _sessionID, _componentHostName, _autoLoginOnExpiredSession, _autoLoginCredentials, info.ActivationType);

            // Proxy transparent machen und zurückgeben
            return((T)proxy.GetTransparentProxy());
        }
Пример #2
0
        /// <summary>
        /// Creates a local proxy object of a specified remote component.
        /// </summary>
        /// <typeparam name="T">Remote component interface type</typeparam>
        /// <param name="uniqueName">Unique component name</param>
        /// <param name="implicitTransactionTransfer">Specify whether transactions (System.Transactions) should be transferred to remote component automatically.</param>
        /// <param name="keepCallbackSynchronizationContext">Specify whether callbacks and events should use the original synchronization context.</param>
        /// <returns>Proxy</returns>
        public T CreateProxy <T>(string uniqueName, bool implicitTransactionTransfer, bool keepCallbackSynchronizationContext)
        {
            Type interfaceType = typeof(T);

            if (string.IsNullOrEmpty(uniqueName))
            {
                uniqueName = interfaceType.FullName;
            }

            if (!interfaceType.IsInterface)
            {
                throw new ApplicationException(string.Format(LanguageResource.ApplicationException_SpecifiedTypeIsNotAnInterface, interfaceType.FullName));
            }

            ComponentInfo info;

            lock (_registeredComponents)
            {
                info = (from entry in _registeredComponents
                        where entry.UniqueName.Equals(uniqueName)
                        select entry).FirstOrDefault();
            }

            if (info == null)
            {
                throw new ApplicationException(string.Format(LanguageResource.ApplicationException_NoServerComponentIsRegisteredForTheGivenInterface, interfaceType.FullName, _serverUrl));
            }

            var proxy = new ZyanProxy(info.UniqueName, typeof(T), this, implicitTransactionTransfer, keepCallbackSynchronizationContext, _sessionID, _componentHostName, _autoLoginOnExpiredSession, info.ActivationType);

            lock (_proxies)
            {
                var proxyReference = new WeakReference(proxy);
                _proxies.Add(proxyReference);
            }

            return((T)proxy.GetTransparentProxy());
        }