Exemple #1
0
        public override void PostInitialisation()
        {
            var collection = StaticBase.Database.GetCollection <T>(typeof(T).Name).FindSync <T>(x => true).ToList();

            trackers = collection.ToDictionary(x => x.Name);

            trackers = (trackers == null ? new Dictionary <string, T>() : trackers);

            if (collection.Count > 0)
            {
                int gap = 600000 / collection.Count;

                for (int i = trackers.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var cur = trackers[trackers.Keys.ElementAt(i)];
                        cur.SetTimer(600000, gap * (i + 1) + 20000);
                        bool save = cur.ChannelConfig.Count == 0;
                        cur.Conversion(trackers.Count - i);
                        cur.PostInitialisation(trackers.Count - i);
                        if (save)
                        {
                            UpdateDBAsync(cur).Wait();
                        }
                        cur.OnMinorEventFired += OnMinorEvent;
                        cur.OnMajorEventFired += OnMajorEvent;
                    }
                    catch (Exception e)
                    {
                        Program.MopsLog(new LogMessage(LogSeverity.Error, "", $"Error on PostInitialisation, {e.Message}", e));
                    }
                }

                //Start Twitter STREAM after all are initialised
                if (typeof(T) == typeof(TwitterTracker))
                {
                    TwitterTracker.STREAM.StreamStopped += (sender, args) => { Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"TwitterSTREAM stopped. {args.DisconnectMessage?.Reason ?? ""}", args.Exception)); TwitterTracker.RestartStream(); };
                    TwitterTracker.STREAM.StreamStarted += (sender, args) => Program.MopsLog(new LogMessage(LogSeverity.Info, "", "TwitterSTREAM started."));
                    TwitterTracker.STREAM.WarningFallingBehindDetected += (sender, args) => Program.MopsLog(new LogMessage(LogSeverity.Warning, "", $"TwitterSTREAM falling behind, {args.WarningMessage.Message} ({args.WarningMessage.PercentFull}%)"));
                    TwitterTracker.STREAM.FilterLevel = Tweetinvi.Streaming.Parameters.StreamFilterLevel.Low;
                    TwitterTracker.STREAM.StartStreamMatchingAllConditionsAsync();
                }
            }
        }
Exemple #2
0
        public override void PostInitialisation()
        {
            var collection = StaticBase.Database.GetCollection <T>(typeof(T).Name).FindSync <T>(x => true).ToList();

            IncreaseGraph = StaticBase.Database.GetCollection <DatePlot>("TrackerHandler").FindSync <DatePlot>(x => x.ID.Equals(typeof(T).Name + "Handler")).FirstOrDefault();
            IncreaseGraph?.InitPlot("Date", "Tracker Increase", "dd-MMM", false);

            trackers = collection.ToDictionary(x => x.Name);

            trackers = (trackers == null ? new Dictionary <string, T>() : trackers);

            if (collection.Count > 0)
            {
                int gap = trackerInterval / collection.Count;

                for (int i = trackers.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var cur = trackers[trackers.Keys.ElementAt(i)];
                        //cur.SetTimer(trackerInterval, gap * (i + 1) + 20000);
                        bool save = cur.ChannelConfig.Count == 0;
                        cur.Conversion(trackers.Count - i);
                        cur.PostInitialisation(trackers.Count - i);
                        if (save)
                        {
                            UpdateDBAsync(cur).Wait();
                        }
                        cur.OnMinorEventFired += OnMinorEvent;
                        cur.OnMajorEventFired += OnMajorEvent;
                    }
                    catch (Exception e)
                    {
                        Program.MopsLog(new LogMessage(LogSeverity.Error, "", $"Error on PostInitialisation, {e.Message}", e));
                    }
                }

                //Start Twitter STREAM after all are initialised
                if (typeof(T) == typeof(TwitterTracker))
                {
                    TwitterTracker.STREAM.StreamStopped += (sender, args) => { Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"TwitterSTREAM stopped. {args.DisconnectMessage?.Reason ?? ""}", args.Exception)); TwitterTracker.RestartStream(); };
                    TwitterTracker.STREAM.StreamStarted += (sender, args) => Program.MopsLog(new LogMessage(LogSeverity.Info, "", "TwitterSTREAM started."));
                    TwitterTracker.STREAM.WarningFallingBehindDetected += (sender, args) => Program.MopsLog(new LogMessage(LogSeverity.Warning, "", $"TwitterSTREAM falling behind, {args.WarningMessage.Message} ({args.WarningMessage.PercentFull}%)"));
                    TwitterTracker.STREAM.FilterLevel = Tweetinvi.Streaming.Parameters.StreamFilterLevel.Low;
                    TwitterTracker.STREAM.StartStreamMatchingAllConditionsAsync();
                }
            }

            nextTracker = new System.Threading.Timer(LoopTrackers);
            loopQueue   = trackers.Values.ToList();
            if (trackers.FirstOrDefault().Value is BaseUpdatingTracker)
            {
                nextUpdate  = new System.Threading.Timer(LoopTrackersUpdate);
                loopQueue   = trackers.Where(x => (x.Value as BaseUpdatingTracker).ToUpdate.Count == 0).Select(x => x.Value).ToList();
                updateQueue = trackers.Where(x => (x.Value as BaseUpdatingTracker).ToUpdate.Count > 0).Select(x => x.Value).ToList();
                nextUpdate.Change(5000, updateInterval / (updateQueue.Count > 0 ? updateQueue.Count : 1));
            }
            nextTracker.Change(5000, trackerInterval / (loopQueue.Count > 0 ? loopQueue.Count : 1));
        }