コード例 #1
0
        public void Handle(CheckIntervalElapsedMessage message)
        {
            if (Interlocked.CompareExchange(ref _ticket, 1, 0) == 0)
            {
                _taskFactory.StartNew(() =>
                {
                    try
                    {
                        if (!_pluginMetadata.IsSyncronizableProfile)
                        {
                            return;
                        }
                        foreach (var account in _collection)
                        {
                            try
                            {
                                if (account.Profiles.Empty())
                                {
                                    continue;
                                }

                                var queueName            = _transport.GetQueueName(account.Name.Value);
                                var queueIsNotOverloaded = MsmqHelper.QueueIsNotOverloaded(queueName,
                                                                                           "Failed to count messages in queue for account '{0}'"
                                                                                           .Fmt(account.Name.Value), 10);
                                if (!queueIsNotOverloaded)
                                {
                                    continue;
                                }
                                foreach (var profile in account.Profiles)
                                {
                                    var lastSyncDate = profile.Get <LastSyncDate>().FirstOrDefault();
                                    if (IsTimeToSyncronize(profile, lastSyncDate) && profile.Initialized)
                                    {
                                        _bus.SetOut(profile.ConvertToPluginProfile().Name);
                                        _bus.SetOut(account.Name);
                                        _bus.SendLocal(lastSyncDate != null
                                                                                                               ? new TickMessage(lastSyncDate.Value)
                                                                                                               : new TickMessage(null));
                                        ObjectFactory.GetInstance <ILogManager>().GetLogger(GetType()).Info("TickMesage sent");
                                        profile.Get <LastSyncDate>().ReplaceWith(new LastSyncDate(CurrentDate.Value));
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                LogManager.GetLogger(GetType())
                                .Error(string.Format("Failed to send tick message for account '{0}'", account.Name.Value), e);
                            }
                        }
                    }
                    finally
                    {
                        Interlocked.Decrement(ref _ticket);
                    }
                });
            }
        }
コード例 #2
0
 public IEnumerable <string> GetChildTags()
 {
     return(_accountCollection.Where(a => a.Profiles.Any()).Select(x => _transport.GetQueueName(x.Name.Value)));
 }