GetChannel() private method

private GetChannel ( int index ) : IChannel
index int
return IChannel
Example #1
0
        }     // NotifyProfiler

        // This is a helper used by UrlObjRef's.
        // Finds an http channel and returns first url for this object.
        internal static String FindFirstHttpUrlForObject(String objectUri)
        {
            if (objectUri == null)
            {
                return(null);
            }

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            for (int i = 0; i < count; i++)
            {
                if (regChnlList.IsReceiver(i))
                {
                    IChannelReceiver chnl     = (IChannelReceiver)regChnlList.GetChannel(i);
                    String           chnlType = chnl.GetType().FullName;
                    if ((String.CompareOrdinal(chnlType, "System.Runtime.Remoting.Channels.Http.HttpChannel") == 0) ||
                        (String.CompareOrdinal(chnlType, "System.Runtime.Remoting.Channels.Http.HttpServerChannel") == 0))
                    {
                        String[] urls = chnl.GetUrlsForUri(objectUri);
                        if ((urls != null) && (urls.Length > 0))
                        {
                            return(urls[0]);
                        }
                    }
                }
            }

            return(null);
        } // FindFirstHttpUrlForObject
Example #2
0
        internal static string FindFirstHttpUrlForObject(string objectUri)
        {
            if (objectUri == null)
            {
                return((string)null);
            }
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int count = registeredChannelList.Count;

            for (int index = 0; index < count; ++index)
            {
                if (registeredChannelList.IsReceiver(index))
                {
                    IChannelReceiver channelReceiver = (IChannelReceiver)registeredChannelList.GetChannel(index);
                    string           fullName        = channelReceiver.GetType().FullName;
                    if (string.CompareOrdinal(fullName, "System.Runtime.Remoting.Channels.Http.HttpChannel") == 0 || string.CompareOrdinal(fullName, "System.Runtime.Remoting.Channels.Http.HttpServerChannel") == 0)
                    {
                        string[] urlsForUri = channelReceiver.GetUrlsForUri(objectUri);
                        if (urlsForUri != null && urlsForUri.Length != 0)
                        {
                            return(urlsForUri[0]);
                        }
                    }
                }
            }
            return((string)null);
        }
Example #3
0
        internal static IMessageSink CreateMessageSink(string url, object data, out string objectURI)
        {
            IMessageSink messageSink = (IMessageSink)null;

            objectURI = (string)null;
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int count = registeredChannelList.Count;

            for (int index = 0; index < count; ++index)
            {
                if (registeredChannelList.IsSender(index))
                {
                    messageSink = ((IChannelSender)registeredChannelList.GetChannel(index)).CreateMessageSink(url, data, out objectURI);
                    if (messageSink != null)
                    {
                        break;
                    }
                }
            }
            if (objectURI == null)
            {
                objectURI = url;
            }
            return(messageSink);
        }
Example #4
0
        } // RegisteredChannels

        internal static IMessageSink CreateMessageSink(String url, Object data, out String objectURI)
        {
            BCLDebug.Trace("REMOTE", "ChannelServices::CreateMessageSink for url " + url + "\n");
            IMessageSink msgSink = null;

            objectURI = null;

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            for (int i = 0; i < count; i++)
            {
                if (regChnlList.IsSender(i))
                {
                    IChannelSender chnl = (IChannelSender)regChnlList.GetChannel(i);
                    msgSink = chnl.CreateMessageSink(url, data, out objectURI);

                    if (msgSink != null)
                    {
                        break;
                    }
                }
            }

            // If the object uri has not been set, set it to the url as
            // default value
            if (null == objectURI)
            {
                objectURI = url;
            }

            return(msgSink);
        } // CreateMessageSink
 internal static string FindFirstHttpUrlForObject(string objectUri)
 {
     if (objectUri != null)
     {
         RegisteredChannelList list = s_registeredChannels;
         int count = list.Count;
         for (int i = 0; i < count; i++)
         {
             if (list.IsReceiver(i))
             {
                 IChannelReceiver channel  = (IChannelReceiver)list.GetChannel(i);
                 string           fullName = channel.GetType().FullName;
                 if ((string.CompareOrdinal(fullName, "System.Runtime.Remoting.Channels.Http.HttpChannel") == 0) || (string.CompareOrdinal(fullName, "System.Runtime.Remoting.Channels.Http.HttpServerChannel") == 0))
                 {
                     string[] urlsForUri = channel.GetUrlsForUri(objectUri);
                     if ((urlsForUri != null) && (urlsForUri.Length > 0))
                     {
                         return(urlsForUri[0]);
                     }
                 }
             }
         }
     }
     return(null);
 }
        internal static IMessageSink CreateMessageSink(string url, object data, out string objectURI)
        {
            IMessageSink sink = null;

            objectURI = null;
            RegisteredChannelList list = s_registeredChannels;
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                if (list.IsSender(i))
                {
                    sink = ((IChannelSender)list.GetChannel(i)).CreateMessageSink(url, data, out objectURI);
                    if (sink != null)
                    {
                        break;
                    }
                }
            }
            if (objectURI == null)
            {
                objectURI = url;
            }
            return(sink);
        }
Example #7
0
        public static String[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (null == obj)
            {
                return(null);
            }

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            Hashtable table = new Hashtable();
            bool      fServer;
            Identity  id = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (null != id)
            {
                String uri = id.ObjURI;

                if (null != uri)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (regChnlList.IsReceiver(i))
                        {
                            try
                            {
                                String[] urls = ((IChannelReceiver)regChnlList.GetChannel(i)).GetUrlsForUri(uri);
                                // Add the strings to the table
                                for (int j = 0; j < urls.Length; j++)
                                {
                                    table.Add(urls[j], urls[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                                // We do not count the channels that do not
                                // support this method
                            }
                        }
                    }
                }
            }

            // copy url's into string array
            ICollection keys = table.Keys;

            String[] urlList = new String[keys.Count];
            int      co      = 0;

            foreach (String key in keys)
            {
                urlList[co++] = key;
            }
            return(urlList);
        }
Example #8
0
        private static object[] CollectChannelDataFromChannels()
        {
            RemotingServices.RegisterWellKnownChannels();
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int count         = registeredChannelList.Count;
            int receiverCount = registeredChannelList.ReceiverCount;

            object[] array = new object[receiverCount];
            int      num   = 0;
            int      i     = 0;
            int      num2  = 0;

            while (i < count)
            {
                IChannel channel = registeredChannelList.GetChannel(i);
                if (channel == null)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[]
                    {
                        ""
                    }));
                }
                if (registeredChannelList.IsReceiver(i))
                {
                    object channelData = ((IChannelReceiver)channel).ChannelData;
                    array[num2] = channelData;
                    if (channelData != null)
                    {
                        num++;
                    }
                    num2++;
                }
                i++;
            }
            if (num != receiverCount)
            {
                object[] array2 = new object[num];
                int      num3   = 0;
                for (int j = 0; j < receiverCount; j++)
                {
                    object obj = array[j];
                    if (obj != null)
                    {
                        array2[num3++] = obj;
                    }
                }
                array = array2;
            }
            return(array);
        }
        public static IChannel GetChannel(String name)
        {
            RegisteredChannelList regChnlList = s_registeredChannels;

            int matchingIdx = regChnlList.FindChannelIndex(name);

            if (0 <= matchingIdx)
            {
                return(regChnlList.GetChannel(matchingIdx));
            }
            else
            {
                return(null);
            }
        } // GetChannel
        private static object[] CollectChannelDataFromChannels()
        {
            RemotingServices.RegisterWellKnownChannels();
            RegisteredChannelList list = s_registeredChannels;
            int count         = list.Count;
            int receiverCount = list.ReceiverCount;

            object[] objArray = new object[receiverCount];
            int      num3     = 0;
            int      index    = 0;
            int      num5     = 0;

            while (index < count)
            {
                IChannel channel = list.GetChannel(index);
                if (channel == null)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[] { "" }));
                }
                if (list.IsReceiver(index))
                {
                    object channelData = ((IChannelReceiver)channel).ChannelData;
                    objArray[num5] = channelData;
                    if (channelData != null)
                    {
                        num3++;
                    }
                    num5++;
                }
                index++;
            }
            if (num3 == receiverCount)
            {
                return(objArray);
            }
            object[] objArray2 = new object[num3];
            int      num6      = 0;

            for (int i = 0; i < receiverCount; i++)
            {
                object obj3 = objArray[i];
                if (obj3 != null)
                {
                    objArray2[num6++] = obj3;
                }
            }
            return(objArray2);
        }
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            bool flag;

            if (obj == null)
            {
                return(null);
            }
            RegisteredChannelList list = s_registeredChannels;
            int       count            = list.Count;
            Hashtable hashtable        = new Hashtable();
            Identity  identity         = MarshalByRefObject.GetIdentity(obj, out flag);

            if (identity != null)
            {
                string objURI = identity.ObjURI;
                if (objURI != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (list.IsReceiver(i))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)list.GetChannel(i)).GetUrlsForUri(objURI);
                                for (int j = 0; j < urlsForUri.Length; j++)
                                {
                                    hashtable.Add(urlsForUri[j], urlsForUri[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] strArray2 = new string[keys.Count];
            int      num4      = 0;

            foreach (string str2 in keys)
            {
                strArray2[num4++] = str2;
            }
            return(strArray2);
        }
Example #12
0
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (obj == null)
            {
                return(null);
            }
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int       count     = registeredChannelList.Count;
            Hashtable hashtable = new Hashtable();
            bool      flag;
            Identity  identity = MarshalByRefObject.GetIdentity(obj, out flag);

            if (identity != null)
            {
                string objURI = identity.ObjURI;
                if (objURI != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (registeredChannelList.IsReceiver(i))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)registeredChannelList.GetChannel(i)).GetUrlsForUri(objURI);
                                for (int j = 0; j < urlsForUri.Length; j++)
                                {
                                    hashtable.Add(urlsForUri[j], urlsForUri[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] array = new string[keys.Count];
            int      num   = 0;

            foreach (object obj2 in keys)
            {
                string text = (string)obj2;
                array[num++] = text;
            }
            return(array);
        }
Example #13
0
        } // FindFirstHttpUrlForObject

        //
        // DEBUG Helpers
        //   Note: These methods should be included even in retail builds so that
        //     they can be called from the debugger.
        //
#if DEBUG
        internal static void DumpRegisteredChannels()
        {
            // To use from cordbg:
            //   f System.Runtime.Remoting.Channels.ChannelServices::DumpRegisteredChannels

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            Console.Error.WriteLine("Registered Channels:");

            for (int i = 0; i < count; i++)
            {
                IChannel chnl = regChnlList.GetChannel(i);
                Console.Error.WriteLine(chnl);
            }
        } // DumpRegisteredChannels
Example #14
0
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (obj == null)
            {
                return((string[])null);
            }
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int       count     = registeredChannelList.Count;
            Hashtable hashtable = new Hashtable();
            bool      fServer;
            Identity  identity = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (identity != null)
            {
                string objUri = identity.ObjURI;
                if (objUri != null)
                {
                    for (int index1 = 0; index1 < count; ++index1)
                    {
                        if (registeredChannelList.IsReceiver(index1))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)registeredChannelList.GetChannel(index1)).GetUrlsForUri(objUri);
                                for (int index2 = 0; index2 < urlsForUri.Length; ++index2)
                                {
                                    hashtable.Add((object)urlsForUri[index2], (object)urlsForUri[index2]);
                                }
                            }
                            catch (NotSupportedException ex)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] strArray = new string[keys.Count];
            int      num      = 0;

            foreach (string str in (IEnumerable)keys)
            {
                strArray[num++] = str;
            }
            return(strArray);
        }
Example #15
0
        private static object[] CollectChannelDataFromChannels()
        {
            RemotingServices.RegisterWellKnownChannels();
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int count         = registeredChannelList.Count;
            int receiverCount = registeredChannelList.ReceiverCount;

            object[] objArray1 = new object[receiverCount];
            int      length    = 0;
            int      index1    = 0;
            int      index2    = 0;

            for (; index1 < count; ++index1)
            {
                IChannel channel = registeredChannelList.GetChannel(index1);
                if (channel == null)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", (object)""));
                }
                if (registeredChannelList.IsReceiver(index1))
                {
                    object channelData = ((IChannelReceiver)channel).ChannelData;
                    objArray1[index2] = channelData;
                    if (channelData != null)
                    {
                        ++length;
                    }
                    ++index2;
                }
            }
            if (length != receiverCount)
            {
                object[] objArray2 = new object[length];
                int      num       = 0;
                for (int index3 = 0; index3 < receiverCount; ++index3)
                {
                    object obj = objArray1[index3];
                    if (obj != null)
                    {
                        objArray2[num++] = obj;
                    }
                }
                objArray1 = objArray2;
            }
            return(objArray1);
        }
Example #16
0
        public static IChannel GetChannel(string name)
        {
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int channelIndex = registeredChannelList.FindChannelIndex(name);

            if (0 > channelIndex)
            {
                return((IChannel)null);
            }
            IChannel channel = registeredChannelList.GetChannel(channelIndex);

            if (channel is CrossAppDomainChannel || channel is CrossContextChannel)
            {
                return((IChannel)null);
            }
            return(channel);
        }
        public static IChannel GetChannel(string name)
        {
            RegisteredChannelList list = s_registeredChannels;
            int index = list.FindChannelIndex(name);

            if (0 > index)
            {
                return(null);
            }
            IChannel channel = list.GetChannel(index);

            if ((channel is CrossAppDomainChannel) || (channel is CrossContextChannel))
            {
                return(null);
            }
            return(channel);
        }
Example #18
0
 private static void StopListeningOnAllChannels()
 {
     try
     {
         RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
         int count = registeredChannelList.Count;
         for (int index = 0; index < count; ++index)
         {
             if (registeredChannelList.IsReceiver(index))
             {
                 ((IChannelReceiver)registeredChannelList.GetChannel(index)).StopListening((object)null);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
 private static void StopListeningOnAllChannels()
 {
     try
     {
         RegisteredChannelList list = s_registeredChannels;
         int count = list.Count;
         for (int i = 0; i < count; i++)
         {
             if (list.IsReceiver(i))
             {
                 ((IChannelReceiver)list.GetChannel(i)).StopListening(null);
             }
         }
     }
     catch (Exception)
     {
     }
 }
Example #20
0
 private static void StopListeningOnAllChannels()
 {
     try
     {
         RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
         int count = registeredChannelList.Count;
         for (int i = 0; i < count; i++)
         {
             if (registeredChannelList.IsReceiver(i))
             {
                 IChannelReceiver channelReceiver = (IChannelReceiver)registeredChannelList.GetChannel(i);
                 channelReceiver.StopListening(null);
             }
         }
     }
     catch (Exception)
     {
     }
 }
Example #21
0
        private static void StopListeningOnAllChannels()
        {
            try
            {
                RegisteredChannelList regChnlList = s_registeredChannels;
                int count = regChnlList.Count;

                for (int i = 0; i < count; i++)
                {
                    if (regChnlList.IsReceiver(i))
                    {
                        IChannelReceiver chnl = (IChannelReceiver)regChnlList.GetChannel(i);
                        chnl.StopListening(null);
                    }
                }
            }
            catch (Exception)
            {
                // Ignore ... appdomain is shutting down..
            }
        }
Example #22
0
        public static IChannel GetChannel(String name)
        {
            RegisteredChannelList regChnlList = s_registeredChannels;

            int matchingIdx = regChnlList.FindChannelIndex(name);

            if (0 <= matchingIdx)
            {
                IChannel channel = regChnlList.GetChannel(matchingIdx);
                if ((channel is CrossAppDomainChannel) || (channel is CrossContextChannel))
                {
                    return(null);
                }
                else
                {
                    return(channel);
                }
            }
            else
            {
                return(null);
            }
        } // GetChannel
Example #23
0
        } // RefreshChannelData

        private static Object[] CollectChannelDataFromChannels()
        {
            // Ensure that our native cross-context & cross-domain channels
            // are registered
            RemotingServices.RegisterWellKnownChannels();

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            // Compute the number of channels that implement IChannelReceiver
            int numChnls = regChnlList.ReceiverCount;

            // Allocate array for channel data
            Object[] data = new Object[numChnls];

            // we need to remove null entries
            int nonNullDataCount = 0;

            // Set the channel data, names and mime types
            for (int i = 0, j = 0; i < count; i++)
            {
                IChannel chnl = regChnlList.GetChannel(i);

                if (null == chnl)
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_ChannelNotRegistered"), ""));
                }

                if (regChnlList.IsReceiver(i))
                {
                    BCLDebug.Trace("REMOTE", "Setting info for receiver " + j + "\n");
                    // Extract the data
                    Object channelData = ((IChannelReceiver)chnl).ChannelData;
                    data[j] = channelData;
                    if (channelData != null)
                    {
                        nonNullDataCount++;
                    }

                    // Increment the counter
                    j++;
                }
            }

            if (nonNullDataCount != numChnls)
            {
                // there were null entries, so remove them.
                Object[] nonNullData    = new Object[nonNullDataCount];
                int      nonNullCounter = 0;
                for (int co = 0; co < numChnls; co++)
                {
                    Object channelData = data[co];
                    if (channelData != null)
                    {
                        nonNullData[nonNullCounter++] = channelData;
                    }
                }

                data = nonNullData;
            }

            return(data);
        } // CollectChannelDataFromChannels