// Token: 0x06002416 RID: 9238 RVA: 0x000A8B98 File Offset: 0x000A6D98
        private void StartService()
        {
            Exception ex = null;

            this.m_service = ThirdPartyService.StartListening(out ex);
            if (this.m_service == null)
            {
                this.m_serviceStartFailure = ex;
                return;
            }
            ex = this.DoTPRCommunication(delegate(object param0, EventArgs param1)
            {
                TimeSpan timeSpan = new TimeSpan(0, 0, 2);
                using (Notify notify = Notify.Open(timeSpan, timeSpan, timeSpan))
                {
                    notify.GetTimeouts(out this.m_retryDelay, out this.m_openTimeout, out this.m_sendTimeout, out this.m_receiveTimeout);
                    this.m_isAmeListening = true;
                    AmConfig config       = AmSystemManager.Instance.Config;
                    if (config.IsPAM)
                    {
                        this.BecomePame();
                    }
                    else
                    {
                        this.RevokePame();
                    }
                }
            });
            if (ex != null)
            {
                ExTraceGlobals.ThirdPartyManagerTracer.TraceError <Exception>(0L, "StartService fails to contact the AME: {0}", ex);
            }
        }
 public void AmeIsStopping()
 {
     this.DoAction(delegate(object param0, EventArgs param1)
     {
         ThirdPartyService.CheckSecurity("AmeIsStopping");
         ThirdPartyManager.Instance.AmeIsStopping();
     });
 }
 public void AmeIsStarting(TimeSpan retryDelay, TimeSpan openTimeout, TimeSpan sendTimeout, TimeSpan receiveTimeout)
 {
     this.DoAction(delegate(object param0, EventArgs param1)
     {
         ThirdPartyService.CheckSecurity("AmeIsStarting");
         ThirdPartyManager.Instance.AmeIsStarting(retryDelay, openTimeout, sendTimeout, receiveTimeout);
     });
 }
        public byte[] ChangeActiveServer(Guid databaseId, string newActiveServerName)
        {
            ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug <Guid, string>(0L, "ChangeActiveServer:db {0} moving to {1}", databaseId, newActiveServerName);
            Exception ex = this.DoAction(delegate(object param0, EventArgs param1)
            {
                ThirdPartyService.CheckSecurity("ChangeActiveServer");
                ThirdPartyManager.Instance.ChangeActiveServer(databaseId, newActiveServerName);
            });

            if (ex != null)
            {
                ReplayCrimsonEvents.TPRChangeActiveServerFailed.Log <Guid, string, string, string>(databaseId, newActiveServerName, ex.Message, ex.StackTrace);
                if (!(ex is ThirdPartyReplicationException))
                {
                    ex = new ChangeActiveServerException(databaseId, newActiveServerName, ex.Message);
                }
                return(this.SerializeException(ex));
            }
            return(null);
        }
        public byte[] ImmediateDismountMailboxDatabase(Guid databaseId)
        {
            ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug <Guid>(0L, "ImmediateDismountMailboxDatabase:db {0}", databaseId);
            Exception ex = this.DoAction(delegate(object param0, EventArgs param1)
            {
                ThirdPartyService.CheckSecurity("ImmediateDismountMailboxDatabase");
                ThirdPartyManager.Instance.ImmediateDismountMailboxDatabase(databaseId);
            });

            if (ex != null)
            {
                ReplayCrimsonEvents.TPRImmediateDismountFailed.Log <Guid, string, string>(databaseId, ex.Message, ex.StackTrace);
                if (!(ex is ThirdPartyReplicationException))
                {
                    ex = new ImmediateDismountMailboxDatabaseException(databaseId, ex.Message);
                }
                return(this.SerializeException(ex));
            }
            return(null);
        }
        public static ThirdPartyService StartListening(out Exception exception)
        {
            ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug(0L, "Starting listener");
            exception = null;
            ThirdPartyService thirdPartyService = null;

            try
            {
                thirdPartyService = new ThirdPartyService();
                EndpointAddress endpointAddress = new EndpointAddress("net.pipe://localhost/Microsoft.Exchange.ThirdPartyReplication.RequestService");
                thirdPartyService.m_host = new ServiceHost(thirdPartyService, new Uri[]
                {
                    endpointAddress.Uri
                });
                thirdPartyService.m_host.AddServiceEndpoint(typeof(IInternalRequest), new NetNamedPipeBinding(), string.Empty);
                thirdPartyService.m_host.Open();
                ReplayEventLogConstants.Tuple_TPRExchangeListenerStarted.LogEvent(null, new object[0]);
                ReplayCrimsonEvents.TPRExchangeListenerStarted.Log();
                ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug(0L, "Started successfully");
                return(thirdPartyService);
            }
            catch (CommunicationException ex)
            {
                exception = ex;
            }
            catch (ConfigurationException ex2)
            {
                exception = ex2;
            }
            catch (InvalidOperationException ex3)
            {
                exception = ex3;
            }
            ReplayCrimsonEvents.TPRExchangeListenerFailedToStart.Log <string>(exception.ToString());
            ExTraceGlobals.ThirdPartyServiceTracer.TraceError <string, Exception>(0L, "Failed to start listener: {0} {1}", exception.Message, exception);
            if (thirdPartyService != null && thirdPartyService.m_host != null)
            {
                thirdPartyService.m_host.Abort();
            }
            return(null);
        }
        private static void CheckSecurity(string methodName)
        {
            ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug <string, string>(0L, "Received '{0}' from '{1}'", methodName, ServiceSecurityContext.Current.PrimaryIdentity.Name);
            WindowsIdentity windowsIdentity = ServiceSecurityContext.Current.PrimaryIdentity as WindowsIdentity;

            if (windowsIdentity == null)
            {
                ExTraceGlobals.ThirdPartyServiceTracer.TraceError(0L, "Not a windows Identity");
                throw new NotAuthorizedException();
            }
            if (!ThirdPartyService.AuthorizeRequest(windowsIdentity))
            {
                ExTraceGlobals.ThirdPartyServiceTracer.TraceError(0L, "Caller in not Local admin");
                if (!ThirdPartyService.s_authFailedLogged)
                {
                    ThirdPartyService.s_authFailedLogged = true;
                    ReplayCrimsonEvents.TPRAuthorizationFailed.Log <string>(ServiceSecurityContext.Current.PrimaryIdentity.Name);
                }
                throw new NotAuthorizedException();
            }
        }
        public string GetPrimaryActiveManager(out byte[] exBytes)
        {
            ExTraceGlobals.ThirdPartyServiceTracer.TraceDebug(0L, "GetPrimaryActiveManager called");
            exBytes = null;
            string    pam = null;
            Exception ex  = this.DoAction(delegate(object param0, EventArgs param1)
            {
                ThirdPartyService.CheckSecurity("GetPrimaryActiveManager");
                pam = ThirdPartyManager.GetPrimaryActiveManager();
            });

            if (ex != null)
            {
                ExTraceGlobals.ThirdPartyServiceTracer.TraceError <Exception>((long)this.GetHashCode(), "GetPrimaryActiveManager fails: {0}", ex);
                if (!(ex is ThirdPartyReplicationException))
                {
                    ex = new GetPrimaryActiveManagerException(ex.Message);
                }
                exBytes = this.SerializeException(ex);
            }
            return(pam);
        }