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); }
internal static void TryGetExistingValueInStore <T>(IExchangePrincipal exchangePrincipal, string clientString, string userConfigKey, Func <string, KeyValuePair <T, ElcMailboxHelper.ConfigState> > valueFunction, out T existingValue, out ElcMailboxHelper.ConfigState state, out Exception exception) { existingValue = default(T); state = ElcMailboxHelper.ConfigState.Unknown; exception = null; try { using (MailboxSession mailboxSession = ElcMailboxHelper.OpenMailboxSessionAsSystemService(exchangePrincipal, clientString)) { if (mailboxSession == null) { state = ElcMailboxHelper.ConfigState.ErrorWhileFetching; } else { StoreId systemFolderId = mailboxSession.GetSystemFolderId(); if (systemFolderId != null) { using (UserConfiguration userConfiguration = ElcMailboxHelper.OpenFaiMessage(mailboxSession, "MRM", false, systemFolderId)) { if (userConfiguration == null) { state = ElcMailboxHelper.ConfigState.FAINotFound; } else { IDictionary dictionary = userConfiguration.GetDictionary(); if (dictionary != null && dictionary.Contains(userConfigKey)) { string text = dictionary[userConfigKey] as string; if (text != null) { KeyValuePair <T, ElcMailboxHelper.ConfigState> keyValuePair = valueFunction(text); existingValue = keyValuePair.Key; state = keyValuePair.Value; } else { state = ElcMailboxHelper.ConfigState.Empty; } } else { state = ElcMailboxHelper.ConfigState.Empty; } } goto IL_AE; } } state = ElcMailboxHelper.ConfigState.FAINotFound; } IL_AE :; } } catch (InvalidCastException ex) { state = ElcMailboxHelper.ConfigState.Corrupt; exception = ex; } catch (CorruptDataException ex2) { state = ElcMailboxHelper.ConfigState.Corrupt; exception = ex2; } catch (InvalidOperationException ex3) { state = ElcMailboxHelper.ConfigState.Invalid; exception = ex3; } catch (StorageTransientException ex4) { state = ElcMailboxHelper.ConfigState.ErrorWhileFetching; exception = ex4; } catch (StoragePermanentException ex5) { state = ElcMailboxHelper.ConfigState.ErrorWhileFetching; exception = ex5; } }
internal static UserConfiguration OpenFaiMessage(MailboxSession mailboxSession, string faiMessageClass, bool createIfMissing) { StoreId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox); return(ElcMailboxHelper.OpenFaiMessage(mailboxSession, faiMessageClass, createIfMissing, defaultFolderId)); }