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);
 }
Exemple #2
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
Exemple #3
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
Exemple #4
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);
        }
        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);
        }
Exemple #6
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);
        }
Exemple #7
0
        public unsafe static void UnregisterChannel(IChannel chnl)
        {
            bool flag = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref flag);
                if (chnl != null)
                {
                    RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                    int num = registeredChannelList.FindChannelIndex(chnl);
                    if (-1 == num)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[]
                        {
                            chnl.ChannelName
                        }));
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] array           = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver    channelReceiver = chnl as IChannelReceiver;
                    if (channelReceiver != null)
                    {
                        channelReceiver.StopListening(null);
                    }
                    int num2 = 0;
                    int i    = 0;
                    while (i < registeredChannels.Length)
                    {
                        if (i == num)
                        {
                            i++;
                        }
                        else
                        {
                            array[num2] = registeredChannels[i];
                            num2++;
                            i++;
                        }
                    }
                    if (ChannelServices.perf_Contexts != null)
                    {
                        ChannelServices.perf_Contexts->cChannels--;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(array);
                }
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
        public static unsafe void UnregisterChannel(IChannel chnl)
        {
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(s_channelLock, ref lockTaken);
                if (chnl != null)
                {
                    RegisteredChannelList list = s_registeredChannels;
                    int num = list.FindChannelIndex(chnl);
                    if (-1 == num)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[] { chnl.ChannelName }));
                    }
                    RegisteredChannel[] registeredChannels = list.RegisteredChannels;
                    RegisteredChannel[] channels           = null;
                    channels = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver receiver = chnl as IChannelReceiver;
                    if (receiver != null)
                    {
                        receiver.StopListening(null);
                    }
                    int index = 0;
                    int num3  = 0;
                    while (num3 < registeredChannels.Length)
                    {
                        if (num3 == num)
                        {
                            num3++;
                        }
                        else
                        {
                            channels[index] = registeredChannels[num3];
                            index++;
                            num3++;
                        }
                    }
                    if (perf_Contexts != null)
                    {
                        perf_Contexts.cChannels--;
                    }
                    s_registeredChannels = new RegisteredChannelList(channels);
                }
                RefreshChannelData();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        public static unsafe void UnregisterChannel(IChannel chnl)
        {
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref lockTaken);
                if (chnl != null)
                {
                    RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                    int channelIndex = registeredChannelList.FindChannelIndex(chnl);
                    if (-1 == channelIndex)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", (object)chnl.ChannelName));
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] channels           = new RegisteredChannel[registeredChannels.Length - 1];
                    IChannelReceiver    channelReceiver    = chnl as IChannelReceiver;
                    if (channelReceiver != null)
                    {
                        channelReceiver.StopListening((object)null);
                    }
                    int index1 = 0;
                    int index2 = 0;
                    while (index2 < registeredChannels.Length)
                    {
                        if (index2 == channelIndex)
                        {
                            ++index2;
                        }
                        else
                        {
                            channels[index1] = registeredChannels[index2];
                            ++index1;
                            ++index2;
                        }
                    }
                    if ((IntPtr)ChannelServices.perf_Contexts != IntPtr.Zero)
                    {
                        --ChannelServices.perf_Contexts->cChannels;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(channels);
                }
                ChannelServices.RefreshChannelData();
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
Exemple #11
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
Exemple #13
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);
        }
        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);
        }
Exemple #16
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
Exemple #17
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);
        }
        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);
        }
Exemple #19
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);
        }
Exemple #20
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);
        }
 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)
     {
     }
 }
Exemple #22
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)
     {
     }
 }
Exemple #23
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)
     {
     }
 }
Exemple #24
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..
            }
        }
Exemple #25
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
Exemple #26
0
        unsafe internal static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            // Validate arguments
            if (null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }

            bool fLocked = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.ReliableEnter(s_channelLock, ref fLocked);
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;

                // Check to make sure that the channel has not been registered
                if ((chnlName == null) ||
                    (chnlName.Length == 0) ||
                    (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null)
                        {
                            securableChannel.IsSecured = ensureSecurity;
                        }
                        else
                        {
                            throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Channel_CannotBeSecured"), chnl.ChannelName ?? chnl.ToString()));
                        }
                    }
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {
                        newList = new RegisteredChannel[1];
                    }
                    else
                    {
                        newList = new RegisteredChannel[oldList.Length + 1];
                    }

                    if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        // Register a unload handler only once and if the channel being registered
                        // is not the x-domain channel. x-domain channel does nothing inside its
                        // StopListening implementation
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);
                        unloadHandlerRegistered = true;
                    }

                    // Add the interface to the array in priority order
                    int priority = chnl.ChannelPriority;
                    int current  = 0;

                    // Find the place in the array to insert
                    while (current < oldList.Length)
                    {
                        RegisteredChannel oldChannel = oldList[current];
                        if (priority > oldChannel.Channel.ChannelPriority)
                        {
                            newList[current] = new RegisteredChannel(chnl);
                            break;
                        }
                        else
                        {
                            newList[current] = oldChannel;
                            current++;
                        }
                    }

                    if (current == oldList.Length)
                    {
                        // chnl has lower priority than all old channels, so we insert
                        //   it at the end of the list.
                        newList[oldList.Length] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        // finish copying rest of the old channels
                        while (current < oldList.Length)
                        {
                            newList[current + 1] = oldList[current];
                            current++;
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            {
                if (fLocked)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        } // RegisterChannelInternal
        [System.Security.SecurityCritical]  // auto-generated 
        unsafe internal static void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        { 
            // Validate arguments 
            if(null == chnl)
            { 
                throw new ArgumentNullException("chnl");
            }
            Contract.EndContractBlock();
 
            bool fLocked = false;
            RuntimeHelpers.PrepareConstrainedRegions(); 
            try 
            {
                Monitor.Enter(s_channelLock, ref fLocked); 
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;
 
                // Check to make sure that the channel has not been registered
                if((chnlName == null) || 
                   (chnlName.Length == 0) || 
                   (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                { 
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null) 
                            securableChannel.IsSecured = ensureSecurity;
                        else 
                            throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", chnl.ChannelName??chnl.ToString())); 

                    } 
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    { 
                        newList = new RegisteredChannel[1];
                    } 
                    else 
                        newList = new RegisteredChannel[oldList.Length + 1];
 
                    if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        // Register a unload handler only once and if the channel being registered
                        // is not the x-domain channel. x-domain channel does nothing inside its 
                        // StopListening implementation
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler); 
                        unloadHandlerRegistered = true; 
                    }
 
                    // Add the interface to the array in priority order
                    int priority = chnl.ChannelPriority;
                    int current = 0;
 
                    // Find the place in the array to insert
                    while (current < oldList.Length) 
                    { 
                        RegisteredChannel oldChannel = oldList[current];
                        if (priority > oldChannel.Channel.ChannelPriority) 
                        {
                            newList[current] = new RegisteredChannel(chnl);
                            break;
                        } 
                        else
                        { 
                            newList[current] = oldChannel; 
                            current++;
                        } 
                    }

                    if (current == oldList.Length)
                    { 
                        // chnl has lower priority than all old channels, so we insert
                        //   it at the end of the list. 
                        newList[oldList.Length] = new RegisteredChannel(chnl); 
                    }
                    else 
                    {
                        // finish copying rest of the old channels
                        while (current < oldList.Length)
                        { 
                            newList[current + 1] = oldList[current];
                            current++; 
                        } 
                    }
 
                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels++;
                    }
 
                    s_registeredChannels = new RegisteredChannelList(newList);
                } 
                else 
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", chnl.ChannelName)); 
                }

                RefreshChannelData();
            } // lock (s_channelLock) 
            finally
            { 
                if (fLocked) 
                {
                    Monitor.Exit(s_channelLock); 
                }
            }
        } // RegisterChannelInternal
        unsafe public static void UnregisterChannel(IChannel chnl)
        { 
            // we allow null to be passed in, so we can use this api to trigger the
            //   refresh of the channel data <

 
            bool fLocked = false;
            RuntimeHelpers.PrepareConstrainedRegions(); 
            try 
            {
                Monitor.Enter(s_channelLock, ref fLocked); 
                if (chnl != null)
                {
                    RegisteredChannelList regChnlList = s_registeredChannels;
 
                    // Check to make sure that the channel has been registered
                    int matchingIdx = regChnlList.FindChannelIndex(chnl); 
                    if(-1 == matchingIdx) 
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", chnl.ChannelName)); 
                    }

                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null; 
                    Contract.Assert((oldList != null) && (oldList.Length != 0), "channel list should not be empty");
 
                    newList = new RegisteredChannel[oldList.Length - 1]; 

                    // Call stop listening on the channel if it is a receiver. 
                    IChannelReceiver srvChannel = chnl as IChannelReceiver;
                    if (srvChannel != null)
                        srvChannel.StopListening(null);
 
                    int current = 0;
                    int oldPos = 0; 
                    while (oldPos < oldList.Length) 
                    {
                        if (oldPos == matchingIdx) 
                        {
                            oldPos++;
                        }
                        else 
                        {
                            newList[current] = oldList[oldPos]; 
                            current++; 
                            oldPos++;
                        } 
                    }

                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels--; 
                    }
 
                    s_registeredChannels = new RegisteredChannelList(newList); 
                }
 
                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            { 
                if (fLocked)
                { 
                    Monitor.Exit(s_channelLock); 
                }
            } 
        } // UnregisterChannel
Exemple #29
0
        internal static unsafe void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
        {
            if (chnl == null)
            {
                throw new ArgumentNullException("chnl");
            }
            bool lockTaken = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.Enter(ChannelServices.s_channelLock, ref lockTaken);
                string channelName = chnl.ChannelName;
                RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
                if (channelName == null || channelName.Length == 0 || -1 == registeredChannelList.FindChannelIndex(chnl.ChannelName))
                {
                    if (ensureSecurity)
                    {
                        ISecurableChannel securableChannel = chnl as ISecurableChannel;
                        if (securableChannel != null)
                        {
                            securableChannel.IsSecured = ensureSecurity;
                        }
                        else
                        {
                            throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", (object)(chnl.ChannelName ?? chnl.ToString())));
                        }
                    }
                    RegisteredChannel[] registeredChannels = registeredChannelList.RegisteredChannels;
                    RegisteredChannel[] channels           = registeredChannels != null ? new RegisteredChannel[registeredChannels.Length + 1] : new RegisteredChannel[1];
                    if (!ChannelServices.unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
                    {
                        AppDomain.CurrentDomain.DomainUnload   += new EventHandler(ChannelServices.UnloadHandler);
                        ChannelServices.unloadHandlerRegistered = true;
                    }
                    int channelPriority = chnl.ChannelPriority;
                    int index;
                    for (index = 0; index < registeredChannels.Length; ++index)
                    {
                        RegisteredChannel registeredChannel = registeredChannels[index];
                        if (channelPriority > registeredChannel.Channel.ChannelPriority)
                        {
                            channels[index] = new RegisteredChannel(chnl);
                            break;
                        }
                        channels[index] = registeredChannel;
                    }
                    if (index == registeredChannels.Length)
                    {
                        channels[registeredChannels.Length] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        for (; index < registeredChannels.Length; ++index)
                        {
                            channels[index + 1] = registeredChannels[index];
                        }
                    }
                    if ((IntPtr)ChannelServices.perf_Contexts != IntPtr.Zero)
                    {
                        ++ChannelServices.perf_Contexts->cChannels;
                    }
                    ChannelServices.s_registeredChannels = new RegisteredChannelList(channels);
                    ChannelServices.RefreshChannelData();
                }
                else
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", (object)chnl.ChannelName));
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(ChannelServices.s_channelLock);
                }
            }
        }
Exemple #30
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
Exemple #31
0
        unsafe public static void UnregisterChannel(IChannel chnl)
        {
            // we allow null to be passed in, so we can use this api to trigger the
            //   refresh of the channel data

            bool fLocked = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                Monitor.ReliableEnter(s_channelLock, ref fLocked);
                if (chnl != null)
                {
                    RegisteredChannelList regChnlList = s_registeredChannels;

                    // Check to make sure that the channel has been registered
                    int matchingIdx = regChnlList.FindChannelIndex(chnl);
                    if (-1 == matchingIdx)
                    {
                        throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_ChannelNotRegistered"), chnl.ChannelName));
                    }

                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    BCLDebug.Assert((oldList != null) && (oldList.Length != 0), "channel list should not be empty");

                    newList = new RegisteredChannel[oldList.Length - 1];

                    // Call stop listening on the channel if it is a receiver.
                    IChannelReceiver srvChannel = chnl as IChannelReceiver;
                    if (srvChannel != null)
                    {
                        srvChannel.StopListening(null);
                    }

                    int current = 0;
                    int oldPos  = 0;
                    while (oldPos < oldList.Length)
                    {
                        if (oldPos == matchingIdx)
                        {
                            oldPos++;
                        }
                        else
                        {
                            newList[current] = oldList[oldPos];
                            current++;
                            oldPos++;
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels--;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }

                RefreshChannelData();
            } // lock (s_channelLock)
            finally
            {
                if (fLocked)
                {
                    Monitor.Exit(s_channelLock);
                }
            }
        } // UnregisterChannel
 internal static unsafe void RegisterChannelInternal(IChannel chnl, bool ensureSecurity)
 {
     if (chnl == null)
     {
         throw new ArgumentNullException("chnl");
     }
     bool lockTaken = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(s_channelLock, ref lockTaken);
         string channelName = chnl.ChannelName;
         RegisteredChannelList list = s_registeredChannels;
         if (((channelName != null) && (channelName.Length != 0)) && (-1 != list.FindChannelIndex(chnl.ChannelName)))
         {
             goto Label_0180;
         }
         if (ensureSecurity)
         {
             ISecurableChannel channel = chnl as ISecurableChannel;
             if (channel == null)
             {
                 object[] values = new object[] { chnl.ChannelName ?? chnl.ToString() };
                 throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CannotBeSecured", values));
             }
             channel.IsSecured = ensureSecurity;
         }
         RegisteredChannel[] registeredChannels = list.RegisteredChannels;
         RegisteredChannel[] channels = null;
         if (registeredChannels == null)
         {
             channels = new RegisteredChannel[1];
         }
         else
         {
             channels = new RegisteredChannel[registeredChannels.Length + 1];
         }
         if (!unloadHandlerRegistered && !(chnl is CrossAppDomainChannel))
         {
             AppDomain.CurrentDomain.DomainUnload += new EventHandler(ChannelServices.UnloadHandler);
             unloadHandlerRegistered = true;
         }
         int channelPriority = chnl.ChannelPriority;
         int index = 0;
         while (index < registeredChannels.Length)
         {
             RegisteredChannel channel2 = registeredChannels[index];
             if (channelPriority > channel2.Channel.ChannelPriority)
             {
                 channels[index] = new RegisteredChannel(chnl);
                 break;
             }
             channels[index] = channel2;
             index++;
         }
         if (index != registeredChannels.Length)
         {
             goto Label_014F;
         }
         channels[registeredChannels.Length] = new RegisteredChannel(chnl);
         goto Label_0157;
     Label_013D:
         channels[index + 1] = registeredChannels[index];
         index++;
     Label_014F:
         if (index < registeredChannels.Length)
         {
             goto Label_013D;
         }
     Label_0157:
         if (perf_Contexts != null)
         {
             perf_Contexts.cChannels++;
         }
         s_registeredChannels = new RegisteredChannelList(channels);
         goto Label_01A4;
     Label_0180:;
         throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered", new object[] { chnl.ChannelName }));
     Label_01A4:
         RefreshChannelData();
     }
     finally
     {
         if (lockTaken)
         {
             Monitor.Exit(s_channelLock);
         }
     }
 }
Exemple #33
0
        unsafe internal static void RegisterChannelInternal(IChannel chnl)
        {
            // Validate arguments
            if(null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }
        
            lock (s_channelLock)
            {
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;
        
                // Check to make sure that the channel has not been registered
                if((chnlName == null) ||
                   (chnlName.Length == 0) ||
                   (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {                                            
                        newList = new RegisteredChannel[1];
                    }
                    else
                        newList = new RegisteredChannel[oldList.Length + 1];

                    if (newList.Length == 1)
                    {
                        // This is the first channel being registered.
                        //   (we know this since the x-appdmn channel can't be unregistered).
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);
                        
                        newList[0] = new RegisteredChannel(chnl);
                    }
                    else
                    {                                                    
                        // Add the interface to the array in priority order
                        int priority = chnl.ChannelPriority;
                        int current = 0;
        
                        // Find the place in the array to insert
                        while (current < oldList.Length)
                        {
                            RegisteredChannel oldChannel = oldList[current];
                            if (priority > oldChannel.Channel.ChannelPriority)
                            {
                                newList[current] = new RegisteredChannel(chnl);
                                break;
                            }
                            else
                            {
                                newList[current] = oldChannel;
                                current++;
                            }
                        }

                        if (current == oldList.Length)
                        {
                            // chnl has lower priority than all old channels, so we insert
                            //   it at the end of the list.
                            newList[oldList.Length] = new RegisteredChannel(chnl);
                        }
                        else
                        {
                            // finish copying rest of the old channels
                            while (current < oldList.Length)
                            {
                                newList[current + 1] = oldList[current];
                                current++;
                            }
                        }
                    }

                    if (perf_Contexts != null) {
                        perf_Contexts->cChannels++;
                    }
                    if (perf_globalContexts != null) {
                        perf_globalContexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
        } // RegisterChannelInternal
        unsafe internal static void RegisterChannelInternal(IChannel chnl)
        {
            // Validate arguments
            if (null == chnl)
            {
                throw new ArgumentNullException("chnl");
            }

            lock (s_channelLock)
            {
                String chnlName = chnl.ChannelName;

                RegisteredChannelList regChnlList = s_registeredChannels;

                // Check to make sure that the channel has not been registered
                if ((chnlName == null) ||
                    (chnlName.Length == 0) ||
                    (-1 == regChnlList.FindChannelIndex(chnl.ChannelName)))
                {
                    RegisteredChannel[] oldList = regChnlList.RegisteredChannels;
                    RegisteredChannel[] newList = null;
                    if (oldList == null)
                    {
                        newList = new RegisteredChannel[1];
                    }
                    else
                    {
                        newList = new RegisteredChannel[oldList.Length + 1];
                    }

                    if (newList.Length == 1)
                    {
                        // This is the first channel being registered.
                        //   (we know this since the x-appdmn channel can't be unregistered).
                        AppDomain.CurrentDomain.DomainUnload += new EventHandler(UnloadHandler);

                        newList[0] = new RegisteredChannel(chnl);
                    }
                    else
                    {
                        // Add the interface to the array in priority order
                        int priority = chnl.ChannelPriority;
                        int current  = 0;

                        // Find the place in the array to insert
                        while (current < oldList.Length)
                        {
                            RegisteredChannel oldChannel = oldList[current];
                            if (priority > oldChannel.Channel.ChannelPriority)
                            {
                                newList[current] = new RegisteredChannel(chnl);
                                break;
                            }
                            else
                            {
                                newList[current] = oldChannel;
                                current++;
                            }
                        }

                        if (current == oldList.Length)
                        {
                            // chnl has lower priority than all old channels, so we insert
                            //   it at the end of the list.
                            newList[oldList.Length] = new RegisteredChannel(chnl);
                        }
                        else
                        {
                            // finish copying rest of the old channels
                            while (current < oldList.Length)
                            {
                                newList[current + 1] = oldList[current];
                                current++;
                            }
                        }
                    }

                    if (perf_Contexts != null)
                    {
                        perf_Contexts->cChannels++;
                    }
                    if (perf_globalContexts != null)
                    {
                        perf_globalContexts->cChannels++;
                    }

                    s_registeredChannels = new RegisteredChannelList(newList);
                }
                else
                {
                    throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_ChannelNameAlreadyRegistered"), chnl.ChannelName));
                }

                RefreshChannelData();
            } // lock (s_channelLock)
        }     // RegisterChannelInternal
 public static unsafe void UnregisterChannel(IChannel chnl)
 {
     bool lockTaken = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(s_channelLock, ref lockTaken);
         if (chnl != null)
         {
             RegisteredChannelList list = s_registeredChannels;
             int num = list.FindChannelIndex(chnl);
             if (-1 == num)
             {
                 throw new RemotingException(Environment.GetResourceString("Remoting_ChannelNotRegistered", new object[] { chnl.ChannelName }));
             }
             RegisteredChannel[] registeredChannels = list.RegisteredChannels;
             RegisteredChannel[] channels = null;
             channels = new RegisteredChannel[registeredChannels.Length - 1];
             IChannelReceiver receiver = chnl as IChannelReceiver;
             if (receiver != null)
             {
                 receiver.StopListening(null);
             }
             int index = 0;
             int num3 = 0;
             while (num3 < registeredChannels.Length)
             {
                 if (num3 == num)
                 {
                     num3++;
                 }
                 else
                 {
                     channels[index] = registeredChannels[num3];
                     index++;
                     num3++;
                 }
             }
             if (perf_Contexts != null)
             {
                 perf_Contexts.cChannels--;
             }
             s_registeredChannels = new RegisteredChannelList(channels);
         }
         RefreshChannelData();
     }
     finally
     {
         if (lockTaken)
         {
             Monitor.Exit(s_channelLock);
         }
     }
 }