Beispiel #1
0
        private TContract GetTestObject <TContract>() where TContract : class, IMdmEntity, new()
        {
            var sourceSystem = new TContract
            {
                Identifiers =
                    new MdmIdList
                {
                    new MdmId
                    {
                        SystemName = "ABC",
                        Identifier = Guid.NewGuid().ToString()
                    },
                    new MdmId
                    {
                        SystemName = "XYZ",
                        Identifier = Guid.NewGuid().ToString()
                    },
                    new MdmId
                    {
                        SystemName = "Nexus", Identifier = Guid.NewGuid().GetHashCode().ToString(), IsMdmId = true
                    }
                },
            };

            return(sourceSystem);
        }
Beispiel #2
0
        public virtual TContract Build <TContract>() where TContract : class
        {
            IClientPipeline pipeline = BuildPipeline();
            TContract       proxy    = _configuration.ProxyFactory.CreateProxy <TContract>(pipeline);

            if (proxy is IContractProvider)
            {
                pipeline.Validate((proxy as IContractProvider).Contract);
            }
            else
            {
                pipeline.Validate(BoltFramework.GetContract(typeof(TContract)));
            }

            return(proxy);
        }
 /// <summary>
 /// Convenience method for configuraing a callback channel.  Since this is not a duplex channel it doesn't
 /// support the declarative callbacks in the normal WCF method.
 /// </summary>
 /// <typeparam name="TContract"></typeparam>
 /// <returns></returns>
 public TContract GetCallback<TContract>()
 {
     ThrowIfDisposedOrNotOpen();
     try
     {
         Binding binding = channelListener.CreateResponseBinding();
         TContract channel = ChannelFactory<TContract>.CreateChannel(binding,new EndpointAddress(SsbUri.Default));
         SsbConversationSender sender = ((IClientChannel)channel).GetProperty<SsbConversationSender>();
         sender.SetConnection(con);
         ((IClientChannel)channel).Open();
         SsbConversationContext conversation = OperationContext.Current.IncomingMessageProperties[SsbConstants.SsbConversationMessageProperty] as SsbConversationContext;
         sender.OpenConversation(conversation.ConversationHandle);
         return channel;
     }
     catch (Exception ex)
     {
         throw new CommunicationException("An error occurred while obtaining callback channel: " + ex.Message, ex);
     }
 }
            public TContract Resolve <TContract>()
            {
                Type type = typeof(TContract);

                if (_registry.TypeOf(type) == ImplementationScope.Isolated)
                {
                    return(_registry.Resolve <TContract>());
                }

                lock (LockObject)
                {
                    if (_cache.ContainsKey(type))
                    {
                        return((TContract)_cache[type]);
                    }

                    TContract implementation = _registry.Resolve <TContract>();

                    _cache[type] = implementation;

                    return(implementation);
                }
            }
        /// <summary>
        /// 获取指定回调契约类型的所有通道连接
        /// </summary>
        /// <typeparam name="TContract">回调契约类型</typeparam>
        /// <returns>指定回调契约类型的所有通道连接</returns>
        public IList <TContract> GetCallbackChannels <TContract>() where TContract : class
        {
            List <TContract> list = new List <TContract>();

            List <object> proxyChannelManagers = new List <object>(_proxyChannelManagerContainer.Values);

            foreach (var item in proxyChannelManagers)
            {
                if (item is IProxyChannelManager <TContract> )
                {
                    IProxyChannelManager <TContract> channelManager = item as IProxyChannelManager <TContract>;
                    if (channelManager != null)
                    {
                        Type      channelType  = channelManager.GetChannel().GetType();
                        Type      expectedType = typeof(TContract);
                        TContract callback     = default(TContract);

                        if (channelType.FullName != expectedType.FullName)
                        {
                            channelType = channelType.GetInterface(expectedType.FullName);
                        }

                        if (channelType != null && channelType.FullName == expectedType.FullName)
                        {
                            callback = channelManager.GetChannel();
                            if (!list.Contains <TContract>(callback))
                            {
                                list.Add(callback);
                            }
                        }
                    }
                }
            }

            return(list);
        }