コード例 #1
0
        public static ExportException WaitForAsynchronousTask(Task task)
        {
            ExportException ex = null;

            if (task != null)
            {
                AggregateException ex2 = null;
                try
                {
                    if (task.Wait(3600000))
                    {
                        ex2 = task.Exception;
                        if (ex2 != null)
                        {
                            Tracer.TraceError("AsynchronousTaskHandler.WaitForAsynchronousTask: Exception returned by asynchronous task: {0}", new object[]
                            {
                                ex2
                            });
                        }
                    }
                    else
                    {
                        ex = new ExportException(ExportErrorType.AsynchronousTaskTimeout);
                    }
                }
                catch (AggregateException ex3)
                {
                    ex2 = ex3;
                    Tracer.TraceError("AsynchronousTaskHandler.WaitForAsynchronousTask: Exception caught from asynchronous task: {0}", new object[]
                    {
                        ex3
                    });
                }
                finally
                {
                    if (ex2 != null)
                    {
                        ExportException ex4 = ex2.InnerException as ExportException;
                        ex = (ex4 ?? new ExportException(ExportErrorType.Unknown, ex2.InnerException));
                    }
                    try
                    {
                        task.Dispose();
                    }
                    catch (InvalidOperationException ex5)
                    {
                        Tracer.TraceError("AsynchronousTaskHandler.WaitForAsynchronousTask - Exception disposing task: {0}", new object[]
                        {
                            ex5
                        });
                        if (ex == null)
                        {
                            ex = new ExportException(ExportErrorType.OperationNotSupportedWithCurrentStatus, ex5);
                        }
                    }
                }
            }
            return(ex);
        }
コード例 #2
0
		public void WriteDataBatchItemListGen(object sender, DataBatchEventArgs<ItemListGenerator.ItemIdsDataBatch> args)
		{
			ScenarioData scenarioData = ScenarioData.Current;
			ExportException ex = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);
			this.writingTask = ((ex != null || args.DataBatch == null) ? null : Task.Factory.StartNew(delegate(object dataBatch)
			{
				ScenarioData scenarioData;
				using (new ScenarioData(scenarioData))
				{
					this.WriteDataBatch((ItemListGenerator.ItemIdsDataBatch)dataBatch);
				}
			}, args.DataBatch));
			if (ex != null)
			{
				throw ex;
			}
		}
コード例 #3
0
        private void WriteDataBatch(object sender, DataBatchEventArgs <T> args)
        {
            ScenarioData    scenarioData = ScenarioData.Current;
            ExportException ex           = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);

            this.writingTask = ((ex != null || args.DataBatch == null) ? null : Task.Factory.StartNew(delegate(object dataBatch)
            {
                ScenarioData scenarioData;
                using (new ScenarioData(scenarioData))
                {
                    this.batchDataWriter.WriteDataBatch((T)((object)dataBatch));
                }
            }, args.DataBatch));
            if (ex != null)
            {
                throw ex;
            }
        }
コード例 #4
0
        public void Execute()
        {
            ExportException ex = null;

            try
            {
                this.batchDataReader.StartReading();
            }
            finally
            {
                ex = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);
                this.writingTask = null;
            }
            if (ex != null)
            {
                throw ex;
            }
        }
コード例 #5
0
		public void WriteDataBatchDataRetriever(object sender, DataBatchEventArgs<List<ItemInformation>> args)
		{
			if (this.DataRetriever == null || this.DataRetriever.DataWriter == null)
			{
				return;
			}
			ScenarioData scenarioData = ScenarioData.Current;
			ExportException ex = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);
			this.writingTask = ((ex != null || args.DataBatch == null) ? null : Task.Factory.StartNew(delegate(object dataBatch)
			{
				ScenarioData scenarioData;
				using (new ScenarioData(scenarioData))
				{
					this.DataRetriever.DataWriter.WriteDataBatch((List<ItemInformation>)dataBatch);
				}
			}, args.DataBatch));
			if (ex != null)
			{
				throw ex;
			}
		}
コード例 #6
0
        private void ExportSourceMailbox(IContextualBatchDataWriter <List <ItemInformation> > dataWriter, SourceInformation source, bool isUnsearchable)
        {
            Tracer.TraceInformation("ProgressController.ExportSourceMailbox: Source Id: {0}; isUnsearchable: {1}", new object[]
            {
                source.Configuration.Id,
                isUnsearchable
            });
            this.ItemListGenerator.DoUnSearchable = isUnsearchable;
            bool flag = (!isUnsearchable && source.Status.ItemCount <= 0) || (isUnsearchable && source.Status.UnsearchableItemCount <= 0);

            if ((!isUnsearchable && source.Status.ItemCount > source.Status.ProcessedItemCount) || (isUnsearchable && source.Status.UnsearchableItemCount > source.Status.ProcessedUnsearchableItemCount) || !this.target.ExportContext.IsResume || flag)
            {
                IItemIdList   itemIdList    = this.target.CreateItemIdList(source.Configuration.Id, isUnsearchable);
                DataContext   dataContext   = new DataContext(source, itemIdList);
                DataRetriever dataRetriever = new DataRetriever(dataContext, this);
                dataRetriever.DataWriter              = dataWriter;
                this.ItemListGenerator.DataRetriever  = dataRetriever;
                this.ItemListGenerator.DataBatchRead += this.ItemListGenerator.WriteDataBatchItemListGen;
                dataRetriever.DataBatchRead          += this.ItemListGenerator.WriteDataBatchDataRetriever;
                ExportException ex = null;
                try
                {
                    this.ItemListGenerator.DoExportForSourceMailbox(dataRetriever.DataContext.SourceInformation);
                }
                finally
                {
                    ex = AsynchronousTaskHandler.WaitForAsynchronousTask(this.ItemListGenerator.WritingTask);
                    this.ItemListGenerator.WritingTask   = null;
                    this.ItemListGenerator.DataRetriever = null;
                }
                if (ex != null)
                {
                    throw ex;
                }
            }
        }
コード例 #7
0
        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(ConstantProvider.TotalRetryTimeWindow);

            ScenarioData.Current["BI"] = DateTime.UtcNow.Ticks.ToString();
            Exception threadException;
            Exception ex;
            Exception ex2;

            for (;;)
            {
                ex = null;
                threadException = null;
                ex2             = null;
                bool flag  = false;
                bool flag2 = false;
                bool flag3 = false;
                ScenarioData.Current["R"]  = num.ToString();
                ScenarioData.Current["RT"] = DateTime.UtcNow.Ticks.ToString();
                if (this.ServiceBinding != null)
                {
                    ServiceBindingType serviceBinding = this.ServiceBinding;
                    serviceBinding.UserAgent = ScenarioData.Current.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("BaseServiceClient.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("BaseServiceClient.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);
                        if (!flag)
                        {
                            flag = this.Rebind();
                        }
                        Tracer.TraceError("BaseServiceClient.InternalCallService: Connect failure. Retry: {0}.", new object[]
                        {
                            flag
                        });
                    }
                    else if (ex5.Status == WebExceptionStatus.NameResolutionFailure)
                    {
                        Tracer.TraceError("BaseServiceClient.InternalCallService: DNS look up failure. No retry.", new object[0]);
                        flag = this.Rebind();
                    }
                    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("BaseServiceClient.InternalCallService: HTTP 401 unauthorized", new object[0]);
                                        flag  = false;
                                        flag3 = true;
                                        ex    = new ExportException(ExportErrorType.Unauthorized, ex5);
                                        goto IL_342;
                                    }
                                    goto IL_342;
                                }
                                break;
                            }
                            string text = httpWebResponse.Headers[HttpResponseHeader.Location];
                            Tracer.TraceInformation("BaseServiceClient.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("BaseServiceClient.InternalCallService: Resetting retry during HTTP redirection.", new object[0]);
                                }
                            }
                        }
                    }
                    IL_342 :;
                }
                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)
                        {
                            if (BaseServiceClient <ServiceBindingType, FunctionalInterfaceType> .IsRebindableError(ex7.Code.Name))
                            {
                                flag = this.Rebind();
                            }
                            if (BaseServiceClient <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("BaseServiceClient.InternalCallService: Exception handler is handling exception : {0}", new object[]
                        {
                            ex
                        });
                        ex2 = exceptionHandler(ex);
                        Tracer.TraceError("BaseServiceClient.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("BaseServiceClient.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("BaseServiceClient.InternalCallService: Unauthorized", new object[0]);
                    if (authorizationHandler == null || !authorizationHandler())
                    {
                        goto IL_4CB;
                    }
                    flag = true;
                }
                if (flag2)
                {
                    num = 0;
                }
                else
                {
                    num++;
                }
                if (!flag || !(t > DateTime.UtcNow))
                {
                    goto IL_4EC;
                }
            }
Block_8:
            throw new ExportException(ExportErrorType.StopRequested);
IL_4CB:
            throw ex;
IL_4EC:
            if (ScenarioData.Current.ContainsKey("BI"))
            {
                ScenarioData.Current.Remove("BI");
            }
            if (ex2 != null)
            {
                Tracer.TraceError("BaseServiceClient.InternalCallService: Exception thrown after all possible actions: {0}", new object[]
                {
                    ex2
                });
                throw ex2;
            }
        }
コード例 #8
0
		public void DoExportForSourceMailbox(SourceInformation sourceMailbox)
		{
			Tracer.TraceInformation("ItemListGenerator.DoExportForSourceMailbox: Generating item list for mailbox '{0}'", new object[]
			{
				sourceMailbox.Configuration.Id
			});
			ErrorRecord errorRecord = null;
			sourceMailbox.Configuration.Id.StartsWith("\\");
			ScenarioData.Current["PM"] = sourceMailbox.Configuration.LegacyExchangeDN.GetHashCode().ToString();
			if (sourceMailbox.Status.ItemCount < 0)
			{
				sourceMailbox.Status.ItemCount = 0;
			}
			if (sourceMailbox.Status.UnsearchableItemCount < 0)
			{
				sourceMailbox.Status.UnsearchableItemCount = 0;
			}
			try
			{
				bool flag = this.target.ExportContext.ExportMetadata.IncludeSearchableItems && !this.DoUnSearchable;
				bool flag2 = this.target.ExportContext.ExportMetadata.IncludeUnsearchableItems && this.DoUnSearchable;
				bool flag3 = false;
				Dictionary<string, string> dictionary = null;
				dictionary = ItemListGenerator.PrepareAllFolders(sourceMailbox.ServiceClient, sourceMailbox.Configuration.Id);
				if (flag)
				{
					bool errorHappened = false;
					try
					{
						bool flag4 = false;
						Tracer.TraceInformation("ItemListGenerator.GenerateItemListForSourceMailbox: call GetAllItemIdsFromServer for primary for mailbox: '{0}'", new object[]
						{
							sourceMailbox.Configuration.Id
						});
						this.GetAllItemIdsFromServer<ItemId>(sourceMailbox, new ItemListGenerator.GetItemIdPageFromServerDelegate<ItemId>(this.GetItemIdPageFromServer), dictionary, !flag, false, ref flag4, out flag3);
						if (dictionary != null && dictionary.Values.Contains("\\archive"))
						{
							Tracer.TraceInformation("ItemListGenerator.GenerateItemListForSourceMailbox: call GetAllItemIdsFromServer for archive for mailbox: '{0}'", new object[]
							{
								sourceMailbox.Configuration.Id
							});
							this.GetAllItemIdsFromServer<ItemId>(sourceMailbox, new ItemListGenerator.GetItemIdPageFromServerDelegate<ItemId>(this.GetItemIdPageFromServer), dictionary, !flag, true, ref flag4, out flag3);
						}
						ExportException ex = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);
						if (ex != null)
						{
							errorHappened = true;
							throw ex;
						}
					}
					finally
					{
						this.DataRetriever.DataWriter.ExitDataContext(errorHappened);
					}
				}
				bool isUnsearchable = true;
				if (flag2)
				{
					bool errorHappened2 = false;
					try
					{
						bool flag5 = false;
						Tracer.TraceInformation("ItemListGenerator.GenerateItemListForSourceMailbox: call GetAllItemIdsFromServer isunsearchable for primary for mailbox: '{0}'", new object[]
						{
							sourceMailbox.Configuration.Id
						});
						this.GetAllItemIdsFromServer<ItemId>(sourceMailbox, new ItemListGenerator.GetItemIdPageFromServerDelegate<ItemId>(this.GetItemIdPageFromServer), dictionary, isUnsearchable, false, ref flag5, out flag3);
						if (!flag3)
						{
							Tracer.TraceInformation("ItemListGenerator.GenerateItemListForSourceMailbox: call GetAllItemIdsFromServer isunsearchable for newschemafailed for mailbox: '{0}'", new object[]
							{
								sourceMailbox.Configuration.Id
							});
							this.GetAllItemIdsFromServer<UnsearchableItemId>(sourceMailbox, new ItemListGenerator.GetItemIdPageFromServerDelegate<UnsearchableItemId>(this.GetUnsearchableItemIdPageFromServer), dictionary, isUnsearchable, false, ref flag5, out flag3);
						}
						else if (dictionary != null && dictionary.Values.Contains("\\archive"))
						{
							Tracer.TraceInformation("ItemListGenerator.GenerateItemListForSourceMailbox: call GetAllItemIdsFromServer isunsearchable for archive for mailbox: '{0}'", new object[]
							{
								sourceMailbox.Configuration.Id
							});
							this.GetAllItemIdsFromServer<ItemId>(sourceMailbox, new ItemListGenerator.GetItemIdPageFromServerDelegate<ItemId>(this.GetItemIdPageFromServer), dictionary, isUnsearchable, true, ref flag5, out flag3);
						}
						ExportException ex2 = AsynchronousTaskHandler.WaitForAsynchronousTask(this.writingTask);
						if (ex2 != null)
						{
							errorHappened2 = true;
							throw ex2;
						}
					}
					finally
					{
						this.DataRetriever.DataWriter.ExitDataContext(errorHappened2);
					}
				}
			}
			catch (ExportException ex3)
			{
				Tracer.TraceInformation("ItemListGenerator.DoExportForSourceMailbox: Error for mailbox '{0}'. Exception: {1}", new object[]
				{
					sourceMailbox.Configuration.Id,
					ex3
				});
				errorRecord = new ErrorRecord
				{
					SourceId = sourceMailbox.Configuration.Id,
					Item = null,
					ErrorType = ex3.ErrorType,
					DiagnosticMessage = ex3.Message,
					Time = DateTime.UtcNow
				};
			}
			if (ScenarioData.Current.ContainsKey("PM"))
			{
				ScenarioData.Current.Remove("PM");
			}
			if (errorRecord != null)
			{
				this.AbortForSourceMailbox(errorRecord);
			}
		}