public static void RemoveNotification(OrganizationId organizationId, string id, bool throwOnError)
 {
     if (AsyncOperationNotificationDataProvider.IsAsyncNotificationDisabled())
     {
         ExTraceGlobals.StorageTracer.TraceWarning(0L, "DisableAsyncNotification is set in registry, no notification will be removed.");
         return;
     }
     try
     {
         AsyncOperationNotificationDataProvider asyncOperationNotificationDataProvider = new AsyncOperationNotificationDataProvider(organizationId);
         AsyncOperationNotification             asyncOperationNotification             = asyncOperationNotificationDataProvider.FindByAlternativeId <AsyncOperationNotification>(id);
         if (asyncOperationNotification != null)
         {
             asyncOperationNotificationDataProvider.Delete(asyncOperationNotification);
         }
         else
         {
             ExTraceGlobals.StorageTracer.TraceError <OrganizationId, string>(0L, "AsyncOperationNotificationDataProvider::RemoveNotification failed: Notification object {0}\\{1} can't be found.", organizationId, id);
         }
     }
     catch (Exception ex)
     {
         string printableId = AsyncOperationNotificationDataProvider.GetPrintableId(organizationId, id);
         ExTraceGlobals.StorageTracer.TraceError <string, string>(0L, "AsyncOperationNotificationDataProvider::RemoveNotification failed: {0}, message: {1}", printableId, ex.Message);
         StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_ErrorRemoveNotification, printableId, new object[]
         {
             printableId,
             ex
         });
         if (throwOnError)
         {
             throw;
         }
     }
 }
        public static void SendNotificationEmail(OrganizationId organizationId, string id, bool forceSendCreatedMail, IEnumerable <LocalizedString> report, bool throwOnError)
        {
            if (AsyncOperationNotificationDataProvider.IsAsyncNotificationDisabled())
            {
                ExTraceGlobals.StorageTracer.TraceWarning(0L, "DisableAsyncNotification is set in registry, no notification email will be sent.");
                return;
            }
            AsyncOperationNotificationDataProvider asyncOperationNotificationDataProvider = new AsyncOperationNotificationDataProvider(organizationId);
            bool flag = false;

            if (asyncOperationNotificationDataProvider.Cache.BadItems.TryGetValue(id, out flag))
            {
                return;
            }
            AsyncOperationNotification asyncOperationNotification = asyncOperationNotificationDataProvider.FindByAlternativeId <AsyncOperationNotification>(id);

            if (asyncOperationNotification != null)
            {
                asyncOperationNotificationDataProvider.SendNotificationEmail(asyncOperationNotification, forceSendCreatedMail, report, throwOnError);
            }
        }
 public static void UpdateNotification(OrganizationId organizationId, string id, AsyncOperationStatus?status, int?percentComplete, LocalizedString?message, bool throwOnError = false, IEnumerable <KeyValuePair <string, LocalizedString> > extendedAttributes = null)
 {
     if (AsyncOperationNotificationDataProvider.IsAsyncNotificationDisabled())
     {
         ExTraceGlobals.StorageTracer.TraceWarning(0L, "DisableAsyncNotification is set in registry, no notification will be updated.");
         return;
     }
     if (status == null && percentComplete == null && message == null)
     {
         if (extendedAttributes == null)
         {
             return;
         }
     }
     try
     {
         AsyncOperationNotificationDataProvider asyncOperationNotificationDataProvider = new AsyncOperationNotificationDataProvider(organizationId);
         asyncOperationNotificationDataProvider.CanRetry = false;
         if (asyncOperationNotificationDataProvider.IsUpdateRequired(id, status, percentComplete, message) || extendedAttributes != null)
         {
             bool flag = false;
             if (!asyncOperationNotificationDataProvider.Cache.BadItems.TryGetValue(id, out flag))
             {
                 AsyncOperationNotification asyncOperationNotification = asyncOperationNotificationDataProvider.FindByAlternativeId <AsyncOperationNotification>(id);
                 if (asyncOperationNotification != null)
                 {
                     if (status != null)
                     {
                         asyncOperationNotification.Status = status.Value;
                         if (status == AsyncOperationStatus.Completed)
                         {
                             percentComplete = new int?(100);
                         }
                     }
                     else if (asyncOperationNotification.Status == AsyncOperationStatus.Queued)
                     {
                         asyncOperationNotification.Status = AsyncOperationStatus.InProgress;
                     }
                     if (percentComplete != null)
                     {
                         asyncOperationNotification.PercentComplete = new int?(percentComplete.Value);
                     }
                     if (message != null)
                     {
                         asyncOperationNotification.Message = message.Value;
                     }
                     if (extendedAttributes != null)
                     {
                         Dictionary <string, LocalizedString> dictionary = asyncOperationNotification.ExtendedAttributes.ToDictionary((KeyValuePair <string, LocalizedString> x) => x.Key, (KeyValuePair <string, LocalizedString> x) => x.Value);
                         foreach (KeyValuePair <string, LocalizedString> keyValuePair in extendedAttributes)
                         {
                             dictionary[keyValuePair.Key] = keyValuePair.Value;
                         }
                         asyncOperationNotification.ExtendedAttributes = dictionary.ToArray <KeyValuePair <string, LocalizedString> >();
                     }
                     asyncOperationNotificationDataProvider.Save(asyncOperationNotification);
                 }
                 else
                 {
                     ExTraceGlobals.StorageTracer.TraceError <string>(0L, "AsyncOperationNotificationDataProvider::UpdateNotification failed: Notification object '{0}' can't be found.", AsyncOperationNotificationDataProvider.GetPrintableId(organizationId, id));
                     asyncOperationNotificationDataProvider.Cache.BadItems.Add(id, true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         string printableId = AsyncOperationNotificationDataProvider.GetPrintableId(organizationId, id);
         ExTraceGlobals.StorageTracer.TraceError <string, string>(0L, "AsyncOperationNotificationDataProvider::UpdateNotification failed: Notification object: {0}, message: {1}", printableId, ex.Message);
         StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_ErrorUpdateNotification, printableId, new object[]
         {
             printableId,
             ex
         });
         if (throwOnError)
         {
             throw;
         }
     }
 }
 public void SendNotificationEmail(AsyncOperationNotification notification, bool forceSendCreatedMail, IEnumerable <LocalizedString> report, bool throwOnError)
 {
     if (AsyncOperationNotificationDataProvider.IsAsyncNotificationDisabled())
     {
         ExTraceGlobals.StorageTracer.TraceWarning(0L, "DisableAsyncNotification is set in registry, no notification email will be sent.");
         return;
     }
     if (notification == null)
     {
         throw new ArgumentNullException("notification");
     }
     try
     {
         AsyncOperationNotificationEmail asyncOperationNotificationEmail = new AsyncOperationNotificationEmail(this, notification, forceSendCreatedMail);
         string alternativeId;
         if (AsyncOperationNotificationDataProvider.SettingsObjectIdentityMap.TryGetValue(notification.Type, out alternativeId))
         {
             AsyncOperationNotification asyncOperationNotification = this.FindByAlternativeId <AsyncOperationNotification>(alternativeId);
             if (asyncOperationNotification != null)
             {
                 asyncOperationNotificationEmail.AppendRecipients(asyncOperationNotification.NotificationEmails);
             }
         }
         if (asyncOperationNotificationEmail.ToRecipients.Count <EmailAddress>() > 0)
         {
             if (report != null)
             {
                 StringBuilder stringBuilder = new StringBuilder();
                 foreach (LocalizedString value in report)
                 {
                     stringBuilder.AppendLine(value);
                 }
                 string s     = stringBuilder.ToString();
                 byte[] bytes = Encoding.Default.GetBytes(s);
                 asyncOperationNotificationEmail.Attachments.AddFileAttachment("Report.txt", bytes);
             }
             int  num = 0;
             bool flag;
             do
             {
                 flag = asyncOperationNotificationEmail.Send();
                 num++;
             }while (!flag && base.CanRetry && num < 3);
             if (forceSendCreatedMail && (notification.Status == AsyncOperationStatus.Completed || notification.Status == AsyncOperationStatus.Failed))
             {
                 this.SendNotificationEmail(notification, false, report, throwOnError);
             }
         }
     }
     catch (Exception ex)
     {
         string printableId = AsyncOperationNotificationDataProvider.GetPrintableId(base.Mailbox.MailboxInfo.OrganizationId, notification.AlternativeId);
         ExTraceGlobals.StorageTracer.TraceError <string, string>(0L, "AsyncOperationNotificationDataProvider::SendNotificationEmail failed: {0}, message: {1}", printableId, ex.Message);
         StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_ErrorSendNotificationEmail, printableId, new object[]
         {
             printableId,
             ex
         });
         if (throwOnError)
         {
             throw;
         }
     }
 }
        public AsyncOperationNotificationEmail(AsyncOperationNotificationDataProvider provider, AsyncOperationNotification notification, bool forceSendCreatedMail)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }
            this.provider     = provider;
            this.notification = notification;
            if (forceSendCreatedMail)
            {
                this.emailType = AsyncOperationNotificationEmailType.Created;
            }
            else
            {
                switch (notification.Status)
                {
                case AsyncOperationStatus.Completed:
                    this.emailType = AsyncOperationNotificationEmailType.Completed;
                    break;

                case AsyncOperationStatus.Failed:
                    this.emailType = AsyncOperationNotificationEmailType.Failed;
                    break;

                case AsyncOperationStatus.CertExpiring:
                    this.emailType = AsyncOperationNotificationEmailType.CertExpiring;
                    break;

                case AsyncOperationStatus.CertExpired:
                    this.emailType = AsyncOperationNotificationEmailType.CertExpired;
                    break;

                default:
                    this.emailType = AsyncOperationNotificationEmailType.Created;
                    break;
                }
            }
            this.emailMessage         = new EmailMessage(this.provider.Service);
            this.emailMessage.Subject = this.GetSubject();
            this.emailMessage.Body    = this.GetBody();
            this.AppendRecipients(notification.NotificationEmails);
        }