Exemplo n.º 1
0
 private void UpdateSyncMetadataOnSyncFailure()
 {
     try
     {
         ExDateTime?   exDateTime    = this.GetSyncMetadataValue("LastSuccessfulSyncTime") as ExDateTime?;
         ExDateTime?   exDateTime2   = this.GetSyncMetadataValue("FirstAttemptedSyncTime") as ExDateTime?;
         ExDateTime?   exDateTime3   = this.GetSyncMetadataValue("LastFailedSyncEmailTime") as ExDateTime?;
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.AppendLine(ProtocolLog.GetExceptionLogString(this.LastError));
         if (this.LastError is SharePointException)
         {
             stringBuilder.AppendLine("SharePointException Diagnostic Info:");
             stringBuilder.AppendLine(((SharePointException)this.LastError).DiagnosticInfo);
         }
         this.SetSyncMetadataValue("LastSyncFailure", stringBuilder.ToString());
         this.SetSyncMetadataValue("LastFailedSyncTime", ExDateTime.UtcNow);
         ExDateTime?exDateTime4 = exDateTime ?? exDateTime2;
         if ((exDateTime3 == null || ExDateTime.UtcNow - exDateTime3 > TimeSpan.FromHours(24.0)) && exDateTime4 != null && ExDateTime.UtcNow - exDateTime4 > TimeSpan.FromHours(12.0))
         {
             StoreObjectId destFolderId = Utils.EnsureSyncIssueFolder(this.mailboxSession);
             using (MessageItem messageItem = MessageItem.Create(this.mailboxSession, destFolderId))
             {
                 LocalizedString empty = LocalizedString.Empty;
                 messageItem.From    = new Participant(this.Job.SyncInfoEntry.MailboxPrincipal);
                 messageItem.Subject = this.GetSyncIssueEmailErrorString(this.LastError.Message, out empty);
                 using (TextWriter textWriter = messageItem.Body.OpenTextWriter(BodyFormat.TextHtml))
                 {
                     messageItem.Body.Reset();
                     using (HtmlWriter htmlWriter = new HtmlWriter(textWriter))
                     {
                         htmlWriter.WriteStartTag(HtmlTagId.P);
                         htmlWriter.WriteText(empty);
                         htmlWriter.WriteEndTag(HtmlTagId.P);
                     }
                 }
                 messageItem.IsDraft = false;
                 messageItem.MarkAsUnread(true);
                 messageItem.Save(SaveMode.NoConflictResolutionForceSave);
                 this.SetSyncMetadataValue("LastFailedSyncEmailTime", ExDateTime.UtcNow);
             }
         }
     }
     catch (StorageTransientException exception)
     {
         ProtocolLog.LogError(this.loggingComponent, this.loggingContext, "UpdateSyncMetadataOnSyncFailure: Failed with StorageTransientException", exception);
     }
     catch (StoragePermanentException exception2)
     {
         ProtocolLog.LogError(this.loggingComponent, this.loggingContext, "UpdateSyncMetadataOnSyncFailure: Failed with StoragePermanentException", exception2);
     }
 }