public DM.PetShop.Inventory.InventoryMessageResponse GetInventory() { using (ChannelWrapper<IPetShopInventoryService> wrapper = new ChannelWrapper<IPetShopInventoryService>("Inventory")) { return wrapper.Channel.GetInventory(); } }
public DM.PetShop.Accounting.AccountBalanceMessageResponse GetAccountBalance() { using (ChannelWrapper<IPetShopAccountingService> wrapper = new ChannelWrapper<IPetShopAccountingService>("Accounting")) { return wrapper.Channel.GetAccountBalance(); } }
public void ChannelWrapper_NormalizesRandomizedUrl() { var randomizedUrl = "wrap://2354gfds45#tcpex://localhost:12356/CoolService"; var originalUrl = ChannelWrapper.NormalizeUrl(randomizedUrl); Assert.IsFalse(string.IsNullOrWhiteSpace(originalUrl)); Assert.AreEqual("tcpex://localhost:12356/CoolService", originalUrl); }
/// <summary> /// open the p2p channel and register for online and offline events /// </summary> /// <param name="endpointConfigName">The configuration name used for the endpoint</param> private void OpenCore(string endpointConfigName) { callbackInstance = new SynchronizationCallback(businessLogic, synchronizationMode, reSyncInterval); //Open p2p channel channelFactory = new DuplexChannelFactory <ISynchronizedState>(callbackInstance, endpointConfigName); channelFactory.Closing += InvokeCommunicationStateChanged; channelFactory.Closed += InvokeCommunicationStateChanged; channelFactory.Faulted += InvokeCommunicationStateChanged; channelFactory.Opened += InvokeCommunicationStateChanged; channelFactory.Opening += InvokeCommunicationStateChanged; if (UseGenericResolver) { channelFactory.AddGenericResolver(); } channelFactory.BeginOpen(ar => { try { channelFactory.EndOpen(ar); } catch (Exception exception) { LogManager.GetCurrentClassLogger().Fatal(exception); return; } synchronizedStateProxy = channelFactory.CreateChannel(); channel = new ChannelWrapper((IClientChannel)synchronizedStateProxy); callbackInstance.Proxy = synchronizedStateProxy; RegisterProxyEvent(channel); /* * both receive online event but then the second participant receive Exception: * "Cannot make a call on this channel because a call to Open() is in progress." * when calling SynchronizationCallback.BeginSynchronization() from Online event handler , * this is because of issue of raising the Online event prior to the Opened state set. **/ //The Online event not raised on the first participant that is already registered channel.BeginOpen(ar2 => { try { channel.EndOpen(ar2); LogManager.GetCurrentClassLogger().Debug("channel opened"); } catch (Exception exception) { LogManager.GetCurrentClassLogger().Fatal(exception); } }, null); }, null); }
void SendTag(Tag tag, ChannelWrapper channel, string prefix = "") { if (channel.headless || tag.attachmentUrl == null || tag.attachmentUrl == "") { channel.SendMessageAsync(prefix + tag.content); } else { WebClient client = new WebClient(); Stream stream = client.OpenRead(tag.attachmentUrl); channel.channel.SendFileAsync(stream, tag.attachmentFilename, prefix + tag.content); } }
public void ChannelWrapper_RandomizesGivenUrl() { var originalUrl = "tcpex://localhost:12356/CoolService"; var randomized1 = ChannelWrapper.RandomizeUrl(originalUrl); var randomized2 = ChannelWrapper.RandomizeUrl(originalUrl); Assert.IsFalse(string.IsNullOrWhiteSpace(randomized1)); Assert.IsFalse(string.IsNullOrWhiteSpace(randomized2)); Assert.AreNotEqual(originalUrl, randomized1); Assert.AreNotEqual(originalUrl, randomized2); Assert.AreNotEqual(randomized1, randomized2); Assert.IsTrue(randomized1.EndsWith(originalUrl)); Assert.IsTrue(randomized2.EndsWith(originalUrl)); }
public void PlaceOrder(OrderMessage request) { using (TransactionScope scope = new TransactionScope()) using (ChannelWrapper<IPetShopInventoryService> inventory = new ChannelWrapper<IPetShopInventoryService>("Inventory")) using (ChannelWrapper<IPetShopAccountingService> accounting = new ChannelWrapper<IPetShopAccountingService>("Accounting")) { // update account int total = CalculateTotal(request.Body.ProductName, request.Body.Quantity); Account account = new Account(); account.Balance = total; ChargeAccountMessage accountingMsg = new ChargeAccountMessage(); accountingMsg.Body = account; try { accounting.Channel.ChargeAccount(accountingMsg); } catch (FaultException<AccountingFault> ex) { OrderFault fault = new OrderFault(); fault.Description = ex.Detail.Description; throw new FaultException<OrderFault>(fault, "Order failed"); } // update inventory UpdateInventoryMessage inventoryMsg = new UpdateInventoryMessage(); inventoryMsg.Body = request.Body; try { inventory.Channel.UpdateInventory(inventoryMsg); } catch (FaultException<InventoryFault> ex) { OrderFault fault = new OrderFault(); fault.Description = ex.Detail.Description; throw new FaultException<OrderFault>(fault, "Order failed"); } scope.Complete(); } }
private void RegisterProxy(ChannelWrapper channelWrapper) { if (channel != null) { channel.Dispose(); } channel = channelWrapper; #if DEBUG channel.Closing += (o, e) => LogManager.GetCurrentClassLogger().Debug("channel closing"); channel.Closed += (o, e) => LogManager.GetCurrentClassLogger().Debug("channel closed"); channel.Faulted += (o, e) => LogManager.GetCurrentClassLogger().Debug("channel faulted"); channel.Opened += (o, e) => LogManager.GetCurrentClassLogger().Debug("channel opened"); channel.Opening += (o, e) => LogManager.GetCurrentClassLogger().Debug("channel opening"); #endif channel.PeerNode.MessagePropagationFilter = new RemoteOnlyMessagePropagationFilter(); channel.Online += PeerNodeOnline; channel.Online += PeerNodeOffline; }
private void RegisterProxyEvent(ChannelWrapper registeredChannel) { registeredChannel.Closing += InvokeCommunicationStateChanged; registeredChannel.Closed += InvokeCommunicationStateChanged; registeredChannel.Faulted += InvokeCommunicationStateChanged; registeredChannel.Opened += InvokeCommunicationStateChanged; registeredChannel.Opening += InvokeCommunicationStateChanged; peerNode = registeredChannel.GetProperty <PeerNode>(); if (peerNode == null) { throw new InvalidOperationException("incorrect behavior - peerNode is null"); } peerNode.Online += (o, e) => InvokePeerOnline(e); peerNode.Offline += (o, e) => InvokePeerOffline(e); peerNode.Online += InvokeCommunicationStateChanged; peerNode.Offline += InvokeCommunicationStateChanged; }
public void Dispose() { if (disposed) { return; } if (channel != null) { channel.Dispose(); channel = null; } if (channelFactory != null) { channelFactory.Close(); channelFactory = null; } DisposeCallbackIfNeed(); GC.SuppressFinalize(this); disposed = true; }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp").</param> /// <param name="protocolSetup">Protocol and communication settings.</param> /// <param name="credentials">Login credentials.</param> /// <param name="autoLoginOnExpiredSession">Specifies whether the proxy should relogin automatically when the session expired.</param> /// <param name="keepSessionAlive">Specifies whether the session should be automaticly kept alive.</param> public ZyanConnection(string serverUrl, IClientProtocolSetup protocolSetup, AuthCredentials credentials, bool autoLoginOnExpiredSession, bool keepSessionAlive) { if (string.IsNullOrEmpty(serverUrl)) { throw new ArgumentException(LanguageResource.ArgumentException_ServerUrlMissing, "serverUrl"); } if (protocolSetup == null) { // try to select the protocol automatically protocolSetup = ClientProtocolSetup.GetClientProtocol(serverUrl); if (protocolSetup == null) { throw new ArgumentNullException("protocolSetup"); } } if (!protocolSetup.IsUrlValid(serverUrl)) { throw new ArgumentException(LanguageResource.ArgumentException_ServerUrlIsInvalid, "serverUrl"); } _proxies = new List <WeakReference>(); _protocolSetup = protocolSetup; _sessionID = Guid.NewGuid(); _serverUrl = serverUrl; _autoLoginOnExpiredSession = autoLoginOnExpiredSession; _keepSessionAlive = keepSessionAlive; if (_autoLoginOnExpiredSession) { _autoLoginCredentials = credentials; } _serializationHandling = new SerializationHandlerRepository(); CallInterceptionEnabled = false; _callInterceptors = new CallInterceptorCollection(); RegisterStandardSerializationHandlers(); string[] addressParts = _serverUrl.Split('/'); _componentHostName = addressParts[addressParts.Length - 1]; _remotingChannel = _protocolSetup.CreateChannel(); if (!ZyanSettings.DisableUrlRandomization) { _remotingChannel = ChannelWrapper.WrapChannel(_remotingChannel, _protocolSetup.ChannelName); } if (_remotingChannel != null) { var registeredChannel = ChannelServices.GetChannel(_remotingChannel.ChannelName); if (registeredChannel == null) { ChannelServices.RegisterChannel(_remotingChannel, false); } else { _remotingChannel = registeredChannel; } } else { throw new ApplicationException(LanguageResource.ApplicationException_NoChannelCreated); } var connectionNotification = _remotingChannel as IConnectionNotification; if (connectionNotification != null) { connectionNotification.ConnectionEstablished += Channel_ConnectionEstablished; } string channelName = _remotingChannel.ChannelName; if (credentials == null) { credentials = new AuthCredentials(); } try { credentials.Authenticate(_sessionID, RemoteDispatcher); _registeredComponents = new List <ComponentInfo>(RemoteDispatcher.GetRegisteredComponents()); _sessionAgeLimit = RemoteDispatcher.SessionAgeLimit; } catch (Exception ex) { // unregister remoting channel var registeredChannel = ChannelServices.GetChannel(channelName); if (registeredChannel != null) { ChannelServices.UnregisterChannel(registeredChannel); } // dispose channel if it's disposable var disposableChannel = registeredChannel as IDisposable; if (disposableChannel != null) { disposableChannel.Dispose(); } _remotingChannel = null; _remoteDispatcher = null; throw ex.PreserveStackTrace(); } var reconnectEvents = new Action(ReconnectRemoteEventsCore); var debounceInterval = ZyanSettings.ReconnectRemoteEventsDebounceInterval.TotalMilliseconds; ReconnectRemoteEvents = reconnectEvents.Debounce((int)debounceInterval); StartKeepSessionAliveTimer(); lock (_connections) { _connections.Add(this); } }
public PollingConsumer() { _channelWrapper = ChannelFactory.CreateChannel(); _thread = new Thread(Start); _thread.Start(_channelWrapper.Channel); }
// ------------------------------------------------------------------------------------------------------ private void _addChannelWrapper(ChannelConfiguration cfg) { ChannelWrapper wrapper = new ChannelWrapper(cfg.buffer); mChannelWrappers.Add(wrapper); EEGChannelGraph graph = new EEGChannelGraph(); mGraphConfigs[wrapper] = cfg; mGraphs[wrapper] = graph; Controls.Add(graph); }
public NotificationConsumer() { _channelWrapper = ChannelFactory.CreateChannel(); Start(_channelWrapper.Channel); }
private void OnBytesReceived(object o, ChannelWrapper.BytesReceivedEventArgs e) { Interlocked.Add(ref bytesReceived, e.Size); receivedData.Write(e.Buffer, e.Offset, e.Size); // without proceed nothing works :) e.Proceed(); }