private bool ShouldSyncMailbox() { bool result; try { ExchangePrincipal exchangePrincipal; if (!PublicFolderSession.TryGetPublicFolderMailboxPrincipal(this.OrganizationId, this.ContentMailboxGuid, false, out exchangePrincipal) || exchangePrincipal == null) { PublicFolderSynchronizerLogger.LogOnServer(string.Format("Sync Cancelled for Mailbox {0} in Organization {1}. Could not get ExchangePrincipal. Mailbox could have been deleted.", this.ContentMailboxGuid, this.OrganizationId), LogEventType.Warning, null); result = false; } else if (!exchangePrincipal.MailboxInfo.IsRemote && LocalServerCache.LocalServer != null && exchangePrincipal.MailboxInfo.Location.ServerFqdn != LocalServerCache.LocalServer.Fqdn) { PublicFolderSynchronizerLogger.LogOnServer(string.Format("Sync Cancelled for Mailbox {0} in Organization {1}. Mailbox was moved to Server {2}.", this.ContentMailboxGuid, this.OrganizationId, exchangePrincipal.MailboxInfo.Location.ServerFqdn), LogEventType.Warning, null); result = false; } else { result = true; } } catch (LocalizedException e) { PublicFolderSynchronizerLogger.LogOnServer(string.Format("Sync Cancelled for Mailbox {0} in Organization {1}. Could not get ExchangePrincipal. Mailbox could have been deleted/relocated. Exception - {2}", this.ContentMailboxGuid, this.OrganizationId, PublicFolderMailboxLoggerBase.GetExceptionLogString(e, PublicFolderMailboxLoggerBase.ExceptionLogOption.All)), LogEventType.Warning, null); result = false; } return(result); }
private bool ExecuteWithinBudget() { if (this.budget == null) { PublicFolderSynchronizer.Tracer.TraceDebug((long)this.GetHashCode(), "Acquiring budget"); this.budget = StandardBudget.Acquire(PublicFolderSynchronizer.BudgetKey); } else { PublicFolderSynchronizer.Tracer.TraceDebug((long)this.GetHashCode(), "Resetting budget"); this.budget.ResetWorkAccomplished(); } TimeSpan timeSpan; for (;;) { PublicFolderSynchronizer.< > c__DisplayClass11 CS$ < > 8__locals1 = new PublicFolderSynchronizer.< > c__DisplayClass11(); CS$ < > 8__locals1.< > 4__this = this; timeSpan = TimeSpan.Zero; CS$ < > 8__locals1.moreBatchesToProcess = false; bool flag = this.transientExceptionHandler.TryExecute(new TryDelegate(CS$ < > 8__locals1, (UIntPtr)ldftn(< ExecuteWithinBudget > b__10))); if (flag) { PublicFolderSynchronizer.Tracer.TraceDebug((long)this.GetHashCode(), "Batch executed successfully"); if (!CS$ < > 8__locals1.moreBatchesToProcess) { break; } } else { PublicFolderSynchronizer.Tracer.TraceDebug((long)this.GetHashCode(), "Batch failed execution. Calculating Delays."); int num = Math.Min(this.transientExceptionHandler.TransientExceptionCount, PublicFolderSynchronizer.FibonacciSequence.Length) - 1; timeSpan = TimeSpan.FromMinutes((double)PublicFolderSynchronizer.FibonacciSequence[num]); } TimeSpan resourceMonitorDelay = this.GetResourceMonitorDelay(); if (resourceMonitorDelay > timeSpan) { timeSpan = resourceMonitorDelay; } if (timeSpan > TimeSpan.Zero) { goto Block_5; } } PublicFolderSynchronizer.Tracer.TraceDebug((long)this.GetHashCode(), "No more batches to process, exiting"); return(true); Block_5: PublicFolderSynchronizerLogger.LogOnServer("Delay=" + timeSpan.TotalMilliseconds, LogEventType.Verbose, new Guid?(this.syncContext.CorrelationId)); if (this.timer == null) { this.timer = new Timer(new TimerCallback(this.TimerExecute)); } PublicFolderSynchronizer.Tracer.TraceDebug <TimeSpan>((long)this.GetHashCode(), "Setting timer to wake up in: {0}", timeSpan); this.timer.Change(timeSpan, TimeSpan.Zero); return(false); }
public void WriteActivitiesCountersToLog() { StringBuilder stringBuilder = new StringBuilder(1000); foreach (PublicFolderActivityPerformanceTracker publicFolderActivityPerformanceTracker in this.performanceTrackers.Values) { stringBuilder.AppendFormat("Batch={0};", this.batchNumber); publicFolderActivityPerformanceTracker.AppendLogData(stringBuilder); PublicFolderSynchronizerLogger.LogOnServer(stringBuilder.ToString(), LogEventType.PerfCounters, this.CorrelationId); stringBuilder.Clear(); } }
private void ReportSynchronizerResult(Exception exception, bool complete) { try { GrayException.MapAndReportGrayExceptions(delegate() { try { if (exception != null) { this.syncContext.Logger.LogEvent(LogEventType.Error, "Failed: " + exception); if (this.syncExecutor != null) { this.syncExecutor.HandleException(exception); } } else if (complete) { this.syncContext.Logger.LogEvent(LogEventType.Verbose, "Completed"); } } catch (StorageTransientException arg2) { PublicFolderSynchronizer.Tracer.TraceError <StorageTransientException>((long)this.GetHashCode(), "Writing batch result to the mailbox log failed with exception: {0}", arg2); PublicFolderSynchronizerLogger.LogOnServer(string.Format("Exception while writing batch result to log. Exception: {0}", arg2), LogEventType.Warning, new Guid?(this.syncContext.CorrelationId)); } catch (StoragePermanentException arg3) { PublicFolderSynchronizer.Tracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "Writing batch result to the mailbox log failed with exception: {0}", arg3); PublicFolderSynchronizerLogger.LogOnServer(string.Format("Exception while writing batch result to log. Exception: {0}", arg3), LogEventType.Warning, new Guid?(this.syncContext.CorrelationId)); } }); } catch (GrayException arg) { PublicFolderSynchronizer.Tracer.TraceError <GrayException>((long)this.GetHashCode(), "Unable to handle completion of the : {0}", arg); } }
private TimeSpan GetResourceMonitorDelay() { DelayInfo delay = ResourceLoadDelayInfo.GetDelay(this.budget, PublicFolderSynchronizer.WorkloadSettings, this.resourcesToAccess, true); if (delay != null) { PublicFolderSynchronizer.Tracer.TraceDebug <TimeSpan>((long)this.GetHashCode(), "Resource load provided delay info: {0}", delay.Delay); if (delay.Delay > this.maximumAllowedDelay) { string text = string.Format("Delay suggested by ResourceMonitor of {0} ms has exceeded the maximum allowed delay of {1} ms", delay.Delay.TotalMilliseconds, this.maximumAllowedDelay.TotalMilliseconds); if (this.syncContext.IsHierarchyReady) { throw new StorageTransientException(new LocalizedString(text)); } PublicFolderSynchronizerLogger.LogOnServer(text, LogEventType.Warning, new Guid?(this.syncContext.CorrelationId)); return(this.maximumAllowedDelay); } } if (delay == null) { return(TimeSpan.Zero); } return(delay.Delay); }