Exemple #1
0
        internal void BeginWorker(ReferralQueue.State stateParam)
        {
            this.WaitForEvent(this.workerAvailableEvent);
            if (!this.ShouldCreateWorkerThread())
            {
                try
                {
                    stateParam.WorkerMethod(stateParam.WorkerState);
                    return;
                }
                finally
                {
                    this.pendingAuthorities.Remove(stateParam.AuthorityKey);
                    this.UpdateOnQueueChange();
                }
            }
            this.currentWorkerCount++;
            ReferralQueue.UpdateEvent(this.workerAvailableEvent, this.IsWorkerAvailable);
            bool flag = true;

            try
            {
                TrackingEventBudget.AcquireThread();
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    TrackingEventBudget.ReleaseThread();
                }
            }
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.WorkerMethodWrapper), stateParam);
        }
Exemple #2
0
 public LogCache(DateTime startTime, DateTime endTime, TrackingEventBudget eventBudget)
 {
     this.startTime     = startTime;
     this.endTime       = endTime;
     this.eventBudget   = eventBudget;
     this.cache         = new Dictionary <Fqdn, Dictionary <string, List <MessageTrackingLogEntry>[]> >();
     this.cacheBySender = new Dictionary <Fqdn, Dictionary <ProxyAddressCollection, List <MessageTrackingLogEntry>[]> >();
 }
Exemple #3
0
 public DirectoryContext(ClientContext clientContext, OrganizationId organizationId, ITopologyConfigurationSession globalConfigSession, IConfigurationSession tenantConfigSession, IRecipientSession tenantGalSession, TrackingEventBudget trackingBudget, DiagnosticsLevel diagnosticsLevel, TrackingErrorCollection errors, bool suppressIdAllocation)
 {
     this.clientContext       = clientContext;
     this.organizationId      = organizationId;
     this.globalConfigSession = globalConfigSession;
     this.tenantConfigSession = tenantConfigSession;
     this.tenantGalSession    = tenantGalSession;
     this.diagnosticsContext  = new DiagnosticsContext(suppressIdAllocation, diagnosticsLevel);
     this.TrackingBudget      = trackingBudget;
     this.Errors = errors;
     if (!this.TrySetExternalOrgId(organizationId))
     {
         TraceWrapper.SearchLibraryTracer.TraceError(0, "Failed to set ExternalOrgId. Assuming forest wide organization", new object[0]);
     }
 }
        private List <MessageTrackingLogEntry> ReadLogs(RpcReason rpcReason, string logFilePrefix, ProxyAddressCollection senderProxyAddresses, string messageId, DateTime startTime, DateTime endTime, TrackingEventBudget eventBudget)
        {
            Exception ex  = null;
            int       num = 0;
            List <MessageTrackingLogEntry> list = null;
            bool flag  = !string.IsNullOrEmpty(messageId);
            bool flag2 = senderProxyAddresses != null;

            if (flag && flag2)
            {
                throw new InvalidOperationException("Cannot get logs with both message id and sender address criteria");
            }
            if (rpcReason == RpcReason.None)
            {
                InfoWorkerMessageTrackingPerformanceCounters.GetMessageTrackingReportQueries.Increment();
            }
            else
            {
                InfoWorkerMessageTrackingPerformanceCounters.SearchMessageTrackingReportQueries.Increment();
            }
            try
            {
                this.context.DiagnosticsContext.LogRpcStart(this.server, rpcReason);
                using (LogSearchCursor cursor = TrackingSearch.GetCursor(this.server, this.version, logFilePrefix, messageId, senderProxyAddresses, startTime, endTime))
                {
                    list = this.ReadLogsFromCursor(cursor, eventBudget);
                }
            }
            catch (LogSearchException ex2)
            {
                ex  = ex2;
                num = ex2.ErrorCode;
            }
            catch (RpcException ex3)
            {
                ex  = ex3;
                num = ex3.ErrorCode;
            }
            finally
            {
                this.context.DiagnosticsContext.LogRpcEnd(ex, (list == null) ? 0 : list.Count);
            }
            if (ex != null)
            {
                TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Error reading from log-search RPC server for {0}: {1}, ErrorCode: {2}, Exception: {3}", new object[]
                {
                    flag ? "message id" : "sender",
                    flag ? messageId : senderProxyAddresses[0].ToString(),
                    num,
                    ex
                });
                TrackingTransientException.AddAndRaiseETX(this.context.Errors, ErrorCode.LogSearchConnection, this.server, ex.ToString());
            }
            return(list);
        }
 public List <MessageTrackingLogEntry> ReadLogs(RpcReason rpcReason, string logFilePrefix, ProxyAddressCollection senderProxyAddresses, DateTime startTime, DateTime endTime, TrackingEventBudget eventBudget)
 {
     return(this.ReadLogs(rpcReason, logFilePrefix, senderProxyAddresses, null, startTime, endTime, eventBudget));
 }
 public List <MessageTrackingLogEntry> ReadLogs(RpcReason rpcReason, string logFilePrefix, string messageId, DateTime startTime, DateTime endTime, TrackingEventBudget eventBudget)
 {
     return(this.ReadLogs(rpcReason, logFilePrefix, null, messageId, startTime, endTime, eventBudget));
 }
        private List <MessageTrackingLogEntry> ReadLogsFromCursor(LogSearchCursor cursor, TrackingEventBudget eventBudget)
        {
            List <MessageTrackingLogEntry> list = new List <MessageTrackingLogEntry>();

            while (cursor.MoveNext())
            {
                MessageTrackingLogEntry messageTrackingLogEntry;
                if (MessageTrackingLogEntry.TryCreateFromCursor(cursor, this.server, this.context.Errors, out messageTrackingLogEntry))
                {
                    if (list.Count % ServerCache.Instance.RowsBeforeTimeBudgetCheck == 0)
                    {
                        eventBudget.TestDelayOperation("GetRpcsBeforeDelay");
                        eventBudget.CheckTimeBudget();
                    }
                    list.Add(messageTrackingLogEntry);
                    if (messageTrackingLogEntry.RecipientAddresses != null)
                    {
                        eventBudget.IncrementBy((uint)messageTrackingLogEntry.RecipientAddresses.Length);
                    }
                    else
                    {
                        eventBudget.IncrementBy(1U);
                    }
                }
            }
            return(list);
        }
Exemple #8
0
        public InternalGetMessageTrackingReportResponse GetMessageTrackingReport(string messageTrackingReportId, ReportTemplate reportTemplate, SmtpAddress[] recipientFilter, SearchScope scope, bool returnQueueEvents, TrackingEventBudget eventBudget)
        {
            GetMessageTrackingReportRequestType getMessageTrackingReportRequestType = new GetMessageTrackingReportRequestType();

            getMessageTrackingReportRequestType.MessageTrackingReportId = messageTrackingReportId;
            if (reportTemplate == ReportTemplate.Summary)
            {
                getMessageTrackingReportRequestType.ReportTemplate = MessageTrackingReportTemplateType.Summary;
            }
            else
            {
                if (reportTemplate != ReportTemplate.RecipientPath)
                {
                    throw new ArgumentException("ReportTemplate must be RecipientPath or Summary", "reportTemplate");
                }
                getMessageTrackingReportRequestType.ReportTemplate = MessageTrackingReportTemplateType.RecipientPath;
            }
            if (recipientFilter != null && recipientFilter.Length > 0)
            {
                getMessageTrackingReportRequestType.RecipientFilter = new EmailAddressType();
                getMessageTrackingReportRequestType.RecipientFilter.EmailAddress = recipientFilter[0].ToString();
            }
            getMessageTrackingReportRequestType.ReturnQueueEvents          = returnQueueEvents;
            getMessageTrackingReportRequestType.ReturnQueueEventsSpecified = true;
            if (this.diagnosticsContext.Enabled)
            {
                getMessageTrackingReportRequestType.DiagnosticsLevel = Names <DiagnosticsLevel> .Map[(int)this.diagnosticsContext.DiagnosticsLevel];
            }
            TimeSpan clientTimeout;
            TimeSpan value;

            this.directoryContext.TrackingBudget.GetTimeBudgetRemainingForWSCall(this.trackingAuthority.TrackingAuthorityKind, out clientTimeout, out value);
            TrackingExtendedProperties trackingExtendedProperties = new TrackingExtendedProperties(false, false, new TimeSpan?(value), reportTemplate == ReportTemplate.Summary, false);

            getMessageTrackingReportRequestType.Properties = trackingExtendedProperties.ToTrackingPropertyArray();
            getMessageTrackingReportRequestType.Scope      = WebServiceBinding.GetWebServiceScope(scope);
            Exception ex = null;
            InternalGetMessageTrackingReportResponse internalGetMessageTrackingReportResponse = null;

            this.WriteStartEvent(false, messageTrackingReportId, null);
            internalGetMessageTrackingReportResponse = this.TryCallWebServiceMethod <InternalGetMessageTrackingReportResponse, GetMessageTrackingReportRequestType>(delegate(GetMessageTrackingReportRequestType req)
            {
                if (clientTimeout == TimeSpan.Zero)
                {
                    throw new TimeoutExpiredException("Not enough time remaining");
                }
                return(this.clientProxy.GetMessageTrackingReport(new GetMessageTrackingReportRequestTypeWrapper(req), clientTimeout));
            }, getMessageTrackingReportRequestType, out ex);
            if (internalGetMessageTrackingReportResponse != null)
            {
                if (internalGetMessageTrackingReportResponse.Response.ResponseClass != ResponseClassType.Success)
                {
                    TrackingError trackingErrorFromWebResponseError = this.GetTrackingErrorFromWebResponseError(internalGetMessageTrackingReportResponse.Response.ResponseCode, this.trackingAuthority.Domain, internalGetMessageTrackingReportResponse.Response.MessageText);
                    this.errors.Errors.Add(trackingErrorFromWebResponseError);
                }
                this.errors.ReadErrorsFromWSMessage(internalGetMessageTrackingReportResponse.Response.Diagnostics, internalGetMessageTrackingReportResponse.Response.Errors);
                this.diagnosticsContext.MergeEvents(internalGetMessageTrackingReportResponse.Response.Diagnostics);
            }
            int num = 0;

            if (internalGetMessageTrackingReportResponse != null && internalGetMessageTrackingReportResponse.Response.MessageTrackingReport != null && internalGetMessageTrackingReportResponse.RecipientTrackingEvents != null)
            {
                num = internalGetMessageTrackingReportResponse.RecipientTrackingEvents.Count;
                if (this.diagnosticsContext.VerboseDiagnostics)
                {
                    foreach (RecipientTrackingEvent recipientTrackingEvent in internalGetMessageTrackingReportResponse.RecipientTrackingEvents)
                    {
                        SmtpAddress recipientAddress = recipientTrackingEvent.RecipientAddress;
                        string      text             = recipientTrackingEvent.RecipientAddress.ToString();
                        string      value2           = text;
                        if (!string.IsNullOrEmpty(recipientTrackingEvent.UniquePathId))
                        {
                            value2 = string.Format("[{0}]{1}", recipientTrackingEvent.UniquePathId, text);
                        }
                        this.diagnosticsContext.AddProperty(DiagnosticProperty.Data1, value2);
                        this.diagnosticsContext.WriteEvent();
                    }
                }
            }
            eventBudget.IncrementBy((uint)num);
            this.WriteEndEvent(ex, num);
            if (ex != null)
            {
                throw ex;
            }
            return(internalGetMessageTrackingReportResponse);
        }
Exemple #9
0
        public FindMessageTrackingReportResponseMessageType FindMessageTrackingReport(string domain, SmtpAddress?senderAddress, SmtpAddress?recipientAddress, string serverHint, SmtpAddress?federatedDeliveryMailbox, SearchScope scope, string messageId, string subject, bool expandTree, bool searchAsRecip, bool searchForModerationResult, DateTime start, DateTime end, TrackingEventBudget eventBudget)
        {
            FindMessageTrackingReportRequestType findMessageTrackingReportRequestType = new FindMessageTrackingReportRequestType();

            findMessageTrackingReportRequestType.StartDateTime          = start;
            findMessageTrackingReportRequestType.StartDateTimeSpecified = true;
            findMessageTrackingReportRequestType.EndDateTime            = end;
            findMessageTrackingReportRequestType.EndDateTimeSpecified   = true;
            findMessageTrackingReportRequestType.MessageId  = messageId;
            findMessageTrackingReportRequestType.Subject    = subject;
            findMessageTrackingReportRequestType.Domain     = domain;
            findMessageTrackingReportRequestType.Scope      = WebServiceBinding.GetWebServiceScope(scope);
            findMessageTrackingReportRequestType.ServerHint = serverHint;
            TimeSpan clientTimeout;
            TimeSpan value;

            this.directoryContext.TrackingBudget.GetTimeBudgetRemainingForWSCall(this.trackingAuthority.TrackingAuthorityKind, out clientTimeout, out value);
            TrackingExtendedProperties trackingExtendedProperties = new TrackingExtendedProperties(expandTree, searchAsRecip, new TimeSpan?(value), false, searchForModerationResult);

            findMessageTrackingReportRequestType.Properties = trackingExtendedProperties.ToTrackingPropertyArray();
            if (this.diagnosticsContext.Enabled)
            {
                findMessageTrackingReportRequestType.DiagnosticsLevel = Names <DiagnosticsLevel> .Map[(int)this.diagnosticsContext.DiagnosticsLevel];
            }
            if (federatedDeliveryMailbox != null)
            {
                findMessageTrackingReportRequestType.FederatedDeliveryMailbox = new EmailAddressType();
                findMessageTrackingReportRequestType.FederatedDeliveryMailbox.EmailAddress = federatedDeliveryMailbox.Value.ToString();
            }
            if (senderAddress != null)
            {
                findMessageTrackingReportRequestType.Sender = new EmailAddressType();
                findMessageTrackingReportRequestType.Sender.EmailAddress = senderAddress.Value.ToString();
            }
            if (recipientAddress != null)
            {
                findMessageTrackingReportRequestType.Recipient = new EmailAddressType();
                findMessageTrackingReportRequestType.Recipient.EmailAddress = recipientAddress.Value.ToString();
            }
            Exception ex = null;

            this.WriteStartEvent(true, messageId, serverHint);
            FindMessageTrackingReportResponseMessageType findMessageTrackingReportResponseMessageType = this.TryCallWebServiceMethod <FindMessageTrackingReportResponseMessageType, FindMessageTrackingReportRequestType>(delegate(FindMessageTrackingReportRequestType req)
            {
                if (clientTimeout == TimeSpan.Zero)
                {
                    throw new TimeoutExpiredException("Not enough time remaining");
                }
                return(this.clientProxy.FindMessageTrackingReport(new FindMessageTrackingReportRequestTypeWrapper(req), clientTimeout));
            }, findMessageTrackingReportRequestType, out ex);
            int count = 0;

            if (findMessageTrackingReportResponseMessageType != null)
            {
                if (findMessageTrackingReportResponseMessageType.ResponseClass != ResponseClassType.Success)
                {
                    TrackingError trackingErrorFromWebResponseError = this.GetTrackingErrorFromWebResponseError(findMessageTrackingReportResponseMessageType.ResponseCode, this.trackingAuthority.Domain, findMessageTrackingReportResponseMessageType.MessageText);
                    this.errors.Errors.Add(trackingErrorFromWebResponseError);
                }
                this.errors.ReadErrorsFromWSMessage(findMessageTrackingReportResponseMessageType.Diagnostics, findMessageTrackingReportResponseMessageType.Errors);
                this.diagnosticsContext.MergeEvents(findMessageTrackingReportResponseMessageType.Diagnostics);
                if (findMessageTrackingReportResponseMessageType.MessageTrackingSearchResults != null)
                {
                    count = findMessageTrackingReportResponseMessageType.MessageTrackingSearchResults.Length;
                    eventBudget.IncrementBy(10U);
                    if (this.diagnosticsContext.VerboseDiagnostics)
                    {
                        foreach (FindMessageTrackingSearchResultType findMessageTrackingSearchResultType in findMessageTrackingReportResponseMessageType.MessageTrackingSearchResults)
                        {
                            this.diagnosticsContext.AddProperty(DiagnosticProperty.Data1, findMessageTrackingSearchResultType.MessageTrackingReportId);
                            this.diagnosticsContext.WriteEvent();
                        }
                    }
                }
            }
            this.WriteEndEvent(ex, count);
            if (ex != null)
            {
                throw ex;
            }
            return(findMessageTrackingReportResponseMessageType);
        }
Exemple #10
0
        private void WorkerMethodWrapper(object stateObject)
        {
            ReferralQueue.State state   = (ReferralQueue.State)stateObject;
            bool          flag          = false;
            bool          flag2         = false;
            TrackingError trackingError = null;

            try
            {
                this.directoryContext.Acquire();
                flag = true;
                if (this.directoryContext.DiagnosticsContext.DiagnosticsLevel == DiagnosticsLevel.Etw)
                {
                    CommonDiagnosticsLogTracer traceWriter = new CommonDiagnosticsLogTracer();
                    TraceWrapper.SearchLibraryTracer.Register(traceWriter);
                    flag2 = true;
                }
                state.WorkerMethod(state.WorkerState);
            }
            catch (TrackingTransientException ex)
            {
                if (!ex.IsAlreadyLogged)
                {
                    trackingError = ex.TrackingError;
                }
            }
            catch (TrackingFatalException ex2)
            {
                if (ex2.IsAlreadyLogged)
                {
                    trackingError = ex2.TrackingError;
                }
            }
            catch (TransientException ex3)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorTransient, string.Empty, ex3.Message, ex3.ToString());
            }
            catch (DataSourceOperationException ex4)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Error from Active Directory provider", ex4.ToString());
            }
            catch (DataValidationException ex5)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Validation Error from Active Directory provider", ex5.ToString());
            }
            finally
            {
                if (flag)
                {
                    if (trackingError != null)
                    {
                        TraceWrapper.SearchLibraryTracer.TraceError <TrackingError>(this.GetHashCode(), "Error in woker thread while processing referral, {0}", trackingError);
                        this.directoryContext.Errors.Errors.Add(trackingError);
                    }
                    this.pendingAuthorities.Remove(state.AuthorityKey);
                    this.currentWorkerCount--;
                    ReferralQueue.UpdateEvent(this.workerAvailableEvent, this.IsWorkerAvailable);
                    this.UpdateOnQueueChange();
                    if (flag2)
                    {
                        TraceWrapper.SearchLibraryTracer.Unregister();
                    }
                    this.directoryContext.Yield();
                    TrackingEventBudget.ReleaseThread();
                }
            }
        }