Re: Arraylist.remove problem?? Please help.
- From: "Extremest" <dnncampbell1@xxxxxxxxxxx>
- Date: 14 Jun 2006 14:50:21 -0700
We went to Florida for about 10 days. Pretty much went all over the
state from beach to beach. Was very relaxing hated to have to come
back to work. Here is my code so far. If you can just help point me
in the right direction I should be able to figure it out. I am usually
a pretty quick learner. I know that the big slow down for it is the
loop. so if the group thing can become a reality I know it will speed
it up big time. Thanks for any help you can give and for what help you
have already given.
using System;
using System.Collections;
using System.Text;
using MySql.Data;
using System.Text.RegularExpressions;
namespace createfiles
{
class Program
{
static ArrayList master;
static string group;
static string table;
static bool prepared = false;
static int numbfound = 1;
static MySql.Data.MySqlClient.MySqlConnection conn = new
MySql.Data.MySqlClient.MySqlConnection();
static MySql.Data.MySqlClient.MySqlCommand cmd = new
MySql.Data.MySqlClient.MySqlCommand();
static MySql.Data.MySqlClient.MySqlConnection connu = new
MySql.Data.MySqlClient.MySqlConnection();
static MySql.Data.MySqlClient.MySqlCommand cmdu = new
MySql.Data.MySqlClient.MySqlCommand();
static string myConnectionString =
"server=127.0.0.1;uid=root;pwd=password;database=test;";
static string[] groups = {"alt.binaries.games.xbox",
"alt.binaries.games.xbox360", "alt.binaries.boneless",
"alt.binaries.nl"};
static Regex reg = new Regex("\\.");
static Regex seg = new
Regex("\\([0-9]*/[0-9]*\\)",RegexOptions.IgnoreCase);
class Header
{
private string numb;
private string subject;
private int messageNumber;
private int maxMessages;
private string realSubject;
private string date;
private string from;
private string msg_id;
private string bytes;
public Header(string numb, string subject, string date,
string
from, string msg_id, string bytes)
{
this.numb = numb;
this.subject = subject;
this.date = date;
this.from = from;
this.msg_id = msg_id;
this.bytes = bytes;
ExtractMessageNumber(this.subject, out
this.messageNumber, out this.maxMessages);
this.realSubject = ExtractMainSubject(this.subject);
}
// Now pull apart the message title... move the
private void ExtractMessageNumber(string subject, out int
number, out int max)
{
Match m = seg.Match(subject);
string segsplit = m.ToString().Replace("(",
"").Replace(")", "");
string[] segments = segsplit.Split('/');
number = int.Parse(segments[0]);
max = int.Parse(segments[1]);
}
private string ExtractMainSubject(string subject)
{
return seg.Replace(subject, "");
}
//ExtractMessageNumber(this.subject, out
this.messageNumber, out this.maxMessages);
//this.realSubject = ExtractMainSubject(this.subject);
public string Number
{
get { return this.numb; }
}
public string Subject
{
get { return this.subject; }
}
public int MessageNumber
{
get { return this.messageNumber; }
}
public int MaxMessages
{
get { return this.maxMessages; }
}
public string RealSubject
{
get { return this.realSubject; }
}
public string Date
{
get { return this.date; }
}
public string From
{
get { return this.from; }
}
public string Msg_id
{
get { return this.msg_id; }
}
public string Bytes
{
get { return this.bytes; }
}
}
static void Main(string[] args)
{
while (numbfound > 0)
{
numbfound = 0;
for (int x = 0; x < groups.Length; x++)
{
conn.ConnectionString = myConnectionString;
conn.Open();
cmd.Connection = conn;
connu.ConnectionString = myConnectionString;
connu.Open();
cmdu.Connection = conn;
table = reg.Replace(groups[x], "");
group = groups[x];
getheaders();
//Console.WriteLine("Have this many headers {0}",
master.Count);
//Header one = (Header)master[0];
//Console.WriteLine("first one {0} {1}",
one.Number, one.Subject);
find();
master.Clear();
prepared = false;
conn.Close();
connu.Close();
}
Console.WriteLine(numbfound);
}
}
static void getheaders()
{
MySql.Data.MySqlClient.MySqlConnection conn = new
MySql.Data.MySqlClient.MySqlConnection();
MySql.Data.MySqlClient.MySqlCommand cmd = new
MySql.Data.MySqlClient.MySqlCommand();
string myConnectionString =
"server=127.0.0.1;uid=root;pwd=password;database=test;";
conn.ConnectionString = myConnectionString;
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "select * from " + table + " where
subject like '%(%/%)%' and subject like '%\"%\"%' limit 400000";
MySql.Data.MySqlClient.MySqlDataReader reader;
reader = cmd.ExecuteReader();
master = new ArrayList();
while (reader.Read())
{
Header h = new Header(reader.GetValue(0).ToString(),
reader.GetValue(1).ToString(), reader.GetValue(3).ToString(),
reader.GetValue(2).ToString(), reader.GetValue(4).ToString(),
reader.GetValue(5).ToString());
master.Add(h);
}
reader.Close();
conn.Close();
}
static void find()
{
while (master.Count > 0)
{
Header start = (Header)master[master.Count-1];
master.RemoveAt(master.Count-1);
int max = start.MaxMessages;
max += 1;
int counter = 1;
Header[] found = new Header[max];
string testsubject = start.RealSubject;
int index = start.MessageNumber;
//int temp = master.Count;
if (index < max)
{
found[index] = start;
for (int x = master.Count - 1; x >= 0; x--)
{
Header test = (Header)master[x];
if (test.RealSubject == testsubject)
{
master.RemoveAt(x);
index = test.MessageNumber;
if (index < max)
{
found[index] = test;
counter++;
}
}
}
int temp = max - 1;
//Console.WriteLine("temp {0} and counter {1}",
temp, counter);
if (counter == temp)
{
int count = 0;
foreach (object o in found)
{
if (o == null)
++count;
}
if (count == 1)
{
numbfound++;
update(found);
insert(found);
}
}
}
}
}
static void insert(Header[] found)
{
string msg_id = null;
string bytes = null;
int totalbytes = 0;
for(int x=1; x<found.Length;x++)
{
msg_id += found[x].Msg_id + "|";
bytes += found[x].Bytes +"|";
totalbytes += int.Parse(found[x].Bytes);
}
if (!prepared)
{
cmd.CommandText = "insert into `files`
(`subject`,`from`,`date`,`msg_ids`,`bytes`,`totalbytes`,`groups`)
values (?subject, ?from, ?date, ?msg_ids, ?bytes, ?totalbytes,
?groups)";
cmd.Prepare();
prepared = true;
}
cmd.Parameters.Add("?subject", found[1].RealSubject);
cmd.Parameters.Add("?from", found[1].From);
cmd.Parameters.Add("?date", found[1].Date);
cmd.Parameters.Add("?msg_ids", msg_id);
cmd.Parameters.Add("?bytes", bytes);
cmd.Parameters.Add("?totalbytes", totalbytes);
cmd.Parameters.Add("?groups", group + "|");
//cmd.Parameters.Add("?nzb", '0');
cmd.ExecuteNonQuery();
}
static void update(Header[] found)
{
for (int x = 1; x < found.Length; x++)
{
cmdu.CommandText = "delete from `" + table + "` where
`numb` = '" + found[x].Number + "'";
cmdu.ExecuteNonQuery();
}
}
}
}
.
- Follow-Ups:
- Re: Arraylist.remove problem?? Please help.
- From: Bjorn Abelli
- Re: Arraylist.remove problem?? Please help.
- References:
- Re: Arraylist.remove problem?? Please help.
- From: Bjorn Abelli
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Bruce Wood
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Bruce Wood
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Bruce Wood
- Re: Arraylist.remove problem?? Please help.
- From: Extremest
- Re: Arraylist.remove problem?? Please help.
- From: Bruce Wood
- Re: Arraylist.remove problem?? Please help.
- Prev by Date: Re: .NET Poor threading architecture?
- Next by Date: Re: How to get a part of a string using reg exp
- Previous by thread: Re: Arraylist.remove problem?? Please help.
- Next by thread: Re: Arraylist.remove problem?? Please help.
- Index(es):
Relevant Pages
|
Loading