Example #1
0
        private static bool UpdateFAIMessage(string userConfigKey, string serializedValue, IExchangePrincipal principal, string clientString, out Exception ex)
        {
            ex = null;
            bool result = false;

            try
            {
                using (MailboxSession mailboxSession = ElcMailboxHelper.OpenMailboxSessionAsSystemService(principal, clientString))
                {
                    if (mailboxSession != null)
                    {
                        StoreId storeId = mailboxSession.GetSystemFolderId();
                        if (storeId == null)
                        {
                            storeId = mailboxSession.CreateSystemFolder();
                        }
                        using (UserConfiguration userConfiguration = ElcMailboxHelper.OpenFaiMessage(mailboxSession, "MRM", true, storeId))
                        {
                            if (userConfiguration != null)
                            {
                                IDictionary dictionary = userConfiguration.GetDictionary();
                                if (dictionary != null)
                                {
                                    if (dictionary.Contains(userConfigKey))
                                    {
                                        dictionary[userConfigKey] = serializedValue;
                                    }
                                    else
                                    {
                                        dictionary.Add(userConfigKey, serializedValue);
                                    }
                                    userConfiguration.Save();
                                    result = true;
                                }
                            }
                        }
                    }
                }
            }
            catch (CorruptDataException ex2)
            {
                result = false;
                ex     = ex2;
            }
            catch (InvalidOperationException ex3)
            {
                result = false;
                ex     = ex3;
            }
            catch (ObjectNotFoundException ex4)
            {
                result = false;
                ex     = ex4;
            }
            catch (StorageTransientException ex5)
            {
                result = false;
                ex     = ex5;
            }
            catch (StoragePermanentException ex6)
            {
                result = false;
                ex     = ex6;
            }
            return(result);
        }