internal static void StartContinuousLogTransmission(NetworkChannel channel, ContinuousLogCopyRequest oldReq)
        {
            LogCopyServerContext logCopyServerContext = new LogCopyServerContext(channel, channel.MonitoredDatabase);

            logCopyServerContext.m_clientIsDownLevel = true;
            LogCopyServerContext.Tracer.TraceDebug <string, bool>((long)logCopyServerContext.GetHashCode(), "Passive({0}) is downlevel {1}}", channel.PartnerNodeName, logCopyServerContext.m_clientIsDownLevel);
            ContinuousLogCopyRequest2 initialRequest = LogCopyServerContext.UpgradeRequest(channel, oldReq);

            logCopyServerContext.InitContinuousLogTransmission(initialRequest);
        }
 private void HandleIncomingMessage()
 {
     try
     {
         if (!this.m_markedForTermination)
         {
             lock (this.m_networkReadLock)
             {
                 NetworkChannelMessage message     = this.Channel.GetMessage();
                 PingMessage           pingMessage = message as PingMessage;
                 if (pingMessage != null)
                 {
                     LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "HandleIncomingMessage: Ping received");
                     Interlocked.Exchange(ref this.m_pingPending, 1);
                     this.m_sendDataEnabled = true;
                 }
                 else
                 {
                     ContinuousLogCopyRequest2 continuousLogCopyRequest = message as ContinuousLogCopyRequest2;
                     if (continuousLogCopyRequest == null)
                     {
                         if (message is ContinuousLogCopyRequest)
                         {
                             continuousLogCopyRequest = LogCopyServerContext.UpgradeRequest(this.Channel, message as ContinuousLogCopyRequest);
                         }
                         else
                         {
                             LogCopyServerContext.Tracer.TraceError <NetworkChannelMessage>((long)this.GetHashCode(), "HandleIncomingMessage: UnexpectedMsg:{0}", message);
                             this.Channel.ThrowUnexpectedMessage(message);
                         }
                     }
                     LogCopyServerContext.Tracer.TraceDebug <long, long, ContinuousLogCopyRequest2.Flags>((long)this.GetHashCode(), "HandleIncomingMessage: First=0x{0:X} Max=0x{1:X} Flags=0x{2:X}", continuousLogCopyRequest.FirstGeneration, continuousLogCopyRequest.LastGeneration, continuousLogCopyRequest.FlagsUsed);
                     this.m_sendDataEnabled    = true;
                     this.m_nextLogCopyRequest = continuousLogCopyRequest;
                 }
                 this.StartNetworkRead();
                 this.SignalWorkPending();
             }
         }
     }
     catch (NetworkTransportException arg)
     {
         LogCopyServerContext.Tracer.TraceError <NetworkTransportException>((long)this.GetHashCode(), "HandleIncomingMessage: Channel exception: {0}", arg);
         this.MarkForTermination();
     }
 }
 private void InitContinuousLogTransmission(ContinuousLogCopyRequest2 initialRequest)
 {
     this.m_clientNodeName = initialRequest.ClientNodeName;
     LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "StartContinuousLogTransmission({0}): First=0x{1:X} Max=0x{2:X} Flags=0x{3:X}", new object[]
     {
         this.PassiveCopyName,
         initialRequest.FirstGeneration,
         initialRequest.LastGeneration,
         initialRequest.FlagsUsed
     });
     this.m_currentLogCopyRequest = initialRequest;
     this.m_nextLogCopyRequest    = initialRequest;
     this.m_currentLogGeneration  = initialRequest.FirstGeneration;
     this.m_sendDataEnabled       = true;
     this.Channel.NetworkChannelManagesAsyncReads = false;
     try
     {
         this.m_workIsPendingEvent = new ManualResetEvent(false);
         this.LinkWithMonitoredDatabase();
     }
     catch (NetworkCancelledException arg)
     {
         LogCopyServerContext.Tracer.TraceError <NetworkCancelledException>((long)this.GetHashCode(), "InitContinuousLogTransmission cancelled {0}", arg);
         this.Terminate();
         return;
     }
     this.SourceDatabasePerfCounters = SourceDatabasePerformanceCounters.GetInstance(this.PassiveCopyName);
     try
     {
         this.StartNetworkRead();
     }
     catch (NetworkTransportException arg2)
     {
         LogCopyServerContext.Tracer.TraceError <NetworkTransportException>((long)this.GetHashCode(), "InitContinuousLogTransmission caught {0}", arg2);
         this.MarkForTermination();
     }
     this.SignalWorkPending();
 }
        internal static void StartContinuousLogTransmission(NetworkChannel channel, ContinuousLogCopyRequest2 initialRequest)
        {
            LogCopyServerContext logCopyServerContext = new LogCopyServerContext(channel, channel.MonitoredDatabase);

            logCopyServerContext.InitContinuousLogTransmission(initialRequest);
        }
        private bool EnterBlockMode()
        {
            TimeSpan  timeout = TimeSpan.FromSeconds(5.0);
            bool      flag;
            Exception ex = AmStoreHelper.IsDatabaseMounted(this.Database.DatabaseGuid, this.LocalNodeName, timeout, out flag);

            if (ex != null)
            {
                LogCopyServerContext.Tracer.TraceError <Exception>((long)this.GetHashCode(), "Store may not be running. Mount check failed: {0}", ex);
                return(false);
            }
            if (!flag)
            {
                LogCopyServerContext.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Db {0} not mounted. BlockMode is not possible", this.Database.DatabaseName);
                return(false);
            }
            EnterBlockModeMsg enterBlockModeMsg = new EnterBlockModeMsg(this.Channel, EnterBlockModeMsg.Flags.PrepareToEnter, this.Database.DatabaseGuid, this.m_currentLogGeneration);
            bool flag2 = false;
            bool result;

            lock (this.m_networkReadLock)
            {
                if (this.m_markedForTermination)
                {
                    result = false;
                }
                else
                {
                    int readTimeoutInMs  = this.Channel.TcpChannel.ReadTimeoutInMs;
                    int writeTimeoutInMs = this.Channel.TcpChannel.WriteTimeoutInMs;
                    try
                    {
                        this.Channel.TcpChannel.ReadTimeoutInMs  = RegistryParameters.LogShipACLLTimeoutInMsec;
                        this.Channel.TcpChannel.WriteTimeoutInMs = RegistryParameters.LogShipACLLTimeoutInMsec;
                        LogCopyServerContext.Tracer.TraceDebug <string>((long)this.GetHashCode(), "EnterBlockMode requesting PrepareToEnter for {0}", this.PassiveCopyName);
                        enterBlockModeMsg.Send();
                        EnterBlockModeMsg enterBlockModeMsg2;
                        string            text;
                        for (;;)
                        {
                            NetworkChannelMessage message     = this.Channel.GetMessage();
                            PingMessage           pingMessage = message as PingMessage;
                            if (pingMessage != null)
                            {
                                LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "PingMessage ignored");
                            }
                            else
                            {
                                ContinuousLogCopyRequest2 continuousLogCopyRequest = message as ContinuousLogCopyRequest2;
                                if (continuousLogCopyRequest != null)
                                {
                                    this.m_nextLogCopyRequest = continuousLogCopyRequest;
                                    LogCopyServerContext.Tracer.TraceDebug <long, long, ContinuousLogCopyRequest2.Flags>((long)this.GetHashCode(), "ContinuousLogCopyRequest2: First=0x{0:X} Max=0x{1:X} Flags=0x{2:X}", continuousLogCopyRequest.FirstGeneration, continuousLogCopyRequest.LastGeneration, continuousLogCopyRequest.FlagsUsed);
                                }
                                else
                                {
                                    enterBlockModeMsg2 = (message as EnterBlockModeMsg);
                                    text = null;
                                    if (enterBlockModeMsg2 == null)
                                    {
                                        text = string.Format("Passive({0}) sent unexpected msg: {1}", this.PassiveCopyName, message.GetType());
                                    }
                                    else if (enterBlockModeMsg2.AckCounter != enterBlockModeMsg.AckCounter)
                                    {
                                        text = string.Format("Passive({0}) is out of sync. BlockModeEntry Aborted", this.PassiveCopyName);
                                    }
                                    if (text != null)
                                    {
                                        break;
                                    }
                                    if (enterBlockModeMsg2.FlagsUsed != EnterBlockModeMsg.Flags.PassiveIsReady)
                                    {
                                        goto Block_13;
                                    }
                                    if (!this.RequestBlockModeInStore())
                                    {
                                        goto Block_15;
                                    }
                                }
                            }
                        }
                        LogCopyServerContext.Tracer.TraceError((long)this.GetHashCode(), text);
                        throw new NetworkUnexpectedMessageException(this.m_clientNodeName, text);
Block_13:
                        if (enterBlockModeMsg2.FlagsUsed == EnterBlockModeMsg.Flags.PassiveReject)
                        {
                            LogCopyServerContext.Tracer.TraceError <string>((long)this.GetHashCode(), "BlockMode rejected by passive {0}", this.PassiveCopyName);
                            flag2 = true;
                            return(false);
                        }
                        text = string.Format("Passive({0}) passed unexpected flags 0x{1X}", this.PassiveCopyName, enterBlockModeMsg2.FlagsUsed);
                        throw new NetworkUnexpectedMessageException(this.m_clientNodeName, text);
Block_15:
                        flag2  = true;
                        result = false;
                    }
                    finally
                    {
                        if (flag2)
                        {
                            this.Channel.TcpChannel.ReadTimeoutInMs  = readTimeoutInMs;
                            this.Channel.TcpChannel.WriteTimeoutInMs = writeTimeoutInMs;
                            this.StartNetworkRead();
                        }
                    }
                }
            }
            return(result);
        }