/// <summary> /// Check exchange mailboxes subscriptions state. Starts exchange events service. /// Fail handler for mailboxes without subscription. /// </summary> /// <param name="userConnection"><see cref="UserConnection"/> instance.</param> /// <param name="parameters">Process parameters collection.</param> public void Execute(UserConnection userConnection, IDictionary <string, object> parameters) { _log = ClassFactory.Get <ISynchronizationLogger>(new ConstructorArgument("userId", userConnection.CurrentUser.Id)); try { _log.InfoFormat("ListenerServiceFailJob started"); if (!GetIsFeatureEnabled(userConnection, "ExchangeListenerEnabled")) { return; } UserConnection = userConnection; ListenerManager = GetExchangeListenerManager(); _log.DebugFormat("ListenerServiceFailJob: _listenerManager initiated"); var mailboxes = GetMailboxesWithoutSubscriptions(); _log.InfoFormat("ListenerServiceFailJob: mailboxes recived"); ScheduleFailoverHandlers(mailboxes); _log.InfoFormat("ListenerServiceFailJob: Failover handlers scheduled"); } catch (Exception e) { _log.Error($"ListenerServiceFailJob error {e}", e); } finally { int periodMin = Core.Configuration.SysSettings.GetValue(userConnection, "ListenerServiceFailJobPeriod", 1); if (periodMin == 0) { var schedulerWraper = ClassFactory.Get <IAppSchedulerWraper>(); schedulerWraper.RemoveGroupJobs(ListenerServiceFailJobFactory.JobGroupName); _log.ErrorFormat("ListenerServiceFailJobPeriod is 0, ListenerServiceFailJob stopped"); } _log.InfoFormat("ListenerServiceFailJob ended"); } }
/// <summary> /// Calls <paramref name="action"/> and handles thrown exceptions. /// </summary> /// <param name="action">Authentication action.</param> /// <param name="senderEmailAddress">Mailbox address.</param> private void TryDoListenerAction(string senderEmailAddress, Action action) { try { ListenerUtils.TryDoListenerAction(action, senderEmailAddress, UserConnection); } catch (Exception e) { var exceptionMessage = e.GetType() == typeof(AggregateException) ? e.InnerException.Message : e.Message; _log.Error(exceptionMessage, e); throw; } }
/// <summary> /// Gets ignore errors retry count flag. /// </summary> /// <param name="parameters">Action parameters collection.</param> /// <returns><c>True</c> if current error ignores retry counter. Otherwise returns <c>false</c>.</returns> private bool GetIgnoreRetryCount(IDictionary <string, object> parameters) { if (!parameters.ContainsKey("Context")) { return(false); } var rawContext = parameters["Context"]?.ToString(); if (rawContext.IsNullOrEmpty()) { return(false); } try { var context = Json.Deserialize <Dictionary <string, object> >(rawContext); return(context.ContainsKey("UserRequested") && (bool)context["UserRequested"]); } catch (Exception e) { _log.Error($"Context deserialization failed", e); return(false); } }
/// <summary> /// Starts mailbox synchronization. /// </summary> /// <param name="mailbox"><see cref="Mailbox"/> instance.</param> /// <param name="filters">Synchronization session filters.</param> private void StartSynchronization(Mailbox mailbox, string filters) { if (!mailbox.CheckSynchronizationSettings()) { _log.Warn($"mailbox {mailbox.SenderEmailAddress} synchronization settings not valid"); return; } var credentials = GetCredentials(mailbox); var emailProvider = GetProvider(); Action action = () => { emailProvider.StartSynchronization(credentials, filters); }; try { ListenerUtils.TryDoListenerAction(action, credentials.SenderEmailAddress, _userConnection); } catch (Exception e) { _log.Error($"Synchronization of {_senderEmailAddress} failed", e); throw; } }