예제 #1
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        public static WikiEdit Parse(string message)
        {
            Match m = _messageRE.Match(message);

            if (m.Success)
            {
                WikiEdit edit = new WikiEdit();
                edit._article  = m.Groups[1].Value;
                edit._diffLink = m.Groups[3].Value;
                edit._author   = m.Groups[4].Value;
                int.TryParse(m.Groups[5].Value, out edit._size);
                edit._summary = m.Groups[6].Value;
                string flags = m.Groups[2].Value;
                edit._flags       = EditFlags.None;
                edit._flagsString = flags;

                m = _diffRE.Match(m.Groups[3].Value);
                if (m.Success)
                {
                    long.TryParse(m.Groups[4].Value, out edit._oldId);
                    if (!string.IsNullOrEmpty(m.Groups[3].Value))
                    {
                        long.TryParse(m.Groups[3].Value, out edit._diff);
                    }
                }
                for (int i = 0; i < flags.Length; ++i)
                {
                    switch (flags[i])
                    {
                    case '!':
                        edit._flags |= EditFlags.Unreviewed;
                        break;

                    case 'B':
                        edit._flags |= EditFlags.Bot;
                        break;

                    case 'M':
                        edit._flags |= EditFlags.Minor;
                        break;

                    case 'N':
                        edit._flags |= EditFlags.New;
                        break;

                    default:
                        break;
                    }
                }
                return(edit);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        public PageListViewItem(string time,
                                string flags,
                                int size,
                                string authors,
                                int changes,
                                long diff,
                                long oldId,
                                string page,
                                int nm)
            : base("")
        {
            _time      = time;
            _flags     = flags;
            _size      = size;
            _authors   = authors;
            _changes   = changes;
            _diffNum   = diff;
            _oldId     = oldId;
            _page      = page;
            _namespace = nm;

            DateTime timeStamp = DateTime.Parse(_time, null,
                                                System.Globalization.DateTimeStyles.AssumeUniversal);
            string t       = timeStamp.ToShortTimeString();
            string strSize = size >= 0 ? "+" + size.ToString() : size.ToString();

            SubItems[0].Text = t;
            SubItems.Add(_flags);
            if (_namespace != 0)
            {
                SubItems.Add(string.Format("{0}:{1}", WikiEdit.NumberToNamespace(_namespace), _page));
            }
            else
            {
                SubItems.Add(_page);
            }
            SubItems.Add(_changes.ToString());
            SubItems.Add(strSize);
            SubItems.Add(_authors);

            UseItemStyleForSubItems = false;
            SubItems[0].ForeColor   = Color.Gray;
            SubItems[2].ForeColor   = Color.Blue;
            SubItems[3].ForeColor   = Color.Gray;

            if (strSize.Contains('+'))
            {
                SubItems[4].ForeColor = Color.Green;
            }
            else if (strSize.Contains('-'))
            {
                SubItems[4].ForeColor = Color.Red;
            }
            SubItems[5].ForeColor = Color.Gray;
        }
예제 #3
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        private void recentChangesListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            PageListViewItem selectedItem = recentChangesListView.SelectedItems.Count > 0 ? (PageListViewItem)recentChangesListView.SelectedItems[0] : null;

            if (selectedItem != null)
            {
                string page = selectedItem.SubItems[2].Text;
                detailsListView.BeginUpdate();
                detailsListView.SuspendLayout();
                detailsListView.Items.Clear();

                using (SQLiteCommand command = new SQLiteCommand(_connection))
                {
                    SQLiteParameter pageValue = new SQLiteParameter("@page");
                    pageValue.Value = selectedItem.Page;
                    command.Parameters.Add(pageValue);
                    SQLiteParameter namespaceValue = new SQLiteParameter("@namespace");
                    namespaceValue.Value = selectedItem.Namespace;
                    command.Parameters.Add(namespaceValue);
                    command.CommandText = @"SELECT timestamp, flags, size, user, summary, id, oldid
                                            FROM [edits]
                                            WHERE page=@page AND namespace=@namespace
                                            ORDER by timestamp DESC";
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int size;
                            int.TryParse(reader[2].ToString(), out size);
                            int flags;
                            int.TryParse(reader[1].ToString(), out flags);
                            long diff;
                            long.TryParse(reader[5].ToString(), out diff);
                            long oldid;
                            long.TryParse(reader[6].ToString(), out oldid);

                            EditListViewItem item = new EditListViewItem(reader[0].ToString(),
                                                                         WikiEdit.FlagsToString((EditFlags)flags),
                                                                         size,
                                                                         reader[3].ToString(),
                                                                         reader[4].ToString(),
                                                                         diff,
                                                                         oldid);

                            detailsListView.Items.Add(item);
                        }
                        detailsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                    }
                }
                detailsListView.ResumeLayout();
                detailsListView.EndUpdate();
            }
        }
예제 #4
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        private void OnChannelMessage(object sender, IrcEventArgs e)
        {
            var edit = WikiEdit.Parse(e.Data.RawMessage);

            if (edit != null)
            {
                using (SQLiteCommand command = new SQLiteCommand(_connection))
                {
                    command.CommandText = @"INSERT INTO [edits]
                        (timestamp, user, page, flags, id, oldid, size, summary, namespace)
                        VALUES (datetime('now'), @user, @page, @flags, @id, @oldid, @size, @summary, @namespace)";
                    SQLiteParameter author = new SQLiteParameter("@user");
                    author.Value = edit.Author;
                    SQLiteParameter page = new SQLiteParameter("@page");
                    page.Value = edit.Article;
                    SQLiteParameter flags = new SQLiteParameter("@flags");
                    flags.Value = (int)edit.Flags;
                    SQLiteParameter diff = new SQLiteParameter("@id");
                    diff.Value = edit.Id;
                    SQLiteParameter size = new SQLiteParameter("@size");
                    size.Value = edit.Size;
                    SQLiteParameter summary = new SQLiteParameter("@summary");
                    summary.Value = edit.Summary;
                    SQLiteParameter oldid = new SQLiteParameter("@oldid");
                    oldid.Value = edit.OldId;
                    SQLiteParameter nm = new SQLiteParameter("@namespace");
                    nm.Value = 0;

                    var    namespaces = WikiEdit.GetNamespaces();
                    string key        = namespaces.Keys.FirstOrDefault(n => edit.Article.StartsWith(n + ":"));
                    if (!string.IsNullOrEmpty(key))
                    {
                        page.Value = edit.Article.Replace(key + ":", "");
                        nm.Value   = namespaces[key];
                    }

                    command.Parameters.Add(author);
                    command.Parameters.Add(page);
                    command.Parameters.Add(flags);
                    command.Parameters.Add(diff);
                    command.Parameters.Add(size);
                    command.Parameters.Add(summary);
                    command.Parameters.Add(oldid);
                    command.Parameters.Add(nm);

                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                }
            }
        }
예제 #5
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        private void importWatchlistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            using (SQLiteCommand command = new SQLiteCommand(_connection))
            {
                command.CommandText = @"DELETE FROM [watched_pages]";
                command.ExecuteNonQuery();
            }

            using (TextReader sr = new StreamReader(dlg.FileName))
                using (SQLiteTransaction transaction = _connection.BeginTransaction())
                    using (SQLiteCommand command = new SQLiteCommand(_connection))
                    {
                        command.CommandText = @"INSERT INTO [watched_pages] (page, namespace) VALUES (@page, @namespace)";
                        SQLiteParameter page = new SQLiteParameter("@page");
                        command.Parameters.Add(page);
                        SQLiteParameter nm = new SQLiteParameter("@namespace");
                        command.Parameters.Add(nm);
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            nm.Value = 0;
                            var    namespaces = WikiEdit.GetNamespaces();
                            string key        = namespaces.Keys.FirstOrDefault(n => line.StartsWith(n + ":"));
                            if (!string.IsNullOrEmpty(key))
                            {
                                page.Value = line.Replace(key + ":", "");
                                nm.Value   = namespaces[key];
                            }
                            else
                            {
                                page.Value = line;
                            }
                            command.ExecuteNonQuery();
                        }
                        transaction.Commit();
                    }
        }
예제 #6
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OptionsForm dlg = new OptionsForm();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Settings.Default.IrcUser        = dlg.User;
                Settings.Default.IrcDescription = dlg.Description;
                Settings.Default.Language       = dlg.Language;
                Settings.Default.HttpsLinks     = dlg.HttpsLinks;
                Settings.Default.Save();

                disconnectButton_Click(this, EventArgs.Empty);
                if (!_connection.ConnectionString.Contains("\\" + Settings.Default.Language + "\\"))
                {
                    SwitchToLanguage(Settings.Default.Language);
                    WikiEdit.SwitchToLanguage(Settings.Default.Language);
                    UpdateViews();
                }
            }
        }
예제 #7
0
파일: MainForm.cs 프로젝트: vnisor/WikiLive
        void UpdateViews()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new StringParameterDelegate(UpdateViews), new object[] {});
            }
            else
            {
                EditFlags mask = EditFlags.None;
                if (reviewedEditsToolStripMenuItem.Checked)
                {
                    mask |= EditFlags.Unreviewed;
                }
                if (newArticlesToolStripMenuItem.Checked)
                {
                    mask |= EditFlags.New;
                }
                if (minorEditsToolStripMenuItem.Checked)
                {
                    mask |= EditFlags.Minor;
                }
                if (botEditsToolStripMenuItem.Checked)
                {
                    mask |= EditFlags.Bot;
                }

                EditFlags onlyMask = EditFlags.None;
                if (onlyNewToolStripMenuItem.Checked)
                {
                    mask     |= EditFlags.New;
                    onlyMask |= EditFlags.New;
                }
                if (onlyBotEditToolStripMenuItem.Checked)
                {
                    mask     |= EditFlags.Bot;
                    onlyMask |= EditFlags.Bot;
                }
                if (onlyMinToolStripMenuItem.Checked)
                {
                    mask     |= EditFlags.Minor;
                    onlyMask |= EditFlags.Minor;
                }
                if (onlyUnreviewedEditsToolStripMenuItem.Checked)
                {
                    mask     |= EditFlags.Unreviewed;
                    onlyMask |= EditFlags.Unreviewed;
                }
                recentChangesListView.BeginUpdate();
                recentChangesListView.Items.Clear();
                recentChangesListView.Groups.Clear();

                using (SQLiteCommand command = new SQLiteCommand(_connection))
                {
                    SQLiteParameter maskValue = new SQLiteParameter("@mask");
                    maskValue.Value = (int)mask;
                    command.Parameters.Add(maskValue);
                    SQLiteParameter onlyMaskValue = new SQLiteParameter("@onlyMask");
                    onlyMaskValue.Value = (int)onlyMask;
                    command.Parameters.Add(onlyMaskValue);
                    command.CommandText = @"SELECT max(timestamp),
                                                   sum(flags & 4),
                                                   page,
                                                   count(timestamp),
                                                   sum(size),
                                                   group_concat(user),
                                                   max(id),
                                                   min(oldid),
                                                   namespace,
                                                   (namespace || ':' || page) AS name
                                            FROM [edits]
                                            WHERE (flags & @onlyMask) == @onlyMask AND
                                                  (flags | @mask) == @mask
                                            GROUP BY name
                                            ORDER by max(timestamp) DESC";
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DateTime      time  = DateTime.Parse(reader[0].ToString());
                            string        day   = time.ToLongDateString();
                            string        t     = time.ToShortTimeString();
                            bool          found = false;
                            ListViewGroup group = null;
                            for (int i = 0; i < recentChangesListView.Groups.Count; ++i)
                            {
                                if (recentChangesListView.Groups[i].Header == day)
                                {
                                    group = recentChangesListView.Groups[i];
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                group = new ListViewGroup(day);
                                recentChangesListView.Groups.Add(group);
                            }

                            string[] authorsList = reader[5].ToString().Split(new char[] { ',' });
                            string   authors     = string.Join(", ", authorsList.Distinct().ToArray());
                            int      size;
                            int.TryParse(reader[4].ToString(), out size);
                            int flags;
                            int.TryParse(reader[1].ToString(), out flags);
                            int changes;
                            int.TryParse(reader[3].ToString(), out changes);
                            long diff;
                            long.TryParse(reader[6].ToString(), out diff);
                            long oldId;
                            long.TryParse(reader[7].ToString(), out oldId);
                            int nm;
                            int.TryParse(reader[8].ToString(), out nm);
                            PageListViewItem item = new PageListViewItem(t,
                                                                         WikiEdit.FlagsToString((EditFlags)flags),
                                                                         size,
                                                                         authors,
                                                                         changes,
                                                                         diff,
                                                                         oldId,
                                                                         reader[2].ToString(),
                                                                         nm);
                            item.Group = group;
                            recentChangesListView.Items.Add(item);
                        }
                    }
                }
                recentChangesListView.EndUpdate();

                watchListView.BeginUpdate();
                watchListView.Items.Clear();
                watchListView.Groups.Clear();

                using (SQLiteCommand command = new SQLiteCommand(_connection))
                {
                    command.CommandText = @"SELECT max(timestamp), sum(flags & 4), edits.page, count(timestamp), sum(size), group_concat(user), max(edits.id), min(oldid), edits.namespace, (edits.namespace || ':' || edits.page) AS name
                                            FROM [edits], [watched_pages]
                                            WHERE edits.page = watched_pages.page AND
                                                  (edits.namespace=watched_pages.namespace OR
                                                   edits.namespace=watched_pages.namespace + 1)
                                            GROUP BY name
                                            ORDER by max(timestamp) DESC";
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DateTime      time  = DateTime.Parse(reader[0].ToString());
                            string        day   = time.ToLongDateString();
                            string        t     = time.ToShortTimeString();
                            bool          found = false;
                            ListViewGroup group = null;
                            for (int i = 0; i < watchListView.Groups.Count; ++i)
                            {
                                if (watchListView.Groups[i].Header == day)
                                {
                                    group = watchListView.Groups[i];
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                group = new ListViewGroup(day);
                                watchListView.Groups.Add(group);
                            }

                            string[] authorsList = reader[5].ToString().Split(new char[] { ',' });
                            string   authors     = string.Join(", ", authorsList.Distinct().ToArray());
                            int      size;
                            int.TryParse(reader[4].ToString(), out size);
                            int flags;
                            int.TryParse(reader[1].ToString(), out flags);
                            int changes;
                            int.TryParse(reader[3].ToString(), out changes);
                            long diff;
                            long.TryParse(reader[6].ToString(), out diff);
                            long oldId;
                            long.TryParse(reader[7].ToString(), out oldId);
                            int nm;
                            int.TryParse(reader[8].ToString(), out nm);
                            PageListViewItem item = new PageListViewItem(t,
                                                                         WikiEdit.FlagsToString((EditFlags)flags),
                                                                         size,
                                                                         authors,
                                                                         changes,
                                                                         diff,
                                                                         oldId,
                                                                         reader[2].ToString(),
                                                                         nm);
                            item.Group = group;
                            watchListView.Items.Add(item);
                        }
                    }
                }
                watchListView.EndUpdate();
            }
        }
예제 #8
0
        public static WikiEdit Parse(string message)
        {
            Match m = _messageRE.Match(message);
            if (m.Success)
            {
                WikiEdit edit = new WikiEdit();
                edit._article = m.Groups[1].Value;
                edit._diffLink = m.Groups[3].Value;
                edit._author = m.Groups[4].Value;
                int.TryParse(m.Groups[5].Value, out edit._size);
                edit._summary = m.Groups[6].Value;
                string flags = m.Groups[2].Value;
                edit._flags = EditFlags.None;
                edit._flagsString = flags;

                m = _diffRE.Match(m.Groups[3].Value);
                if (m.Success)
                {
                    long.TryParse(m.Groups[4].Value, out edit._oldId);
                    if (!string.IsNullOrEmpty(m.Groups[3].Value))
                    {
                        long.TryParse(m.Groups[3].Value, out edit._diff);
                    }
                }
                for (int i = 0; i < flags.Length; ++i)
                {
                    switch (flags[i])
                    {
                        case '!':
                            edit._flags |= EditFlags.Unreviewed;
                            break;
                        case 'B':
                            edit._flags |= EditFlags.Bot;
                            break;
                        case 'M':
                            edit._flags |= EditFlags.Minor;
                            break;
                        case 'N':
                            edit._flags |= EditFlags.New;
                            break;
                        default:
                            break;
                    }
                }
                return edit;
            }
            else
            {
                return null;
            }
        }