public void LocalCallContextDataFlowsWithExecutionContextInTaskStartNew() { const string SlotName = "Hello8"; LocalCallContextData.SetData(SlotName, "World"); var dataAccessible = false; var resetEvent = new ManualResetEvent(false); var task = Task.Factory.StartNew(() => { var data = LocalCallContextData.GetData(SlotName); dataAccessible = data != null; resetEvent.Set(); }); // check if ordinal call context data is accessible task.Wait(); Assert.IsTrue(dataAccessible); }
public void LocalCallContextDataFlowsWithExecutionContextInDeledateBeginInvoke() { const string SlotName = "Hello5"; LocalCallContextData.SetData(SlotName, "World"); var dataAccessible = false; var action = new Action(() => { var data = LocalCallContextData.GetData(SlotName); dataAccessible = data != null; }); // check if ordinal call context data is accessible var result = action.BeginInvoke(null, null); result.AsyncWaitHandle.WaitOne(); Assert.IsTrue(dataAccessible); }
/// <summary> /// Returns a channel message sink that delivers messages to the specified URL or channel data object. /// </summary> /// <param name="url">The URL to which the new sink will deliver messages. Can be null.</param> /// <param name="remoteChannelData">The channel data object of the remote host to which the new sink will deliver messages. Can be null.</param> /// <param name="objectURI">When this method returns, contains a URI of the new channel message sink that delivers messages to the specified URL or channel data object. This parameter is passed uninitialized.</param> /// <returns> /// A channel message sink that delivers messages to the specified URL or channel data object, or null if the channel cannot connect to the given endpoint. /// </returns> /// <exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception> public IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI) { objectURI = null; if (url == null) { var channelData = remoteChannelData as TcpExChannelData; if (channelData == null) { // unsupported ChannelData object return(null); } var connections = Connection.GetRunningConnectionsOfChannel(this); if (connections.All(c => c.RemoteChannelID != channelData.ChannelID)) { // unknown channel identity return(null); } // known channel is establishing back connection to us url = Manager.CreateUrl(LocalCallContextData.GetData("RemoteChannelID", channelData.ChannelID)); } if (Manager.Parse(url, out objectURI) != null) { IClientChannelSink clientChannelSink = clientSinkProvider.CreateSink(this, url, remoteChannelData); IMessageSink messageSink = clientChannelSink as IMessageSink; if (clientChannelSink != null && messageSink == null) { throw new RemotingException(LanguageResource.RemotingException_MessageSinkNotSet); } return(messageSink); } else { // unsupported URL format return(null); } }
public void LocalCallContextDataFlowsWithExecutionContextInThreadStart() { const string SlotName = "Hello7"; LocalCallContextData.SetData(SlotName, "World"); var dataAccessible = false; var resetEvent = new ManualResetEvent(false); var thread = new Thread(x => { var data = LocalCallContextData.GetData(SlotName); dataAccessible = data != null; resetEvent.Set(); }); // check if ordinal call context data is accessible thread.Start(); resetEvent.WaitOne(); Assert.IsTrue(dataAccessible); }
public void LocalCallContextDataDoestnLeaveApplicationDomain() { var domainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory }; var otherDomain = AppDomain.CreateDomain("Sandbox", null, domainSetup); otherDomain.Load(typeof(ZyanConnection).Assembly.GetName()); otherDomain.Load(typeof(LocalCallContextDataTests).Assembly.GetName()); try { const string SlotName = "Hello9"; LocalCallContextData.SetData(SlotName, "World"); var dataAccessible = LocalCallContextData.GetData(SlotName) != null; Assert.IsTrue(dataAccessible); otherDomain.DoCallBack(() => { var data = LocalCallContextData.GetData(SlotName); var accessible = data != null; AppDomain.CurrentDomain.SetData(SlotName, accessible); }); // check if ordinal call context data is not accessible dataAccessible = (bool)otherDomain.GetData(SlotName); Assert.IsFalse(dataAccessible); // check if the callback doesn't wipe out the data dataAccessible = LocalCallContextData.GetData(SlotName) != null; Assert.IsTrue(dataAccessible); } finally { AppDomain.Unload(otherDomain); } }