Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();
                    }
        }