Esempio n. 1
0
        protected TimeMonitor()
        {
            this._targetDate = Configuration.singleton()["newYearDateMonitoringTarget"];

            this._monitorThread = new Thread(monitorThreadMethod);

            this._timezoneList = new Dictionary<DateTime, string>();

            DAL.Select q = new DAL.Select(
                "tz_places",
                "ADDDATE(ADDDATE(\"" + MySqlHelper.EscapeString(this._targetDate) +
                "\", INTERVAL -tz_offset_hours HOUR), INTERVAL -tz_offset_minutes MINUTE)"
                );
            q.setFrom("timezones");
            q.escapeSelects(false);
            q.addOrder(
                new DAL.Select.Order(
                    "ADDDATE(ADDDATE(\"" + MySqlHelper.EscapeString(this._targetDate) +
                    "\", INTERVAL -tz_offset_hours HOUR), INTERVAL -tz_offset_minutes MINUTE)", false, false));

            ArrayList al = DAL.singleton().executeSelect(q);

            foreach (object[] row in al)
            {
                this._timezoneList.Add((DateTime.Parse(new String(Encoding.UTF8.GetChars(((byte[]) (row)[1]))))),
                                 (string) (row[0]));
            }

            this.registerInstance();
            this._monitorThread.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WatcherController"/> class.
        /// </summary>
        protected WatcherController()
        {
            this._watchers = new Dictionary<string, CategoryWatcher>();

            DAL.Select q = new DAL.Select("watcher_category", "watcher_keyword", "watcher_sleeptime");
            q.addOrder(new DAL.Select.Order("watcher_priority", true));
            q.setFrom("watcher");
            q.addLimit(100, 0);
            ArrayList watchersInDb = DAL.singleton().executeSelect(q);
            foreach (object[] item in watchersInDb)
            {
                this._watchers.Add((string) item[1],
                             new CategoryWatcher((string) item[0], (string) item[1],
                                                 int.Parse(((UInt32) item[2]).ToString())));
            }
            foreach (KeyValuePair<string, CategoryWatcher> item in this._watchers)
            {
                item.Value.categoryHasItemsEvent += categoryHasItemsEvent;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WatcherController"/> class.
        /// </summary>
        protected WatcherController()
        {
            this._watchers = new Dictionary <string, CategoryWatcher>();

            DAL.Select q = new DAL.Select("watcher_category", "watcher_keyword", "watcher_sleeptime");
            q.addOrder(new DAL.Select.Order("watcher_priority", true));
            q.setFrom("watcher");
            q.addLimit(100, 0);
            ArrayList watchersInDb = DAL.singleton().executeSelect(q);

            foreach (object[] item in watchersInDb)
            {
                this._watchers.Add((string)item[1],
                                   new CategoryWatcher((string)item[0], (string)item[1],
                                                       int.Parse(((UInt32)item[2]).ToString())));
            }
            foreach (KeyValuePair <string, CategoryWatcher> item in this._watchers)
            {
                item.Value.categoryHasItemsEvent += categoryHasItemsEvent;
            }
        }
Esempio n. 4
0
        private void threadBody()
        {
            Logger.instance().addToLog("Starting ACC Notifications watcher", Logger.LogTypes.General);
            try
            {
                DAL.Select query = new DAL.Select("notif_id", "notif_text", "notif_type");
                query.setFrom("acc_notifications");
                query.addLimit(1, 0);
                query.addOrder(new DAL.Select.Order("notif_id", true));

                while (true)
                {
                    Thread.Sleep(5000);

                    ArrayList data = DAL.singleton().executeSelect(query);

                    if (data.Count == 0)
                    {
                        continue;
                    }

                    foreach (object raw in data)
                    {
                        var d    = (object[])raw;
                        var id   = (int)d[0];
                        var text = (string)d[1];
                        var type = (int)d[2];

                        var destination = "##helpmebot";

                        switch (type)
                        {
                        case 1:
                            destination = "#wikipedia-en-accounts";
                            break;

                        case 2:
                            destination = "#wikipedia-en-accounts-devs";
                            break;
                        }

                        DAL.singleton().delete("acc_notifications", 1, new DAL.WhereConds("notif_id", id));

                        if (Configuration.singleton()["silence", destination] == "false")
                        {
                            Helpmebot6.irc.ircPrivmsg(destination, text);
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                EventHandler temp = this.threadFatalError;
                if (temp != null)
                {
                    temp(this, new EventArgs());
                }
            }
            Helpmebot6.irc.ircPrivmsg("##helpmebot", "ACC Notifications watcher died");
            Logger.instance().addToLog("ACC Notifications watcher died.", Logger.LogTypes.Error);
        }