Re: Arraylist.remove problem?? Please help.



ok this is what I have so far. Does anyone see anything wrong with it
or any ways to make it better.

using System;
using System.Collections;
using System.Text;
using MySql.Data;
using System.Text.RegularExpressions;

namespace groupheaders
{
class Program
{
static Hashtable master;
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.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 seg = new Regex("\\([0-9]*/[0-9]*\\)",
RegexOptions.IgnoreCase);
static string group;
static string table;
static Regex reg = new Regex("\\.");
static bool prepared = false;
static int numbfound = 1;
class RelatedHeaders : IEnumerable
{
private string _realSubject = null;
private ArrayList _list = new ArrayList();


public RelatedHeaders(Header firstHeader)
{
this._realSubject = firstHeader.RealSubject;
this._list.Add(firstHeader);
}


public void Add(Header newHeader)
{
if (newHeader.RealSubject != this._realSubject)
{
throw new ArgumentException(String.Format("New
header has subject '{0}', but should be '{1}'.", newHeader.RealSubject,
this._realSubject), "newHeader");
}
this._list.Add(newHeader);
}

public ArrayList GetList()
{
return this._list;
}

public IEnumerator GetEnumerator()
{
return this._list.GetEnumerator();
}
}
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;
static Regex seg = new Regex("\\([0-9]*/[0-9]*\\)",
RegexOptions.IgnoreCase);

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;
conn.ConnectionString = myConnectionString;
conn.Open();
cmd.Connection = conn;
cmdu.Connection = conn;
for (int x = 0; x < groups.Length; x++)
{
table = reg.Replace(groups[x], "");
group = groups[x];
getheaders();
//Console.WriteLine("Have this many in {0} - {1}",
group, master.Count);
RelatedHeaders[] t = new
RelatedHeaders[master.Count];
master.Values.CopyTo(t, 0);
//master.Clear();
for (int s = 0; s < t.Length; s++)
{
RelatedHeaders temp = t[s];
ArrayList p = temp.GetList();
for (int y = p.Count - 1; y >= 0; y--)
{
Header test = (Header)p[y];
Header[] narray = new
Header[test.MaxMessages + 1];
narray[test.MessageNumber] = test;
find(narray);
}

}
prepared = false;
}
conn.Close();
Console.WriteLine(numbfound);
}
}
static void find(Header[] list)
{
int count = 0;
foreach (object o in list)
{
if (o == null)
++count;
}
if (count == 1)
{
if (list[0] == null)
{
insert(list);
update(list);
numbfound++;
}
}
}
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();
}
}
static void getheaders()
{
cmd.CommandText = "select * from " + table + " where
subject like '%(%/%)%' and subject like '%\"%\"%' order by `numb` desc
limit 500000";
MySql.Data.MySqlClient.MySqlDataReader reader;
reader = cmd.ExecuteReader();
master = new Hashtable();
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());
RelatedHeaders group =
(RelatedHeaders)master[h.RealSubject];
if (group == null)
{
group = new RelatedHeaders(h);
master.Add(h.RealSubject, group);
}
else
{
group.Add(h);
}


}
reader.Close();
}


}
}

.



Relevant Pages

  • Re: Setting id in a dynmaically generated checkboxlist
    ... > protected Repeater Repeater1; ... > public Category(string title, string explanation, ... > public string Explanation ... > private string explanation; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Threading with an object and Session
    ... thread post the mail body directly to the session, ... private string _DatabaseConnection; ... public string EmailNameField ...
    (microsoft.public.dotnet.framework.aspnet)
  • Default.aspx.cs
    ... string strReturn = SendInvitations(txtName.Text, ... private string SendInvitations(string name, string body, string ... emails, string codedString, ArrayList friend) ... public string subject ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: variable length fields for flexibility in subroutines
    ... private string _IntBlock; ... public string IBreturn ... public string IBstreet ...
    (comp.lang.cobol)
  • Re: casting class to interface
    ... to Comparable2... ... private String title, firstName, lastName, publisher, dateOfEdition, ... String lastName, int editionNumber,String dateOfEdition,int ... public String toStringLong() ...
    (comp.lang.java.programmer)