Esempio n. 1
0
        private void DiscoverUrl()
        {
            string text = null;

            if (this.IsTraceEnabled(TraceType.DebugTrace))
            {
                this.Tracer.TraceDebug <string>(0L, "Will try to discover the URL for EWS with the Backendlocator for  mailbox {0}", this.connectionManager.GetPrincipalInfoForTracing());
            }
            Exception innerException = null;

            try
            {
                Uri backEndWebServicesUrl = this.connectionManager.GetBackEndWebServicesUrl();
                if (backEndWebServicesUrl != null)
                {
                    if (this.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        this.Tracer.TraceDebug <string, string>(0L, "Found Uri from the back end locator.{0}, {1}", backEndWebServicesUrl.ToString(), this.connectionManager.GetPrincipalInfoForTracing());
                    }
                    text = backEndWebServicesUrl.ToString();
                }
                else if (this.IsTraceEnabled(TraceType.ErrorTrace))
                {
                    this.Tracer.TraceError <string>(0L, "Unable to discover internal URL for EWS for mailbox {0}. BackEndLocator call returned null", this.connectionManager.GetPrincipalInfoForTracing());
                }
            }
            catch (LocalizedException ex)
            {
                DiagnosticContext.TraceLocation((LID)51388U);
                innerException = ex;
                if (this.IsTraceEnabled(TraceType.ErrorTrace))
                {
                    this.Tracer.TraceError <string, LocalizedException>(0L, "Unable to discover internal URL for EWS for mailbox {0} due to exception {1}", this.connectionManager.GetPrincipalInfoForTracing(), ex);
                }
            }
            if (string.IsNullOrEmpty(text))
            {
                DiagnosticContext.TraceLocation((LID)45244U);
                throw new FailedToFindEwsEndpointException(this.connectionManager.GetPrincipalInfoForTracing(), innerException);
            }
            this.binding.Url         = text;
            this.lastUrlDiscoverTime = ExDateTime.UtcNow;
            if (this.IsTraceEnabled(TraceType.DebugTrace))
            {
                this.Tracer.TraceDebug(0L, "Refreshed service binding (url and adminauditlogs folder), new url: " + text);
            }
        }
Esempio n. 2
0
 public void RefreshUrl(bool reloadBinding)
 {
     if (reloadBinding)
     {
         DiagnosticContext.TraceLocation((LID)59580U);
         this.connectionManager.ReloadPrincipal();
         this.InitializeExchangeBinding();
     }
     if (this.lastUrlDiscoverTime.Add(this.ExpiryInterval) < ExDateTime.UtcNow)
     {
         DiagnosticContext.TraceLocation((LID)35004U);
         if (this.IsTraceEnabled(TraceType.DebugTrace))
         {
             this.Tracer.TraceDebug <ExDateTime, string>(0L, "Need to refresh service binding, last discover time : {0}, current url: {1}", this.lastUrlDiscoverTime, this.binding.Url.ToString());
         }
         this.DiscoverUrl();
     }
 }
Esempio n. 3
0
        public bool CreateFolder(string folderName, FolderIdType parentFolderId, out FolderIdType folderId)
        {
            DiagnosticContext.TraceLocation((LID)39100U);
            folderId = null;
            CreateFolderType cft = new CreateFolderType
            {
                ParentFolderId = new TargetFolderIdType
                {
                    Item = parentFolderId
                },
                Folders = new BaseFolderType[]
                {
                    new FolderType
                    {
                        DisplayName = folderName
                    }
                }
            };

            return(this.InternalCreateFolder(cft, null, out folderId));
        }
Esempio n. 4
0
        protected override void WriteResult(IConfigurable dataObject)
        {
            ADUser mailbox = (ADUser)dataObject;

            this.isUserObjValid = true;
            if (this.resultCount <= this.ResultSize)
            {
                DiagnosticContext.TraceLocation((LID)47804U);
                Exception ex = null;
                try
                {
                    IEnumerable <MailboxAuditLogRecord> enumerable = this.worker.SearchMailboxAudits(mailbox);
                    foreach (MailboxAuditLogRecord dataObject2 in enumerable)
                    {
                        this.resultCount++;
                        if (this.resultCount > this.ResultSize)
                        {
                            DiagnosticContext.TraceLocation((LID)64188U);
                            break;
                        }
                        base.WriteResult(dataObject2);
                    }
                }
                catch (StorageTransientException ex2)
                {
                    DiagnosticContext.TraceLocation((LID)39612U);
                    TaskLogger.Trace("Search mailbox audit log failed with transient storage exception. {0}", new object[]
                    {
                        ex2
                    });
                    ex = ex2;
                    base.WriteError(ex2, ErrorCategory.ReadError, null);
                }
                catch (StoragePermanentException ex3)
                {
                    DiagnosticContext.TraceLocation((LID)55996U);
                    TaskLogger.Trace("Search mailbox audit log failed with permanent storage exception. {0}", new object[]
                    {
                        ex3
                    });
                    ex = ex3;
                    base.WriteError(ex3, ErrorCategory.ReadError, null);
                }
                catch (MailboxAuditLogSearchException ex4)
                {
                    DiagnosticContext.TraceLocation((LID)43708U);
                    ex = ex4;
                    base.WriteError(ex4, ErrorCategory.NotSpecified, null);
                }
                catch (AuditLogException ex5)
                {
                    DiagnosticContext.TraceLocation((LID)60092U);
                    ex = ex5;
                    base.WriteError(ex5, ErrorCategory.NotSpecified, null);
                }
                finally
                {
                    if (this.searchStatistics != null)
                    {
                        this.searchStatistics.MailboxCount++;
                        if (ex != null)
                        {
                            this.searchStatistics.ErrorType = ex;
                            this.searchStatistics.ErrorCount++;
                        }
                    }
                    TaskLogger.LogExit();
                }
            }
        }
Esempio n. 5
0
        private void CallEwsWithRetries(LID lid, Func <BaseResponseMessageType> delegateEwsCall, Func <ResponseMessageType, int, bool> responseMessageProcessor, Func <ResponseMessageType, int, bool> responseErrorProcessor)
        {
            ExDateTime t    = ExDateTime.UtcNow.Add((this.CallTimeout < EwsAuditClient.TotalRetryTimeWindow) ? EwsAuditClient.TotalRetryTimeWindow : this.CallTimeout);
            bool       flag = false;
            Exception  ex   = null;
            int        num  = -1;

            do
            {
                if (flag)
                {
                    this.WaitBeforeRetry(num);
                }
                ex   = null;
                flag = false;
                num++;
                try
                {
                    DiagnosticContext.TraceDword((LID)57532U, (uint)num);
                    BaseResponseMessageType baseResponseMessageType;
                    using (DiagnosticContext.TraceLatency(lid))
                    {
                        baseResponseMessageType = delegateEwsCall();
                    }
                    int i = 0;
                    while (i < baseResponseMessageType.ResponseMessages.Items.Length)
                    {
                        ResponseMessageType responseMessageType = baseResponseMessageType.ResponseMessages.Items[i];
                        if (responseMessageProcessor != null && responseMessageProcessor(responseMessageType, i))
                        {
                            DiagnosticContext.TraceLocation((LID)32956U);
                            if (this.IsTraceEnabled(TraceType.DebugTrace))
                            {
                                this.Tracer.TraceDebug(0L, "Successfully executed EWS call");
                                break;
                            }
                            break;
                        }
                        else
                        {
                            if (responseMessageType.ResponseClass == ResponseClassType.Error)
                            {
                                DiagnosticContext.TraceDwordAndString((LID)33100U, (uint)responseMessageType.ResponseCode, responseMessageType.ResponseCode.ToString());
                                if (responseMessageType.ResponseCode == ResponseCodeType.ErrorCrossSiteRequest)
                                {
                                    if (this.IsTraceEnabled(TraceType.DebugTrace))
                                    {
                                        this.Tracer.TraceDebug(0L, "Crosssite request error , recreate exchange binding and reset the url caches");
                                    }
                                    flag = true;
                                    this.RefreshUrl(true);
                                    break;
                                }
                                if (!EwsAuditClient.TransientServiceErrors.Contains(responseMessageType.ResponseCode))
                                {
                                    if (responseErrorProcessor == null || !responseErrorProcessor(responseMessageType, i))
                                    {
                                        if (this.IsTraceEnabled(TraceType.ErrorTrace))
                                        {
                                            this.Tracer.TraceError <string, string, string>(0L, "Permanent error encountered:  {0}, {1}, {2}", responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString());
                                        }
                                        DiagnosticContext.TraceLocation((LID)65212U);
                                        throw new AuditLogServiceException(responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString());
                                    }
                                    DiagnosticContext.TraceLocation((LID)48828U);
                                    if (this.IsTraceEnabled(TraceType.DebugTrace))
                                    {
                                        this.Tracer.TraceDebug(0L, "Error encountered, but was handled by error callback:  {0}, {1}, {2}, response index={3}", new object[]
                                        {
                                            responseMessageType.ResponseClass.ToString(),
                                            responseMessageType.ResponseCode.ToString(),
                                            responseMessageType.MessageText.ToString(),
                                            i
                                        });
                                    }
                                }
                                else
                                {
                                    DiagnosticContext.TraceLocation((LID)40636U);
                                    flag = true;
                                    ex   = new AuditLogServiceException(responseMessageType.ResponseClass.ToString(), responseMessageType.ResponseCode.ToString(), responseMessageType.MessageText.ToString());
                                    if (this.IsTraceEnabled(TraceType.DebugTrace))
                                    {
                                        this.Tracer.TraceDebug(0L, "Transient error encountered, will attempt to retry, Exception: " + ex);
                                    }
                                }
                            }
                            i++;
                        }
                    }
                }
                catch (CommunicationException ex2)
                {
                    DiagnosticContext.TraceLocation((LID)57020U);
                    ex   = ex2;
                    flag = true;
                }
                catch (TimeoutException ex3)
                {
                    DiagnosticContext.TraceLocation((LID)44732U);
                    ex   = ex3;
                    flag = false;
                }
                catch (SoapException ex4)
                {
                    DiagnosticContext.TraceLocation((LID)61116U);
                    ex   = ex4;
                    flag = false;
                }
                catch (WebException ex5)
                {
                    DiagnosticContext.TraceLocation((LID)36540U);
                    ex   = ex5;
                    flag = false;
                }
                catch (IOException ex6)
                {
                    DiagnosticContext.TraceLocation((LID)52924U);
                    ex   = ex6;
                    flag = false;
                }
                catch (InvalidOperationException ex7)
                {
                    DiagnosticContext.TraceLocation((LID)46780U);
                    ex   = ex7;
                    flag = false;
                }
                catch (LocalizedException ex8)
                {
                    DiagnosticContext.TraceLocation((LID)63164U);
                    ex   = ex8;
                    flag = false;
                }
            }while (flag && t > ExDateTime.UtcNow);
            if (ex != null)
            {
                if (this.IsTraceEnabled(TraceType.ErrorTrace))
                {
                    this.Tracer.TraceError <int, Exception>(0L, "Failed to make EWS call to audit log, Total attempts made {0}, Exception: {1} ", num, ex);
                }
                DiagnosticContext.TraceLocation((LID)38588U);
                throw this.GetSpecificException(ex);
            }
        }
Esempio n. 6
0
        public void CheckAndCreateWellKnownFolder(DistinguishedFolderIdNameType parentFolder, DistinguishedFolderIdNameType targetFolder, out FolderIdType targetFolderId)
        {
            targetFolderId = null;
            GetFolderType getFolder = new GetFolderType
            {
                FolderShape = new FolderResponseShapeType
                {
                    BaseShape = DefaultShapeNamesType.Default
                },
                FolderIds = new BaseFolderIdType[]
                {
                    new DistinguishedFolderIdType
                    {
                        Id = targetFolder
                    }
                }
            };
            FolderIdType localTargetFolderId = null;
            bool         retry = false;

            do
            {
                this.CallEwsWithRetries((LID)47292U, () => this.binding.GetFolder(getFolder), delegate(ResponseMessageType responseMessage, int messageIndex)
                {
                    FolderInfoResponseMessageType folderInfoResponseMessageType = responseMessage as FolderInfoResponseMessageType;
                    if (folderInfoResponseMessageType != null && folderInfoResponseMessageType.ResponseClass == ResponseClassType.Success && folderInfoResponseMessageType.Folders != null && folderInfoResponseMessageType.Folders.Length == 1)
                    {
                        localTargetFolderId = folderInfoResponseMessageType.Folders[0].FolderId;
                        if (this.IsTraceEnabled(TraceType.DebugTrace))
                        {
                            this.Tracer.TraceDebug <string, string>(0L, "Found the folder {0} with the id {1}", targetFolder.ToString(), localTargetFolderId.Id);
                        }
                        retry = false;
                        return(true);
                    }
                    return(false);
                }, delegate(ResponseMessageType responseMessage, int messageIndex)
                {
                    if (responseMessage != null && responseMessage.ResponseClass == ResponseClassType.Error && responseMessage.ResponseCode == ResponseCodeType.ErrorFolderNotFound && !retry)
                    {
                        DiagnosticContext.TraceLocation((LID)37196U);
                        if (this.IsTraceEnabled(TraceType.DebugTrace))
                        {
                            this.Tracer.TraceDebug(0L, "Folder not found, an attempt will be made to create it", new object[]
                            {
                                targetFolder.ToString(),
                                responseMessage.ResponseClass,
                                responseMessage.ResponseCode,
                                responseMessage.MessageText
                            });
                        }
                        return(true);
                    }
                    return(false);
                });
                if (localTargetFolderId == null && !retry)
                {
                    DiagnosticContext.TraceLocation((LID)61628U);
                    if (!this.InternalCreateFolder(new CreateFolderType
                    {
                        ParentFolderId = new TargetFolderIdType
                        {
                            Item = new DistinguishedFolderIdType
                            {
                                Id = parentFolder,
                                Mailbox = this.Mailbox
                            }
                        },
                        Folders = new BaseFolderType[]
                        {
                            new FolderType
                            {
                                DistinguishedFolderId = targetFolder,
                                DistinguishedFolderIdSpecified = true
                            }
                        }
                    }, delegate(ResponseMessageType responseMessage, int messageIndex)
                    {
                        if (responseMessage != null && responseMessage.ResponseClass == ResponseClassType.Error && responseMessage.ResponseCode == ResponseCodeType.ErrorInvalidOperation)
                        {
                            DiagnosticContext.TraceLocation((LID)53580U);
                            retry = true;
                            return(true);
                        }
                        return(false);
                    }, out localTargetFolderId))
                    {
                        localTargetFolderId = null;
                    }
                }
            }while (retry);
            ExAssert.RetailAssert(localTargetFolderId != null, "Well known folder ID must be valid at this point");
            targetFolderId = localTargetFolderId;
        }
 protected override void WriteResult <T>(IEnumerable <T> dataObjects)
 {
     try
     {
         TaskLogger.LogEnter(new object[]
         {
             dataObjects
         });
         DiagnosticContext.Reset();
         using (AuditLogOpticsLogData auditLogOpticsLogData = new AuditLogOpticsLogData())
         {
             auditLogOpticsLogData.IsAsynchronous      = false;
             auditLogOpticsLogData.CallResult          = false;
             auditLogOpticsLogData.SearchStartDateTime = this.searchObject.StartDateUtc;
             auditLogOpticsLogData.SearchEndDateTime   = this.searchObject.EndDateUtc;
             try
             {
                 if (AdminAuditLogHelper.ShouldIssueWarning(base.CurrentOrganizationId))
                 {
                     DiagnosticContext.TraceLocation((LID)42684U);
                     this.WriteWarning(Strings.WarningSearchAdminAuditLogOnPreE15(base.CurrentOrganizationId.ToString()));
                 }
                 else
                 {
                     if (dataObjects != null)
                     {
                         using (IEnumerator <AdminAuditLogConfig> enumerator = (IEnumerator <AdminAuditLogConfig>)dataObjects.GetEnumerator())
                         {
                             this.GetAuditConfigObject(enumerator);
                             auditLogOpticsLogData.SearchType     = "Admin";
                             auditLogOpticsLogData.OrganizationId = this.searchObject.OrganizationId;
                             auditLogOpticsLogData.ShowDetails    = true;
                             auditLogOpticsLogData.MailboxCount   = 1;
                             AdminAuditLogSearchWorker adminAuditLogSearchWorker = new AdminAuditLogSearchWorker(600, this.searchObject, auditLogOpticsLogData);
                             base.WriteVerbose(Strings.VerboseStartAuditLogSearch);
                             AdminAuditLogEvent[] array = adminAuditLogSearchWorker.Search();
                             base.WriteVerbose(Strings.VerboseSearchCompleted((array != null) ? array.Length : 0));
                             foreach (AdminAuditLogEvent dataObject in array)
                             {
                                 this.WriteResult(dataObject);
                             }
                             auditLogOpticsLogData.CallResult = true;
                             goto IL_181;
                         }
                     }
                     DiagnosticContext.TraceLocation((LID)59068U);
                     Exception ex = new AdminAuditLogSearchException(Strings.ErrorAdminAuditLogConfig(base.CurrentOrganizationId.ToString()));
                     auditLogOpticsLogData.ErrorType = ex;
                     auditLogOpticsLogData.ErrorCount++;
                     base.WriteError(ex, ErrorCategory.ObjectNotFound, null);
                     IL_181 :;
                 }
             }
             catch (ArgumentException ex2)
             {
                 DiagnosticContext.TraceLocation((LID)34492U);
                 auditLogOpticsLogData.ErrorType = ex2;
                 auditLogOpticsLogData.ErrorCount++;
                 base.WriteError(ex2, ErrorCategory.InvalidArgument, null);
             }
             catch (AdminAuditLogSearchException ex3)
             {
                 DiagnosticContext.TraceLocation((LID)50876U);
                 auditLogOpticsLogData.ErrorType = ex3;
                 auditLogOpticsLogData.ErrorCount++;
                 base.WriteError(ex3, ErrorCategory.NotSpecified, null);
             }
         }
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }