Пример #1
0
        /// <summary>
        /// Constructs an instance of the HostInformation class.
        /// Instances of the class HostInformation must be constructed only by objects implementing
        /// the IKnownHosts interface.
        /// </summary>
        /// <param name="uriOrUrl">Uri or Url of the remote host.</param>
        /// <param name="iTransportContext">Transport Context.</param>
        internal HostInformation(string uriOrUrl, ITransportContext iTransportContext)
        {
            this._iTransportContext = iTransportContext;

            if (uriOrUrl[0] == '_')
            {
                this._uri = uriOrUrl;
                UriStorage.RegisterConnection(uriOrUrl, this.ITransportContext);
            }
            else
            {
                this._url = uriOrUrl;
            }
        }
Пример #2
0
        /// <summary>
        /// Updates the value of the Uri member.
        /// </summary>
        /// <param name="uri">The uri of this host.</param>
        /// <param name="remoteHostUniqueIdentifier">The unique identifier of the HostInformation used by the remote host.</param>
        /// <param name="checkHostInfoVersion">The boolean value that determines whether the host version should be checked.</param>
        /// <returns>The exception explaining why the remote host has lost its state.</returns>
        public Exception UpdateUri(string uri, int remoteHostUniqueIdentifier, bool checkHostInfoVersion)
        {
            Exception       exception       = null;
            BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;

            lock (this._uriLock)
            {
                if (this._uri != uri)
                {
                    if (this._uri != null && this._uri != uri)
                    {
                        exception = GenuineExceptions.Get_Receive_ServerHasBeenRestared();

                        // LOG:
                        if (binaryLogWriter != null && binaryLogWriter[LogCategory.HostInformation] > 0)
                        {
                            binaryLogWriter.WriteEvent(LogCategory.HostInformation, "HostInformation.UpdateUri",
                                                       LogMessageType.HostInformationUriUpdated, exception, null, this,
                                                       null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                       null, null, -1, 0, 0, 0, this._uri, uri, null, null,
                                                       "The URI mismatch has been detected. The remote host has been restarted. Expected uri: \"{0}\". Provided uri: \"{1}\".", this._uri, uri);
                        }

//						if (! (bool) this.ITransportContext.IParameterProvider[GenuineParameter.IgnoreRemoteHostUriChanges])
                        throw exception;
                    }

                    this._uri = uri;
                    UriStorage.RegisterConnection(uri, this.ITransportContext);
                    this.ITransportContext.KnownHosts.UpdateHost(uri, this);

                    // LOG:
                    if (binaryLogWriter != null && binaryLogWriter[LogCategory.HostInformation] > 0)
                    {
                        binaryLogWriter.WriteEvent(LogCategory.HostInformation, "HostInformation.UpdateUri",
                                                   LogMessageType.HostInformationUriUpdated, null, null, this,
                                                   null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                   null, null, -1, 0, 0, 0, this._uri, uri, null, null,
                                                   "The URI of the HostInformation has been updated. Provided uri: \"{0}\".", this._uri);
                    }
                }

                if (checkHostInfoVersion && this.RemoteHostUniqueIdentifier != remoteHostUniqueIdentifier || (this._uri != null && this._uri != uri))
                {
                    if (this.RemoteHostUniqueIdentifier != -1)
                    {
                        exception = GenuineExceptions.Get_Receive_NewSessionDetected();

                        // release all security sessions
                        lock (_securitySessions)
                        {
                            foreach (DictionaryEntry entry in this._securitySessions)
                            {
                                SecuritySession securitySession = (SecuritySession)entry.Value;
                                securitySession.DispatchException(exception);
                            }

                            this._securitySessions = new Hashtable();
                        }

                        this.ITransportContext.IIncomingStreamHandler.DispatchException(this, exception);
                    }

                    this._remoteHostUniqueIdentifier = remoteHostUniqueIdentifier;
                    this.ITransportContext.IGenuineEventProvider.Fire(new GenuineEventArgs(GenuineEventType.GeneralNewSessionDetected, null, this, null));
                }
            }

            return(exception);
        }