Пример #1
0
        /// <inheritdoc cref="BaseLoadEmailEventExecutor.Synchronize(UserConnection, IDictionary{string, object})"/>
        protected override void Synchronize(UserConnection uc, IDictionary <string, object> parameters)
        {
            _log.Info($"LoadEmailEventExecutor.Synchronize started");
            var emails = parameters["Items"] as IEnumerable <Email>;

            if (!emails.Any())
            {
                _log.Info($"LoadEmailEventExecutor.Synchronize - no emails passed");
                return;
            }
            var emailService = ClassFactory.Get <IEmailService>(new ConstructorArgument("uc", uc));

            _log.Info($"IEmailService created");
            var synsSessionId = string.Format("LoadEmailEventSyncSession_{0}", Guid.NewGuid());
            var mailboxId     = (Guid)parameters["MailboxId"];

            foreach (var emailDto in emails)
            {
                if (LockItemForSync(uc, emailDto))
                {
                    _log.Info($"{synsSessionId} - item {emailDto.MessageId} locked for sync");
                    emailService.Save(emailDto, mailboxId, synsSessionId);
                }
                else
                {
                    NeedReRun = true;
                }
            }
            SaveSyncSession(uc, synsSessionId);
            UnlockSyncedEntities(uc);
            _log.Info($"LoadEmailEventExecutor.Synchronize ended");
        }
        /// <summary>
        /// Creates user connection and starts <paramref name="emailsData"/> synchronization.
        /// </summary>
        /// <param name="emailsData"><see cref="LoadEmailCommand"/> instance.</param>
        public void ProcessLoadEmailCommand(LoadEmailCommand emailsData)
        {
            var userName       = emailsData.SubscriptionInfo.SysAdminUnit;
            var userConnection = CreateUserConnection(userName, emailsData.SubscriptionInfo.TimeZoneId);

            _log = ClassFactory.Get <ISynchronizationLogger>(new ConstructorArgument("userId", userConnection.CurrentUser.Id));
            _log.Info($"UserConnection for {emailsData.SubscriptionInfo.SysAdminUnit} created.");
            try {
                StartSynchronization(userConnection, emailsData);
            }
            finally {
                userConnection?.Close(SessionEndMethod.Logout, false);
            }
            _log.Info($"ProcessLoadEmailCommand for {emailsData.SubscriptionInfo.MailboxId} ended.");
        }
        /// <summary>
        /// Starts <paramref name="emailsData"/> synchronization.
        /// </summary>
        /// <param name="userConnection"><see cref="UserConnection"/> instance.</param>
        /// <param name="emailsData"><see cref="LoadEmailCommand"/> instance.</param>
        protected void StartSynchronization(UserConnection userConnection, LoadEmailCommand emailsData)
        {
            Guid mailboxSyncSettingsId = emailsData.SubscriptionInfo.MailboxId;

            CheckMailboxAvaliable(userConnection, mailboxSyncSettingsId);
            var parameters = new Dictionary <string, object> {
                { "MailboxId", mailboxSyncSettingsId },
                { "Items", emailsData.Emails }
            };

            _log.Info($"StartSynchronization mailbox {mailboxSyncSettingsId} avaliable.");
            ValidateEvent(userConnection, parameters);
            _log.Info($"StartSynchronization mailbox {mailboxSyncSettingsId} valid.");
            Terrasoft.Core.Tasks.Task.StartNewWithUserConnection <LoadEmailEventExecutor, IDictionary <string, object> >(parameters);
        }
        /// <inheritdoc cref="IJobExecutor.Execute(UserConnection userConnection, IDictionary{string, object})"/>
        public void Execute(UserConnection userConnection, IDictionary <string, object> parameters)
        {
            _log = ClassFactory.Get <ISynchronizationLogger>(new ConstructorArgument("userId", userConnection.CurrentUser.Id));
            var senderEmailAddress = parameters["SenderEmailAddress"].ToString();

            _log.Info($"ConnectionEventExecutor.Execute for {senderEmailAddress} started");
            var helper = ClassFactory.Get <ISynchronizationErrorHelper>
                             (new ConstructorArgument("userConnection", userConnection));
            var ignoreRetryCount = GetIgnoreRetryCount(parameters);

            if ((bool)parameters["Avaliable"])
            {
                helper.CleanUpSynchronizationError(senderEmailAddress);
            }
            else
            {
                helper.ProcessSynchronizationError(senderEmailAddress,
                                                   parameters["ExceptionClassName"].ToString(), parameters["ExceptionMessage"].ToString(), ignoreRetryCount);
            }
            _log.Info($"ConnectionEventExecutor.Execute for {senderEmailAddress} finished");
        }
Пример #5
0
 /// <inheritdoc cref="BaseLoadEmailEventExecutor.Run(IDictionary{string, object})"/>
 public override void Run(IDictionary <string, object> parameters)
 {
     _log = ClassFactory.Get <ISynchronizationLogger>(new ConstructorArgument("userId", UserConnection.CurrentUser.Id));
     _log.Info($"LoadEmailEventExecutor.Run started");
     base.Run(parameters);
 }