Esempio n. 1
0
        // Token: 0x06000535 RID: 1333 RVA: 0x00027478 File Offset: 0x00025678
        public RemoteArchiveProcessorBase(MailboxSession mailboxSession, ADUser user, StatisticsLogEntry statisticsLogEntry, bool isCrossPremise, bool isTestMode)
        {
            this.statisticsLogEntry = statisticsLogEntry;
            this.isCrossPremise     = isCrossPremise;
            this.LoadRegistryConfigurations();
            this.primaryMailboxSession = mailboxSession;
            this.currentBatch          = new List <ElcEwsItem>(this.moveToArchiveBatchCountLimit);
            this.currentBatchSize      = 0U;
            if (isTestMode)
            {
                return;
            }
            Uri uri = ElcEwsClientHelper.DiscoverEwsUrl(mailboxSession.MailboxOwner.MailboxInfo);

            if (uri != null)
            {
                this.PrimaryEwsClient = new ElcEwsClient(mailboxSession.MailboxOwner, uri, new ElcEwsCallingContext(user, false), RemoteArchiveProcessorBase.TotalRetryTimeWindowForPrimary, RemoteArchiveProcessorBase.RetryScheduleForPrimary);
            }
            Uri uri2 = isCrossPremise ? ElcEwsClientHelper.DiscoverCloudArchiveEwsUrl(user) : ElcEwsClientHelper.DiscoverEwsUrl(mailboxSession.MailboxOwner.GetArchiveMailbox());

            if (uri2 != null)
            {
                this.ArchiveEwsClient = new ElcEwsClient(mailboxSession.MailboxOwner, uri2, new ElcEwsCallingContext(user, isCrossPremise), RemoteArchiveProcessorBase.TotalRetryTimeWindowForArchive, RemoteArchiveProcessorBase.RetryScheduleForArchive);
                return;
            }
            throw new ElcEwsException(ElcEwsErrorType.ArchiveExchangeWebServiceNotAvailable, "Archive EWS url is unknown.");
        }
Esempio n. 2
0
 // Token: 0x0600053D RID: 1341 RVA: 0x00027D94 File Offset: 0x00025F94
 internal static object[] ConvertToFolderProperties(IEnumerable <ExtendedPropertyType> propertyList)
 {
     object[] array = new object[FolderHelper.DataColumns.Length];
     if (propertyList != null)
     {
         foreach (ExtendedPropertyType extendedPropertyType in propertyList)
         {
             if (string.Compare("RetentionTagEntryId", extendedPropertyType.ExtendedFieldURI.PropertyName, true) == 0)
             {
                 array[8] = ElcEwsClientHelper.ConvertRetentionPropertyFromService(extendedPropertyType.Item, extendedPropertyType.ExtendedFieldURI.PropertyType);
             }
             else
             {
                 int num = (int)RemoteArchiveProcessorBase.RetentionPropertyTagsMapping[extendedPropertyType.ExtendedFieldURI.PropertyTag];
                 array[num] = ElcEwsClientHelper.ConvertRetentionPropertyFromService(extendedPropertyType.Item, extendedPropertyType.ExtendedFieldURI.PropertyType);
             }
         }
     }
     return(array);
 }
Esempio n. 3
0
        // Token: 0x0600053C RID: 1340 RVA: 0x00027BA4 File Offset: 0x00025DA4
        public FolderTuple CreateAndUpdateFolderInArchive(FolderTuple parentInArchive, FolderTuple sourceInPrimary)
        {
            FolderTupleRemoteArchive folderTupleRemoteArchive = (FolderTupleRemoteArchive)parentInArchive;
            FolderType     folderType     = new FolderType();
            BaseFolderType baseFolderType = null;

            folderType.DisplayName = sourceInPrimary.DisplayName;
            List <ExtendedPropertyType> list = new List <ExtendedPropertyType>();

            for (FolderHelper.DataColumnIndex dataColumnIndex = FolderHelper.DataColumnIndex.startOfTagPropsIndex; dataColumnIndex <= FolderHelper.DataColumnIndex.containerClassIndex; dataColumnIndex++)
            {
                PropertyDefinition      key = FolderHelper.DataColumns[(int)dataColumnIndex];
                PathToExtendedFieldType pathToExtendedFieldType = this.EwsStorePropertyMapping[key];
                object obj = sourceInPrimary.FolderProps[key];
                if (obj != null && !(obj is PropertyError))
                {
                    obj = ElcEwsClientHelper.ConvertRetentionPropertyForService(obj, pathToExtendedFieldType.PropertyType);
                    ExtendedPropertyType item = new ExtendedPropertyType
                    {
                        ExtendedFieldURI = pathToExtendedFieldType,
                        Item             = obj
                    };
                    list.Add(item);
                }
            }
            if (list.Count > 0)
            {
                folderType.ExtendedProperty = list.ToArray();
            }
            try
            {
                baseFolderType = this.ArchiveEwsClient.CreateFolder(folderTupleRemoteArchive.EwsFolderId, folderType);
            }
            catch (ElcEwsException arg)
            {
                RemoteArchiveProcessorBase.Tracer.TraceError <string, MailboxSession, ElcEwsException>((long)this.GetHashCode(), "Create folder {0} in archive for {1} failed, Exception: {2}", sourceInPrimary.DisplayName, this.primaryMailboxSession, arg);
                throw;
            }
            if (baseFolderType != null)
            {
                try
                {
                    baseFolderType = this.ArchiveEwsClient.GetFolderById(baseFolderType.FolderId, this.FolderAllProperties.ToArray());
                    goto IL_16D;
                }
                catch (ElcEwsException arg2)
                {
                    RemoteArchiveProcessorBase.Tracer.TraceError <string, MailboxSession, ElcEwsException>((long)this.GetHashCode(), "Get newly created folder {0} in archive for {1} failed, Exception: {2}", sourceInPrimary.DisplayName, this.primaryMailboxSession, arg2);
                    throw;
                }
                goto IL_13E;
IL_16D:
                if (baseFolderType != null)
                {
                    return(new FolderTupleRemoteArchive(baseFolderType, baseFolderType.FolderId, folderTupleRemoteArchive.EwsFolderId, baseFolderType.DisplayName, RemoteArchiveProcessorBase.ConvertToFolderProperties(baseFolderType.ExtendedProperty)));
                }
                RemoteArchiveProcessorBase.Tracer.TraceError <string, MailboxSession>((long)this.GetHashCode(), "Get newly created folder {0} in archive for {1} returned no folder", sourceInPrimary.DisplayName, this.primaryMailboxSession);
                throw new ElcEwsException(ElcEwsErrorType.FailedToGetFolderById, "Get newly created folder {0} returned no folder");
            }
IL_13E:
            RemoteArchiveProcessorBase.Tracer.TraceError <string, MailboxSession>((long)this.GetHashCode(), "Create folder {0} in archive for {1} returned no folder", sourceInPrimary.DisplayName, this.primaryMailboxSession);
            throw new ElcEwsException(ElcEwsErrorType.FailedToCreateFolder, "Creating folder {0} returned no folder");
        }
Esempio n. 4
0
        // Token: 0x0600053B RID: 1339 RVA: 0x000279E4 File Offset: 0x00025BE4
        public void UpdatePropertiesOnFolderInArchive(FolderTuple sourceInPrimary, FolderTuple targetInArchive)
        {
            FolderTupleRemoteArchive folderTupleRemoteArchive = targetInArchive as FolderTupleRemoteArchive;

            if (folderTupleRemoteArchive == null)
            {
                throw new ArgumentException("Archive folder tuple must be a FolderTupleRemoteArchive.", "targetInArchive");
            }
            List <FolderChangeDescriptionType> list = new List <FolderChangeDescriptionType>();

            for (FolderHelper.DataColumnIndex dataColumnIndex = FolderHelper.DataColumnIndex.startOfTagPropsIndex; dataColumnIndex <= FolderHelper.DataColumnIndex.containerClassIndex; dataColumnIndex++)
            {
                PropertyDefinition      key = FolderHelper.DataColumns[(int)dataColumnIndex];
                PathToExtendedFieldType pathToExtendedFieldType = this.EwsStorePropertyMapping[key];
                object obj  = sourceInPrimary.FolderProps[key];
                object obj2 = folderTupleRemoteArchive.FolderProps[key];
                if (obj != null && !(obj is PropertyError))
                {
                    string text = ElcEwsClientHelper.ConvertRetentionPropertyForService(obj, pathToExtendedFieldType.PropertyType);
                    string b    = ElcEwsClientHelper.ConvertRetentionPropertyForService(obj2, pathToExtendedFieldType.PropertyType);
                    if (text != b)
                    {
                        SetFolderFieldType   setFolderFieldType   = new SetFolderFieldType();
                        FolderType           folderType           = new FolderType();
                        ExtendedPropertyType extendedPropertyType = new ExtendedPropertyType
                        {
                            ExtendedFieldURI = pathToExtendedFieldType,
                            Item             = text
                        };
                        folderType.ExtendedProperty = new ExtendedPropertyType[]
                        {
                            extendedPropertyType
                        };
                        setFolderFieldType.Item  = pathToExtendedFieldType;
                        setFolderFieldType.Item1 = folderType;
                        list.Add(setFolderFieldType);
                    }
                }
                else if (obj2 != null)
                {
                    list.Add(new DeleteFolderFieldType
                    {
                        Item = pathToExtendedFieldType
                    });
                }
            }
            if (list.Count > 0)
            {
                RemoteArchiveProcessorBase.Tracer.TraceDebug <RemoteArchiveProcessorBase, int, string>((long)this.GetHashCode(), "{0}: {1} properties to be updated for folder {2}.", this, list.Count, folderTupleRemoteArchive.DisplayName);
                FolderChangeType folderChangeType = new FolderChangeType();
                folderChangeType.Item    = folderTupleRemoteArchive.EwsFolderId;
                folderChangeType.Updates = list.ToArray();
                try
                {
                    this.ArchiveEwsClient.UpdateFolder(folderChangeType);
                }
                catch (ElcEwsException arg)
                {
                    RemoteArchiveProcessorBase.Tracer.TraceError <MailboxSession, string, ElcEwsException>((long)this.GetHashCode(), "Update folder {1} in archive for {0} failed, Exception: {2}", this.primaryMailboxSession, folderTupleRemoteArchive.DisplayName, arg);
                    throw;
                }
            }
        }
 // Token: 0x06000563 RID: 1379 RVA: 0x000294DE File Offset: 0x000276DE
 public ElcEwsCallingContext(ADUser user, bool isCrossPremise)
 {
     this.user           = user;
     this.isCrossPremise = isCrossPremise;
     this.userAgent      = ElcEwsClientHelper.GetOAuthUserAgent("ElcClient");
 }
Esempio n. 6
0
        // Token: 0x06000560 RID: 1376 RVA: 0x00028EBC File Offset: 0x000270BC
        protected void InternalCallService <BaseResponseMessageType>(Func <BaseResponseMessageType> delegateServiceCall, Action <BaseResponseMessageType> responseProcessor, Func <Exception, Exception> exceptionHandler, Func <bool> authorizationHandler, Action <Uri> urlRedirectionHandler)
        {
            int       num = 0;
            DateTime  t   = DateTime.UtcNow.Add(this.TotalRetryTimeWindow);
            Exception threadException;
            Exception ex;
            Exception ex2;

            for (;;)
            {
                ex = null;
                threadException = null;
                ex2             = null;
                bool flag  = false;
                bool flag2 = false;
                bool flag3 = false;
                if (this.ServiceBinding != null)
                {
                    ServiceBindingType serviceBinding = this.ServiceBinding;
                    serviceBinding.UserAgent = string.Format("{0}{1}=MRM&{2}={3}&{4}={5}&{6}={7}", new object[]
                    {
                        ElcEwsClientHelper.GetOAuthUserAgent("ElcClient"),
                        "S",
                        "BI",
                        DateTime.UtcNow.Ticks.ToString(),
                        "R",
                        num.ToString(),
                        "RT",
                        DateTime.UtcNow.Ticks.ToString()
                    });
                }
                try
                {
                    BaseResponseMessageType response = default(BaseResponseMessageType);
                    bool flag4 = false;
                    Thread thread = new Thread(delegate()
                    {
                        try
                        {
                            response = delegateServiceCall();
                        }
                        catch (Exception threadException)
                        {
                            threadException = threadException;
                        }
                    });
                    thread.Start();
                    while (!flag4)
                    {
                        if (this.AbortTokenForTasks.IsCancellationRequested)
                        {
                            throw new ExportException(ExportErrorType.StopRequested);
                        }
                        flag4 = thread.Join(5000);
                    }
                    if (!flag4)
                    {
                        thread.Abort();
                    }
                    if (threadException != null)
                    {
                        throw threadException;
                    }
                    if (responseProcessor != null)
                    {
                        responseProcessor(response);
                    }
                }
                catch (RetryException ex3)
                {
                    ex   = ex3.InnerException;
                    flag = true;
                    if (ex3.ResetRetryCounter)
                    {
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Resetting retry in RetryException.", new object[0]);
                        flag2 = true;
                    }
                }
                catch (ExportException ex4)
                {
                    ex = ex4;
                    if (ex4.ErrorType == ExportErrorType.Unauthorized)
                    {
                        flag3 = true;
                    }
                }
                catch (WebException ex5)
                {
                    ex = ex5;
                    if (ex5.Status == WebExceptionStatus.TrustFailure)
                    {
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Unable to establish trust on exception. No retry.", new object[0]);
                        flag = false;
                    }
                    else if (ex5.Status == WebExceptionStatus.ConnectFailure)
                    {
                        SocketException ex6 = ex5.InnerException as SocketException;
                        flag = (ex6 == null || ex6.SocketErrorCode != SocketError.ConnectionRefused);
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Connect failure. Retry: {0}.", new object[]
                        {
                            flag
                        });
                    }
                    else if (ex5.Status == WebExceptionStatus.NameResolutionFailure)
                    {
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: DNS look up failure. No retry.", new object[0]);
                        flag = false;
                    }
                    else
                    {
                        HttpWebResponse httpWebResponse = ex5.Response as HttpWebResponse;
                        flag = true;
                        if (httpWebResponse != null)
                        {
                            HttpStatusCode statusCode = httpWebResponse.StatusCode;
                            switch (statusCode)
                            {
                            case HttpStatusCode.MovedPermanently:
                            case HttpStatusCode.Found:
                                break;

                            default:
                                if (statusCode != HttpStatusCode.TemporaryRedirect)
                                {
                                    if (statusCode == HttpStatusCode.Unauthorized)
                                    {
                                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: HTTP 401 unauthorized", new object[0]);
                                        flag  = false;
                                        flag3 = true;
                                        ex    = new ExportException(ExportErrorType.Unauthorized, ex5);
                                        goto IL_352;
                                    }
                                    goto IL_352;
                                }
                                break;
                            }
                            string text = httpWebResponse.Headers[HttpResponseHeader.Location];
                            Tracer.TraceInformation("ElcBaseServiceClient.InternalCallService: HTTP redirection to {0}", new object[]
                            {
                                text
                            });
                            ex   = new ExportException(ExportErrorType.UnexpectedWebServiceUrlRedirection, ex5);
                            flag = false;
                            if (Uri.IsWellFormedUriString(text, UriKind.Absolute))
                            {
                                Uri uri = new Uri(text);
                                if (uri.Scheme == Uri.UriSchemeHttps && urlRedirectionHandler != null)
                                {
                                    this.ServiceEndpoint = uri;
                                    urlRedirectionHandler(uri);
                                    ex    = null;
                                    flag  = true;
                                    flag2 = true;
                                    Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Resetting retry during HTTP redirection.", new object[0]);
                                }
                            }
                        }
                    }
                    IL_352 :;
                }
                catch (SoapException ex7)
                {
                    if (ex7.Code != null && ex7.Code.Name == "ErrorAccessDenied")
                    {
                        flag  = false;
                        flag3 = true;
                        ex    = new ExportException(ExportErrorType.Unauthorized, ex7);
                    }
                    else
                    {
                        ex   = ex7;
                        flag = false;
                        if (ex7.Code != null && ElcBaseServiceClient <ServiceBindingType, FunctionalInterfaceType> .IsTransientError(ex7.Code.Name))
                        {
                            flag = true;
                        }
                    }
                }
                catch (TimeoutException ex8)
                {
                    ex   = ex8;
                    flag = true;
                }
                catch (InvalidOperationException ex9)
                {
                    ex   = ex9;
                    flag = true;
                }
                if (ex != null)
                {
                    if (exceptionHandler != null)
                    {
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Exception handler is handling exception : {0}", new object[]
                        {
                            ex
                        });
                        ex2 = exceptionHandler(ex);
                        Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Exception after being handled : {0}", new object[]
                        {
                            ex2
                        });
                    }
                    else
                    {
                        ex2 = new ExportException(ExportErrorType.ExchangeWebServiceCallFailed, ex);
                    }
                }
                if (flag && !flag2)
                {
                    int num2 = this.GetRetryWaitTime(num);
                    Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Retry after {0} milliseconds on exception : {1}", new object[]
                    {
                        num2,
                        ex
                    });
                    while (num2 > 0 && t > DateTime.UtcNow)
                    {
                        Thread.Sleep((num2 > 5000) ? 5000 : num2);
                        num2 -= 5000;
                        if (this.AbortTokenForTasks.IsCancellationRequested)
                        {
                            goto Block_8;
                        }
                    }
                }
                if (flag3)
                {
                    Tracer.TraceInformation("ElcBaseServiceClient.InternalCallService: Unauthorized", new object[0]);
                    if (authorizationHandler == null || !authorizationHandler())
                    {
                        goto IL_4BE;
                    }
                    flag = true;
                }
                if (flag2)
                {
                    num = 0;
                }
                else
                {
                    num++;
                }
                if (!flag || !(t > DateTime.UtcNow))
                {
                    goto IL_4DF;
                }
            }
Block_8:
            throw new ExportException(ExportErrorType.StopRequested);
IL_4BE:
            throw ex;
IL_4DF:
            if (ex2 != null)
            {
                Tracer.TraceError("ElcBaseServiceClient.InternalCallService: Exception thrown after all possible actions: {0}", new object[]
                {
                    ex2
                });
                throw ex2;
            }
        }
        // Token: 0x0600059B RID: 1435 RVA: 0x0002B16C File Offset: 0x0002936C
        public static Uri DiscoverCloudArchiveEwsUrl(ADUser user)
        {
            Uri    result = null;
            string text   = null;
            string domain = user.ArchiveDomain.Domain;
            Uri    uri    = null;
            EndPointDiscoveryInfo endPointDiscoveryInfo;
            bool flag = RemoteDiscoveryEndPoint.TryGetDiscoveryEndPoint(OrganizationId.ForestWideOrgId, domain, null, null, null, out uri, out endPointDiscoveryInfo);

            if (endPointDiscoveryInfo != null && endPointDiscoveryInfo.Status != EndPointDiscoveryInfo.DiscoveryStatus.Success)
            {
                ElcEwsClientHelper.Tracer.TraceDebug <SmtpAddress, EndPointDiscoveryInfo.DiscoveryStatus, string>(0L, "Getting autodiscover url for {0} encountered problem with status {1}. {2}", user.PrimarySmtpAddress, endPointDiscoveryInfo.Status, endPointDiscoveryInfo.Message);
            }
            if (!flag || uri == null)
            {
                ElcEwsClientHelper.Tracer.TraceError <SmtpAddress>(0L, "Failed to get autodiscover URL for {0}.", user.PrimarySmtpAddress);
                return(null);
            }
            SmtpAddress      archiveAddress = new SmtpAddress(SmtpProxyAddress.EncapsulateExchangeGuid(domain, user.ArchiveGuid));
            Guid             value          = Guid.NewGuid();
            OAuthCredentials oauthCredentialsForAppActAsToken = OAuthCredentials.GetOAuthCredentialsForAppActAsToken(OrganizationId.ForestWideOrgId, user, domain);

            oauthCredentialsForAppActAsToken.ClientRequestId = new Guid?(value);
            AutodiscoverService service = new AutodiscoverService(EwsWsSecurityUrl.FixForAnonymous(uri), 4)
            {
                Credentials     = new OAuthCredentials(oauthCredentialsForAppActAsToken),
                PreAuthenticate = true,
                UserAgent       = ElcEwsClientHelper.GetOAuthUserAgent("ElcAutoDiscoverClient")
            };

            service.ClientRequestId       = value.ToString();
            service.ReturnClientRequestId = true;
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsClientHelper.CertificateErrorHandler));
                GetUserSettingsResponse response = null;
                Exception arg   = null;
                bool      flag2 = ElcEwsClientHelper.ExecuteEwsCall(delegate
                {
                    response = service.GetUserSettings(archiveAddress.ToString(), new UserSettingName[]
                    {
                        58
                    });
                }, out arg);
                if (flag2)
                {
                    if (response.ErrorCode == null)
                    {
                        if (!response.TryGetSettingValue <string>(58, ref text) || string.IsNullOrEmpty(text))
                        {
                            ElcEwsClientHelper.Tracer.TraceError <SmtpAddress, SmtpAddress>(0L, "Sucessfully called autodiscover, but did not retrieve a url for {0}/{1}.", user.PrimarySmtpAddress, archiveAddress);
                        }
                    }
                    else
                    {
                        ElcEwsClientHelper.Tracer.TraceError(0L, "Unable to autodiscover EWS endpoint for {0}/{1}, error code: {2}, message {3}.", new object[]
                        {
                            user.PrimarySmtpAddress,
                            archiveAddress,
                            response.ErrorCode,
                            response.ErrorMessage
                        });
                    }
                }
                else
                {
                    ElcEwsClientHelper.Tracer.TraceError <SmtpAddress, SmtpAddress, Exception>(0L, "Unable to autodiscover EWS endpoint for {0}/{1}, exception {2}.", user.PrimarySmtpAddress, archiveAddress, arg);
                }
            }
            finally
            {
                ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Remove(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(ElcEwsClientHelper.CertificateErrorHandler));
            }
            if (!string.IsNullOrEmpty(text))
            {
                result = new Uri(text);
            }
            return(result);
        }