private static Exception DumpsterResubmitRpc(string hubServer, ReplayConfiguration config, SafetyNetRequestKey snKey, SafetyNetInfo snInfo, IMonitoringADConfig adConfig, bool inPrimaryPhase)
        {
            bool      flag = false;
            Exception ex   = null;

            SafetyNetRedelivery.Tracer.TraceDebug <string, string, string>((long)config.GetHashCode(), "DumpsterResubmitRpc() called for {0}({1}) to HUB server {2}.", config.Name, config.Identity, hubServer);
            if (SafetyNetRedelivery.IsSafetyNetRedeliveryRpcSupportedOnHubServer(hubServer, adConfig, out ex))
            {
                AddResubmitRequestStatus addResubmitRequestStatus;
                ex = SafetyNetRedelivery.DumpsterResubmitRpcInternal(true, hubServer, config, snKey, snInfo, inPrimaryPhase, out addResubmitRequestStatus);
                if (addResubmitRequestStatus == AddResubmitRequestStatus.Disabled)
                {
                    flag = true;
                    SafetyNetRedelivery.Tracer.TraceDebug <string, string, string>((long)config.GetHashCode(), "DumpsterResubmitRpc() requested from SafetyNet for {0}({1}) to HUB server {2}, but it is Disabled. Falling back to classic Dumpster...", config.Name, config.Identity, hubServer);
                }
                else if (addResubmitRequestStatus == AddResubmitRequestStatus.DuplicateRequest)
                {
                    SafetyNetRedelivery.Tracer.TraceDebug <string, string, string>((long)config.GetHashCode(), "DumpsterResubmitRpc() requested from SafetyNet for {0}({1}) to HUB server {2}, but it is DuplicateRequest. Treating this duplicate RPC as successful.", config.Name, config.Identity, hubServer);
                }
            }
            else if (ex != null)
            {
                SafetyNetRedelivery.LogResubmitToServerException(true, hubServer, config, snKey, snInfo, inPrimaryPhase, ex, string.Empty);
            }
            else
            {
                flag = true;
            }
            if (flag)
            {
                AddResubmitRequestStatus addResubmitRequestStatus;
                ex = SafetyNetRedelivery.DumpsterResubmitRpcInternal(false, hubServer, config, snKey, snInfo, inPrimaryPhase, out addResubmitRequestStatus);
            }
            return(ex);
        }
        private static Exception DumpsterResubmitRpcInternal(bool isSafetyNetRpc, string hubServer, ReplayConfiguration config, SafetyNetRequestKey snKey, SafetyNetInfo snInfo, bool inPrimaryPhase, out AddResubmitRequestStatus snStatus)
        {
            Exception        ex       = null;
            SubmissionStatus dpStatus = SubmissionStatus.Error;
            string           unresponsivePrimaryServersStr = string.Empty;

            snStatus = AddResubmitRequestStatus.Error;
            AddResubmitRequestStatus tempSnStatus = AddResubmitRequestStatus.Error;

            SafetyNetRedelivery.Tracer.TraceDebug((long)config.GetHashCode(), "DumpsterResubmitRpcInternal() called for {0}({1}) to HUB server {2}. isSafetyNetRpc={3}. inPrimaryPhase={4}", new object[]
            {
                config.Name,
                config.Identity,
                hubServer,
                isSafetyNetRpc,
                inPrimaryPhase
            });
            try
            {
                InvokeWithTimeout.Invoke(delegate()
                {
                    using (MailSubmissionServiceRpcClient mailSubmissionServiceRpcClient = new MailSubmissionServiceRpcClient(hubServer))
                    {
                        mailSubmissionServiceRpcClient.SetTimeOut(RegistryParameters.DumpsterRpcTimeoutInMSecs);
                        if (isSafetyNetRpc)
                        {
                            string[] array = null;
                            if (!inPrimaryPhase)
                            {
                                List <string> list = snInfo.PrimaryHubServers;
                                if (list == null || list.Count == 0)
                                {
                                    list = snInfo.HubServers;
                                    SafetyNetRedelivery.Tracer.TraceDebug <string, string, string>((long)config.GetHashCode(), "DumpsterResubmitRpcInternal() for {0}({1}) to HUB server {2} : PrimaryHubServers list was empty, so assuming all HubServers failed to respond to primary and will issue shadow requests for all of them.", config.Name, config.Identity, hubServer);
                                }
                                if (list != null && list.Count > 0)
                                {
                                    array = list.ToArray();
                                    unresponsivePrimaryServersStr = string.Join(",", array);
                                    if (SafetyNetRedelivery.Tracer.IsTraceEnabled(TraceType.DebugTrace))
                                    {
                                        SafetyNetRedelivery.Tracer.TraceDebug((long)config.GetHashCode(), "DumpsterResubmitRpcInternal() for {0}({1}) to HUB server {2} : unresponsivePrimaryServers = {3}", new object[]
                                        {
                                            config.Name,
                                            config.Identity,
                                            hubServer,
                                            unresponsivePrimaryServersStr
                                        });
                                    }
                                }
                            }
                            tempSnStatus = mailSubmissionServiceRpcClient.AddMdbResubmitRequest(Guid.Empty, config.IdentityGuid, snInfo.StartTimeUtc.Ticks, snInfo.EndTimeUtc.Ticks, array, null);
                        }
                        else
                        {
                            dpStatus = mailSubmissionServiceRpcClient.SubmitDumpsterMessages(config.DatabaseDn, snInfo.StartTimeUtc.Ticks, snInfo.EndTimeUtc.Ticks);
                        }
                    }
                }, TimeSpan.FromMilliseconds((double)RegistryParameters.DumpsterRpcTimeoutInMSecs));
                if (isSafetyNetRpc)
                {
                    snStatus = tempSnStatus;
                    if (snStatus == AddResubmitRequestStatus.DuplicateRequest)
                    {
                        ReplayCrimsonEvents.DumpsterRedeliverySpecificRequestDuplicate.Log <string, Guid, DateTime, DateTime, DateTime, string>(config.DatabaseName, config.IdentityGuid, snKey.RequestCreationTimeUtc, snInfo.StartTimeUtc, snInfo.EndTimeUtc, hubServer);
                    }
                    else if (snStatus != AddResubmitRequestStatus.Success && snStatus != AddResubmitRequestStatus.Disabled)
                    {
                        ex = new DumpsterSafetyNetRpcFailedException(hubServer, tempSnStatus.ToString());
                        return(ex);
                    }
                }
                TimeSpan timeSpan = DateTime.UtcNow.Subtract(snKey.RequestCreationTimeUtc);
                SafetyNetRedelivery.Tracer.TraceDebug((long)config.GetHashCode(), "DumpsterResubmitRpcInternal() succeeded for {0}({1}) to HUB server {2} after {3}. isSafetyNetRpc={4}. snStatus returned = {5}.", new object[]
                {
                    config.Name,
                    config.Identity,
                    hubServer,
                    timeSpan,
                    isSafetyNetRpc,
                    snStatus
                });
                ReplayCrimsonEvents.DumpsterRedeliverySpecificRequestRPCSucceeded.Log <string, Guid, bool, DateTime, DateTime, DateTime, string, SafetyNetRequestKey, string, TimeSpan, bool, bool, string>(config.DatabaseName, config.IdentityGuid, false, snKey.RequestCreationTimeUtc, snInfo.StartTimeUtc, snInfo.EndTimeUtc, hubServer, snKey, snInfo.GetSerializedForm(), timeSpan, isSafetyNetRpc, inPrimaryPhase, unresponsivePrimaryServersStr);
                ReplayEventLogConstants.Tuple_DatabaseSubmitDumpsterMessages.LogEvent(config.IdentityGuid + hubServer, new object[]
                {
                    hubServer,
                    snInfo.StartTimeUtc,
                    snInfo.EndTimeUtc,
                    config.Name
                });
            }
            catch (RpcException ex2)
            {
                ex = ex2;
            }
            catch (DumpsterCouldNotFindHubServerException ex3)
            {
                ex = ex3;
            }
            catch (TimeoutException ex4)
            {
                ex = ex4;
            }
            finally
            {
                if (ex != null)
                {
                    SafetyNetRedelivery.LogResubmitToServerException(isSafetyNetRpc, hubServer, config, snKey, snInfo, inPrimaryPhase, ex, unresponsivePrimaryServersStr);
                }
            }
            return(ex);
        }