예제 #1
0
 void exporter_OnError(ExportException e)
 {
     InvokeIfRequired(() =>
     {
         log.AppendText(string.Format(Program.LanguageManager.GetString(StringResources.Export_Error), DateTime.Now.ToString(), e.Message) + "\n");
         if (e.InnerException != null && e.InnerException.StackTrace != null)
         {
             log.AppendText(e.InnerException.StackTrace.ToString() + "\n");
         }
     });
 }
예제 #2
0
 public void Start()
 {
     ExWatson.SendReportOnUnhandledException(delegate()
     {
         int mailboxesSearchedCount = 0;
         long itemCount             = 0L;
         long totalSize             = 0L;
         long unsearchableItemCount = 0L;
         long unsearchableTotalSize = 0L;
         List <ErrorRecord> unsearchableFailedMailboxes = null;
         List <ErrorRecord> failedMailboxes             = null;
         List <KeywordHit> keywordHits = null;
         SearchState searchState       = SearchState.NotStarted;
         Exception exception           = null;
         try
         {
             GrayException.MapAndReportGrayExceptions(delegate()
             {
                 try
                 {
                     if (this.searchObject != null)
                     {
                         this.searchObject.ScenarioId = ScenarioData.Current["SID"];
                     }
                     if (this.isStatisticsOnlySearch)
                     {
                         if (string.IsNullOrEmpty(this.keywordStatisticsQuery))
                         {
                             ScenarioData.Current["S"] = "ES";
                             if (this.searchObject != null && !string.IsNullOrEmpty(this.searchObject.CalculatedQuery))
                             {
                                 ScenarioData.Current["QL"] = this.searchObject.CalculatedQuery.Length.ToString();
                             }
                         }
                         else
                         {
                             ScenarioData.Current["S"]  = "KS";
                             ScenarioData.Current["QL"] = this.keywordStatisticsQuery.Length.ToString();
                         }
                         string text        = (this.searchObject == null) ? string.Empty : this.searchObject.CalculatedQuery;
                         List <string> list = null;
                         if (this.ExportContext.Sources != null && this.ExportContext.Sources.Count > 0)
                         {
                             ScenarioData.Current["M"] = this.ExportContext.Sources.Count.ToString();
                             ISource source            = this.ExportContext.Sources[0];
                             if (string.IsNullOrEmpty(text))
                             {
                                 text = source.SourceFilter;
                             }
                             list = new List <string>(this.ExportContext.Sources.Count);
                             foreach (ISource source2 in this.ExportContext.Sources)
                             {
                                 list.Add(source2.LegacyExchangeDN);
                             }
                         }
                         if (list != null || this.isPFSearchFlightingEnabled)
                         {
                             bool flag = false;
                             this.GetSearchResultEstimation(text, list, out mailboxesSearchedCount, false, ref flag, out itemCount, out totalSize, out failedMailboxes);
                         }
                         if (!string.IsNullOrEmpty(this.keywordStatisticsQuery) && !this.isTaskAborted)
                         {
                             List <ErrorRecord> list2 = null;
                             List <KeywordStatisticsSearchResultType> keywordStatistics = this.ewsClient.GetKeywordStatistics(this.executingUserPrimarySmtpAddress, this.keywordStatisticsQuery, this.ExportContext.ExportMetadata.Language, (list != null) ? list : new List <string>(1), out list2, (this.searchObject == null || !this.isPFSearchFlightingEnabled) ? null : this.searchObject.Name);
                             keywordHits = Util.ConvertToKeywordHitList(keywordStatistics, this.userKeywordsMap);
                             if (list2 != null)
                             {
                                 if (failedMailboxes == null)
                                 {
                                     failedMailboxes = list2;
                                 }
                                 else
                                 {
                                     failedMailboxes.AddRange(list2);
                                 }
                             }
                         }
                         if (Util.IncludeUnsearchableItems(this.ExportContext) && !this.isTaskAborted && (list != null || (this.searchObject != null && this.searchObject.IsFeatureFlighted("PublicFolderSearchFlighted"))))
                         {
                             KeywordHit keywordHit = null;
                             if (keywordHits != null)
                             {
                                 keywordHit = new KeywordHit
                                 {
                                     Phrase = "652beee2-75f7-4ca0-8a02-0698a3919cb9"
                                 };
                                 keywordHits.Add(keywordHit);
                             }
                             bool flag2 = false;
                             if (this.searchObject != null && this.searchObject.IsFeatureFlighted("PublicFolderSearchFlighted"))
                             {
                                 this.GetSearchResultEstimation(text, list, out mailboxesSearchedCount, true, ref flag2, out unsearchableItemCount, out unsearchableTotalSize, out unsearchableFailedMailboxes);
                                 if (flag2 && keywordHit != null)
                                 {
                                     keywordHit.Count += (int)unsearchableItemCount;
                                 }
                             }
                             else
                             {
                                 foreach (string mailboxId in list)
                                 {
                                     if (this.isTaskAborted)
                                     {
                                         break;
                                     }
                                     long unsearchableItemStatistics = this.ewsClient.GetUnsearchableItemStatistics(this.executingUserPrimarySmtpAddress, mailboxId);
                                     unsearchableItemCount          += unsearchableItemStatistics;
                                     if (keywordHit != null)
                                     {
                                         keywordHit.Count        += (int)unsearchableItemStatistics;
                                         keywordHit.MailboxCount += ((unsearchableItemStatistics == 0L) ? 0 : 1);
                                     }
                                 }
                             }
                         }
                         searchState = (this.isTaskAborted ? SearchState.EstimateStopped : SearchState.EstimateSucceeded);
                     }
                     else
                     {
                         ScenarioData.Current["S"] = "CS";
                         this.exportHandler.Prepare();
                         this.exportHandler.Export();
                         this.PrepareCompleted(this.exportHandler.SearchResults);
                         searchState = (this.isTaskAborted ? SearchState.Stopped : SearchState.Succeeded);
                     }
                 }
                 catch (ExportException exception)
                 {
                     ExportException exception = exception;
                 }
                 catch (StorageTransientException exception2)
                 {
                     ExportException exception = exception2;
                 }
                 catch (StoragePermanentException exception3)
                 {
                     ExportException exception = exception3;
                 }
                 catch (DataSourceOperationException exception4)
                 {
                     ExportException exception = exception4;
                 }
             });
         }
         catch (GrayException ex)
         {
             exception = ex;
             ExTraceGlobals.SearchTracer.TraceError <GrayException>((long)this.GetHashCode(), "GrayException {0} is thrown", ex);
         }
         finally
         {
             if (exception != null)
             {
                 string message = exception.Message;
                 if (string.IsNullOrEmpty(message) && exception.InnerException != null)
                 {
                     message = exception.InnerException.Message;
                 }
                 SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, exception);
                 this.Errors.Add(message);
                 mailboxesSearchedCount = 0;
                 itemCount             = 0L;
                 totalSize             = 0L;
                 unsearchableItemCount = 0L;
                 keywordHits           = null;
                 searchState           = (this.isStatisticsOnlySearch ? SearchState.EstimateFailed : SearchState.Failed);
             }
             if (failedMailboxes != null && failedMailboxes.Count > 0)
             {
                 foreach (ErrorRecord errorRecord in failedMailboxes)
                 {
                     this.Errors.Add(Util.GenerateErrorMessageFromErrorRecord(errorRecord));
                 }
                 this.Errors.Insert(0, "Number of failed mailboxes: " + failedMailboxes.Count);
             }
             try
             {
                 if (this.isStatisticsOnlySearch)
                 {
                     this.EstimateCompleted(mailboxesSearchedCount, itemCount, totalSize, unsearchableItemCount, keywordHits, searchState);
                 }
                 else
                 {
                     this.ExportCompleted(searchState);
                 }
             }
             catch (ExportException ex2)
             {
                 SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, ex2);
                 this.Errors.Add(ex2.Message);
                 searchState = (this.isStatisticsOnlySearch ? SearchState.EstimateFailed : SearchState.Failed);
             }
         }
     }, delegate(object exception)
     {
         ExTraceGlobals.SearchTracer.TraceError((long)this.GetHashCode(), "InternalStart: Unhandled exception {0}", new object[]
         {
             exception
         });
         SearchEventLogger.Instance.LogDiscoverySearchTaskErrorEvent(this.ExportContext.ExportMetadata.ExportName, this.DiscoverySearchTaskErrorHint, exception.ToString());
         return(!(exception is GrayException));
     });
 }
예제 #3
0
        private static void Export(Opts opts)
        {
            Result <ExportManager> managerResult;

            if (opts.Archive)
            {
                if (opts.Test)
                {
                    return;
                }
                managerResult = opts.ExportRelto.HasValue
                    ? ExportManager.CreateArchiveExportManagerAsync(opts.DekiApi, opts.ExportDocument, opts.ExportRelto.Value, opts.FilePath, new Result <ExportManager>())
                    : ExportManager.CreateArchiveExportManagerAsync(opts.DekiApi, opts.ExportDocument, opts.ExportReltoPath, opts.FilePath, new Result <ExportManager>());
            }
            else
            {
                if (!Directory.Exists(opts.FilePath))
                {
                    try {
                        Directory.CreateDirectory(opts.FilePath);
                    } catch (Exception e) {
                        throw new ConfigurationException(string.Format("Unable to create '{0}': {1}", opts.FilePath, e.Message), e);
                    }
                }
                if (opts.Test)
                {
                    return;
                }
                managerResult = opts.ExportRelto.HasValue
                    ? ExportManager.CreateFileExportManagerAsync(opts.DekiApi, opts.ExportDocument, opts.ExportRelto.Value, opts.FilePath, new Result <ExportManager>())
                    : ExportManager.CreateFileExportManagerAsync(opts.DekiApi, opts.ExportDocument, opts.ExportReltoPath, opts.FilePath, new Result <ExportManager>());
            }
            managerResult.Block();
            if (managerResult.HasException)
            {
                throw new Exception(string.Format("Export failed: {0}", managerResult.Exception.Message), managerResult.Exception);
            }
            ExportManager manager = managerResult.Value;

            manager.MaxRetries = opts.Retries;
            Result result    = manager.ExportAsync(manifest => FixupManifest(manifest, opts), new Result());
            int    completed = 0;

            Console.WriteLine("Exporting: {0}", opts.FilePath);
            if (manager.TotalItems == 0)
            {
                throw new Exception("nothing to export");
            }
            while (!result.HasFinished)
            {
                Thread.Sleep(200);
                if (manager.CompletedItems <= completed)
                {
                    continue;
                }
                if (SysUtil.IsUnix)
                {
                    Console.WriteLine("  {0} of {1} files ({2:0}%)", manager.CompletedItems, manager.TotalItems, 100.0 * manager.CompletedItems / manager.TotalItems);
                }
                else
                {
                    Console.Write("  {0} of {1} files ({2:0}%)      \r", manager.CompletedItems, manager.TotalItems, 100.0 * manager.CompletedItems / manager.TotalItems);
                }
                completed = manager.CompletedItems;
            }
            if (!SysUtil.IsUnix)
            {
                Console.WriteLine();
            }
            if (result.HasException)
            {
                ExportException exportException = result.Exception as ExportException;
                if (exportException != null)
                {
                    Console.WriteLine("Export failed on Item:\r\n{0}", exportException.ManifestItem.ToPrettyString());
                }
                throw new Exception(string.Format("Export failed: {0}", result.Exception.Message), result.Exception);
            }
        }
예제 #4
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;
            }
        }