internal TrackingError Add(ErrorCode errorCode, string target, string data, string exception)
        {
            TrackingError trackingError = new TrackingError(errorCode, target, data, exception);

            this.errors.Add(trackingError);
            return(trackingError);
        }
        internal static TrackingError CreateFromWSMessage(ArrayOfTrackingPropertiesType propertyBag)
        {
            string value  = string.Empty;
            string value2 = string.Empty;
            string value3 = string.Empty;

            foreach (TrackingPropertyType trackingPropertyType in propertyBag.Items)
            {
                if (string.Equals(trackingPropertyType.Name, "ErrorCode", StringComparison.OrdinalIgnoreCase))
                {
                    value = trackingPropertyType.Value;
                }
                else if (string.Equals(trackingPropertyType.Name, "Server", StringComparison.OrdinalIgnoreCase))
                {
                    value2 = trackingPropertyType.Value;
                }
                else if (string.Equals(trackingPropertyType.Name, "Domain", StringComparison.OrdinalIgnoreCase))
                {
                    value3 = trackingPropertyType.Value;
                }
            }
            if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value2) || string.IsNullOrEmpty(value3))
            {
                TraceWrapper.SearchLibraryTracer.TraceError(0, "Error is not well formed. One or more of errorCode, server or domain is missing", new object[0]);
                return(null);
            }
            TrackingError trackingError = new TrackingError(propertyBag);

            TraceWrapper.SearchLibraryTracer.TraceDebug <TrackingError>(0, "Decoded error: {0}", trackingError);
            return(trackingError);
        }
Beispiel #3
0
        public override BaseQuery CreateFromGroup(RecipientData recipientData, BaseQuery[] groupMembers, bool groupCapped)
        {
            TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Attempted to create group query in x-forest case.", new object[0]);
            TrackingError          trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Group autodiscover query for Cross-Forest disallowed", string.Empty);
            TrackingFatalException ex            = new TrackingFatalException(trackingError, null, false);

            DiagnosticWatson.SendWatsonWithoutCrash(ex, "CreateFromGroup", TimeSpan.FromDays(1.0));
            throw ex;
        }
Beispiel #4
0
        public override LocalQuery CreateLocalQuery(ClientContext clientContext, DateTime requestCompletionDeadline)
        {
            TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Attempted to create local query in x-forest case.", new object[0]);
            TrackingError          trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Local autodiscover query for Cross-Forest disallowed", string.Empty);
            TrackingFatalException ex            = new TrackingFatalException(trackingError, null, false);

            DiagnosticWatson.SendWatsonWithoutCrash(ex, "CreateLocalQuery", TimeSpan.FromDays(1.0));
            throw ex;
        }
        protected TrackingBaseException(TrackingError trackingError, Exception innerException, bool isAlreadyLogged) : base(trackingError.ToString(), innerException)
        {
            this.trackingError   = trackingError;
            this.IsAlreadyLogged = isAlreadyLogged;
            ErrorCode errorCode;

            if (EnumValidator <ErrorCode> .TryParse(trackingError.ErrorCode, EnumParseOptions.Default, out errorCode))
            {
                this.isOverBudgetError = (errorCode == ErrorCode.BudgetExceeded || errorCode == ErrorCode.TimeBudgetExceeded || errorCode == ErrorCode.TotalBudgetExceeded);
            }
        }
Beispiel #6
0
 private bool IsUnderTimeBudget(out TrackingError trackingError)
 {
     trackingError = null;
     if (this.timer.Elapsed > this.timeBudgetAllowed)
     {
         TraceWrapper.SearchLibraryTracer.TraceError <long, double>(this.GetHashCode(), "Over time budget, used={0}, allowed={1}", this.timer.ElapsedMilliseconds, this.timeBudgetAllowed.TotalMilliseconds);
         trackingError = this.errors.Add(ErrorCode.TimeBudgetExceeded, string.Empty, string.Empty, string.Empty);
         return(false);
     }
     return(true);
 }
Beispiel #7
0
        internal static void AcquireThread()
        {
            int num = Interlocked.Increment(ref TrackingEventBudget.currentSearchingThreadCount);

            if (num <= ServerCache.Instance.NumberOfThreadsAllowed)
            {
                return;
            }
            TraceWrapper.SearchLibraryTracer.TraceError <int, int>(0, "Server too busy, current-threads={0} max-threads={1}", num, ServerCache.Instance.NumberOfThreadsAllowed);
            TrackingError trackingError = new TrackingError(ErrorCode.TotalBudgetExceeded, string.Empty, string.Empty, string.Empty);

            throw new TrackingTransientException(trackingError, null, false);
        }
 private void ReadErrorsFromWSMessage_Exchange2010SP1(ArrayOfTrackingPropertiesType[] propertyBags)
 {
     if (propertyBags != null)
     {
         foreach (ArrayOfTrackingPropertiesType propertyBag in propertyBags)
         {
             TrackingError trackingError = TrackingError.CreateFromWSMessage(propertyBag);
             if (trackingError != null)
             {
                 this.errors.Add(trackingError);
             }
         }
     }
 }
Beispiel #9
0
 public void IncrementBy(uint incrementValue)
 {
     if ((ulong)(this.budgetUsed + incrementValue) >= (ulong)((long)ServerCache.Instance.MaxTrackingEventBudgetForSingleQuery))
     {
         TrackingError trackingError = this.errors.Add(ErrorCode.BudgetExceeded, string.Empty, string.Empty, string.Empty);
         throw new TrackingFatalException(trackingError, null, true);
     }
     this.budgetUsed += incrementValue;
     Interlocked.Add(ref TrackingEventBudget.totalBudgetUsed, (int)incrementValue);
     if (TrackingEventBudget.totalBudgetUsed > ServerCache.Instance.MaxTrackingEventBudgetForAllQueries)
     {
         TrackingError trackingError2 = this.errors.Add(ErrorCode.TotalBudgetExceeded, string.Empty, string.Empty, string.Empty);
         throw new TrackingTransientException(trackingError2, null, true);
     }
 }
 public TrackingFatalException(TrackingError trackingError, Exception innerException, bool isAlreadyLogged) : base(trackingError, innerException, isAlreadyLogged)
 {
 }
Beispiel #11
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);
        }
Beispiel #12
0
        private ResponseType TryCallWebServiceMethod <ResponseType, RequestType>(WebServiceBinding.WebMethodCallDelegate <ResponseType, RequestType> methodCall, RequestType request, out Exception exception)
        {
            exception = null;
            Exception     ex            = null;
            Exception     ex2           = null;
            TrackingError trackingError = null;
            bool          flag          = false;

            try
            {
                this.directoryContext.Yield();
                flag = true;
                return(methodCall(request));
            }
            catch (InvalidOperationException ex3)
            {
                WebException ex4 = ex3 as WebException;
                if (ex4 != null)
                {
                    trackingError = this.GetTrackingErrorForWebException(ex4, false);
                    ex            = ex3;
                }
                else
                {
                    trackingError = new TrackingError(ErrorCode.UnexpectedErrorTransient, this.TargetInfoForDisplay, string.Format("WS call to {0} failed with InvalidOperationException", this.TargetInfoForDisplay), ex3.ToString());
                    ex2           = ex3;
                }
            }
            catch (SoapException ex5)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, this.TargetInfoForDisplay, string.Format("WS call to {0} failed with SoapException", this.TargetInfoForDisplay), ex5.ToString());
                ex2           = ex5;
            }
            catch (SocketException ex6)
            {
                trackingError = new TrackingError(ErrorCode.Connectivity, this.TargetInfoForDisplay, string.Empty, ex6.ToString());
                ex            = ex6;
            }
            catch (InvalidParameterException ex7)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, this.TargetInfoForDisplay, string.Format("WS call to {0} failed with InvalidParameterException", this.TargetInfoForDisplay), ex7.ToString());
                ex2           = ex7;
            }
            catch (SoapFaultException ex8)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, this.TargetInfoForDisplay, string.Format("WS call to {0} failed with SoapFaultException", this.TargetInfoForDisplay), ex8.ToString());
                ex2           = ex8;
            }
            catch (TimeoutExpiredException ex9)
            {
                trackingError = new TrackingError(ErrorCode.TimeBudgetExceeded, this.TargetInfoForDisplay, string.Empty, ex9.ToString());
                ex            = ex9;
            }
            catch (ClientDisconnectedException ex10)
            {
                trackingError = new TrackingError(ErrorCode.Connectivity, this.TargetInfoForDisplay, string.Empty, ex10.ToString());
                ex            = ex10;
            }
            catch (AvailabilityException ex11)
            {
                trackingError = this.GetTrackingErrorForAvailabilityException(ex11);
                ex            = ex11;
            }
            catch (AuthzException ex12)
            {
                trackingError = new TrackingError(ErrorCode.CrossForestAuthentication, this.TargetInfoForDisplay, string.Empty, ex12.ToString());
                ex            = ex12;
            }
            catch (OverBudgetException ex13)
            {
                trackingError = new TrackingError(ErrorCode.BudgetExceeded, this.TargetInfoForDisplay, string.Empty, ex13.ToString());
                ex            = ex13;
            }
            catch (InvalidFederatedOrganizationIdException ex14)
            {
                trackingError = new TrackingError(ErrorCode.CrossPremiseAuthentication, this.TargetInfoForDisplay, string.Empty, ex14.ToString());
                ex2           = ex14;
            }
            catch (UserWithoutFederatedProxyAddressException ex15)
            {
                trackingError = new TrackingError(ErrorCode.CrossPremiseMisconfiguration, this.TargetInfoForDisplay, string.Empty, ex15.ToString());
                ex2           = ex15;
            }
            finally
            {
                if (flag)
                {
                    this.directoryContext.Acquire();
                }
            }
            this.errors.Errors.Add(trackingError);
            if (ex != null)
            {
                exception = new TrackingTransientException(trackingError, ex, true);
            }
            else
            {
                exception = new TrackingTransientException(trackingError, ex2, true);
            }
            TraceWrapper.SearchLibraryTracer.TraceError <Exception>(this.GetHashCode(), "Exception in web-service call: {0}", (ex == null) ? ex2 : ex);
            return(default(ResponseType));
        }
Beispiel #13
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);
        }
Beispiel #14
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();
                }
            }
        }