Exemplo n.º 1
0
        /// <summary>
        /// Releases resources belonging to the remote host.
        /// </summary>
        /// <param name="hostInformation">The remote host.</param>
        /// <param name="reason">The exception.</param>
        /// <returns>True if host resources have been released by this call. False if host resources have been already released.</returns>
        public bool ReleaseHostResources(HostInformation hostInformation, Exception reason)
        {
            if (hostInformation.Uri != null)
            {
                this.RemoveHostInformation(hostInformation.Uri, hostInformation);
            }
            if (hostInformation.Url != null)
            {
                this.RemoveHostInformation(hostInformation.Url, hostInformation);
            }

            // release all resources associated with this host
            bool cleanup = hostInformation.Dispose(reason);

            if (cleanup)
            {
                this.ITransportContext.ConnectionManager.ReleaseConnections(hostInformation, GenuineConnectionType.All, reason);
                this.ITransportContext.IIncomingStreamHandler.DispatchException(hostInformation, reason);

                // and fire a warning
                this.ITransportContext.IGenuineEventProvider.Fire(new GenuineEventArgs(GenuineEventType.HostResourcesReleased, reason, hostInformation, null));
            }

            return(cleanup);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds an element to the collection associated with the specified key.
        /// Ensures that there is the only instance of the element in the collection.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="hostInformation">The element being stored.</param>
        private void SetHostInformation(string key, HostInformation hostInformation)
        {
            lock (this.SyncRoot)
            {
                ArrayList arrayList = this._hashtable[key] as ArrayList;

                // if there is no collection corresponding to the key
                if (arrayList == null)
                {
                    arrayList            = new ArrayList();
                    this._hashtable[key] = arrayList;
                    arrayList.Add(hostInformation);
                    return;
                }

                // check whether this element is already in the collection
                for (int i = 0; i < arrayList.Count; i++)
                {
                    if (object.ReferenceEquals(arrayList[i], hostInformation))
                    {
                        return;
                    }

                    // TODO: What to do with this fix?! It does work, but only in really unusual circumstances.
                    // remove all HostInformations with empty URI, if the current hostInformation contains the URI
                    HostInformation currentHostInformation = (HostInformation)arrayList[i];
                    if (hostInformation.Url != null && currentHostInformation.Url == null &&
                        hostInformation.Uri == currentHostInformation.Uri && currentHostInformation.RemoteHostUniqueIdentifier == -1)
                    {
                        arrayList.RemoveAt(i);
                        arrayList.Add(hostInformation);
                        currentHostInformation.Dispose(GenuineExceptions.Get_Receive_ConflictOfConnections());
                        return;
                    }
                }

                arrayList.Add(hostInformation);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Releases resources belonging to the remote host.
        /// </summary>
        /// <param name="hostInformation">The remote host.</param>
        /// <param name="reason">The exception.</param>
        /// <returns>True if host resources have been released by this call. False if host resources have been already released.</returns>
        public bool ReleaseHostResources(HostInformation hostInformation, Exception reason)
        {
            if (hostInformation.Uri != null)
                this.RemoveHostInformation(hostInformation.Uri, hostInformation);
            if (hostInformation.Url != null)
                this.RemoveHostInformation(hostInformation.Url, hostInformation);

            // release all resources associated with this host
            bool cleanup = hostInformation.Dispose(reason);
            if (cleanup)
            {
                this.ITransportContext.ConnectionManager.ReleaseConnections(hostInformation, GenuineConnectionType.All, reason);
                this.ITransportContext.IIncomingStreamHandler.DispatchException(hostInformation, reason);

                // and fire a warning
                this.ITransportContext.IGenuineEventProvider.Fire(new GenuineEventArgs(GenuineEventType.HostResourcesReleased, reason, hostInformation, null));
            }

            return cleanup;
        }