473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Can Someone Help me figure this out? Not only finding multiparts

Here is the code I have so far. It connects to a db and grabs headers.
It then sorts them into groups and then puts all the complete ones
into another table. Problem I am having is that for some reason now it
is not finding ones that are single posts. Here is an example of a
header for a single.
(Ask the Dust ) [001/001] - "atd-ftc-repack.nfo" www.ctjes.com (1/1)

(1/1) at the end means it is part 1 of a 1 part post.

Any help would be greatly appreciated.

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

namespace groupheaders
{
class Program
{
static Hashtable master;
static ArrayList full;
static Header[] narray;
static MySql.Data.MySqlClient.MySqlConnection conn = new
MySql.Data.MySqlClient.MySqlConnection();
static MySql.Data.MySqlClient.MySqlConnection connr = new
MySql.Data.MySqlClient.MySqlConnection();
static MySql.Data.MySqlClient.MySqlCommand cmd = new
MySql.Data.MySqlClient.MySqlCommand();
static MySql.Data.MySqlClient.MySqlCommand cmdi = new
MySql.Data.MySqlClient.MySqlCommand();
static MySql.Data.MySqlClient.MySqlCommand cmdu = new
MySql.Data.MySqlClient.MySqlCommand();
static MySql.Data.MySqlClient.MySqlCommand cmds = new
MySql.Data.MySqlClient.MySqlCommand();
static string myConnectionString =
"server=127.0.0.1;uid=root;pwd=pass;database=test; ";
static string myConnectionStringr =
"server=local;uid=root;pwd=pass;database=db;";
//static string myConnectionStringr =
"server=127.0.0.1;uid=root;pwd=pass;database=test; ";
static ArrayList groupget;
static string[] groups;
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 bool prepareds = false;
static int numbfound = 1;
class RelatedHeaders : IEnumerable
{
private string _realSubject = null;
private ArrayList _list = new ArrayList();
private int _max;

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

public int max()
{
return this._max;
}

public int count()
{
return this._list.Count;
}
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);
//Console.WriteLine("{0}-{1}", this.count(),
this._max);
if (this.count() == this._max)
full.Add(this._list);
}

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;
private string group;

public Header(string numb, string subject, string date,
string
from, string msg_id, string bytes, string groups)
{
this.numb = numb;
this.subject = subject;
this.date = date;
this.from = from;
this.msg_id = msg_id;
this.bytes = bytes;
this.group = groups;
ExtractMessageNumber(this.subject, out
this.messageNumber, out this.maxMessages, out this.realSubject);
this.realSubject = ExtractMainSubject(this.subject);
}

// Now pull apart the message title...
private void ExtractMessageNumber(string subject, out int
number, out int max, out string realsubject)
{
try
{
int end = subject.LastIndexOf(")");
int start = subject.LastIndexOf("(");
int length = (end) - (start + 1);
string fullset = subject.Substring(start + 1,
length);
string[] segments = fullset.Split('/');
number = int.Parse(segments[0]);
max = int.Parse(segments[1]);
realsubject = subject.Substring(0, start - 1);
}
catch (Exception e)
{
//Console.WriteLine(e);
number = 0;
max = 10;
realsubject = null;
}
}

private string ExtractMainSubject(string subject)
{
return seg.Replace(subject, "");
}

public string Number
{
get { return this.numb; }
}
public string Subject
{
get { return this.subject; }
}

public string Groups
{
get { return this.group; }
}

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)
{
getgroups();
while (numbfound 0)
{
numbfound = 0;
conn.ConnectionString = myConnectionString;
conn.Open();
connr.ConnectionString = myConnectionStringr;
connr.Open();
cmd.Connection = conn;
cmdu.Connection = conn;
cmds.Connection = connr;
cmdi.Connection = connr;
for (int x = 0; x < groups.Length; x++)
{
//int start = 0;
//do
//{
full = new ArrayList();
table = reg.Replace(groups[x], "");
group = groups[x];
getheaders();
Console.WriteLine("Master Has This Size {0}",
master.Count);
master.Clear();
Console.WriteLine("Have this many in {0} -
{1}", group, full.Count);
for (int y = 0; y < full.Count; y++)
{
fullfind((ArrayList)full[y]);
}
//start = start + 50000;
//} while (master.Count 0);
prepared = false;
prepareds = false;
}
conn.Close();
connr.Close();
Console.WriteLine(numbfound);
int sleeptime = 5000;
//System.Threading.Thread.Sleep(sleeptime);
}
}
static void getgroups()
{
MySql.Data.MySqlClient.MySqlConnection conn2 = new
MySql.Data.MySqlClient.MySqlConnection();
MySql.Data.MySqlClient.MySqlCommand cmd2 = new
MySql.Data.MySqlClient.MySqlCommand();
string myConnectionString2 =
"server=127.0.0.1;uid=root;pwd=pass;database=test; ";
conn2.ConnectionString = myConnectionString2;
conn2.Open();
cmd2.Connection = conn2;
cmd2.CommandText = "select * from `groups`";
MySql.Data.MySqlClient.MySqlDataReader reader1;
reader1 = cmd2.ExecuteReader();
groupget = new ArrayList();
while (reader1.Read())
{
string temp = reader1.GetValue(0).ToString();
groupget.Add(temp);
}
reader1.Close();
conn2.Close();
groups = new string[groupget.Count];
for (int x = 0; x < groupget.Count; x++)
{
groups[x] = groupget[x].ToString();
//Console.WriteLine(groups[x]);
}

}
static void fullfind(ArrayList p)
{
Header test = (Header)p[0];
narray = new Header[test.MaxMessages + 1];
for (int y = 0; y < p.Count; y++)
{
test = (Header)p[y];
//Console.WriteLine("{0}-{1}-{2}", test.Subject,
test.MessageNumber, test.MaxMessages);
if (test.MessageNumber < narray.Length)
narray[test.MessageNumber] = test;
}
find(narray);
}
static void find(Header[] list)
{
int count = 0;
foreach (object o in list)
{
if (o == null)
count++;
}
if (count == 1)
{
if (list[0] == null)
{
//Console.Write(".");
insert(list);
update(list);
numbfound++;
}
}
}
static void insert(Header[] found)
{
string msg_id = null;
string bytes = null;
int totalbytes = 0;
int id;
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)
{
cmdi.CommandText = "insert ignore into `files`
(`subject`,`from`,`date`,`msg_ids`,`bytes`,`totalb ytes`,`groups`)
values (?subject, ?from, ?date, ?msg_ids, ?bytes, ?totalbytes,
?groups)";
cmdi.Prepare();
prepared = true;
}
cmdi.Parameters.Add("?subject", found[1].RealSubject);
cmdi.Parameters.Add("?from", found[1].From);
cmdi.Parameters.Add("?date", found[1].Date);
cmdi.Parameters.Add("?msg_ids", msg_id);
cmdi.Parameters.Add("?bytes", bytes);
cmdi.Parameters.Add("?totalbytes", totalbytes);
cmdi.Parameters.Add("?groups", found[1].Groups);
cmdi.ExecuteNonQuery();

if (!prepareds)
{
cmds.CommandText = "insert ignore into `subjects`
(`id`,`subject`,`totalbytes`,`date`,`groups`) values (last_insert_id(),
?subject, ?totalbytes, ?date, ?groups)";
cmds.Prepare();
prepareds = true;
}

cmds.Parameters.Add("?subject", found[1].RealSubject);
cmds.Parameters.Add("?totalbytes", totalbytes);
cmds.Parameters.Add("?date", found[1].Date);
cmds.Parameters.Add("?groups", found[1].Groups);
cmds.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 '%.nfo%' 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(), reader.GetValue(6).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();
}
}
}

Jul 25 '06 #1
2 1980
Extremest <dn**********@charter.netwrote:
Here is the code I have so far. It connects to a db and grabs headers.
It then sorts them into groups and then puts all the complete ones
into another table. Problem I am having is that for some reason now it
is not finding ones that are single posts. Here is an example of a
header for a single.
(Ask the Dust ) [001/001] - "atd-ftc-repack.nfo" www.ctjes.com (1/1)

(1/1) at the end means it is part 1 of a 1 part post.

Any help would be greatly appreciated.
You've posted a lot of code. Which bit is failing - the SQL, the
regular expression? If you could change your code into a *short* but
complete example, that would really help.

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 25 '06 #2
sorry about that. But I did happen to just find the problem. I was
adding them to the group and checking for it to be complete when it
added one to an existing group but not checking for completion when it
made a new group.

Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DOK | last post by:
I'm trying to create an eBay ad. So far, I've got the page the way I want it. However, the few animated gif's I have on the page display but are no longer animated. I can get it to work in...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
8
by: Jerim79 | last post by:
I am working on a script that will query a database for a FNAME/LNAME combo. If it finds the combo, I need it to do one set of instructions. If it doesn't find it, I need it to do something else....
10
by: strife | last post by:
Hi, This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot. I have to figure out the highest number from a users...
4
by: mattG | last post by:
I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or...
4
by: krishnai888 | last post by:
I had already asked this question long back but no one has replied to me..I hope someone replies to me because its very important for me as I am doing my internship. I am currently writing a code...
12
by: Jeff | last post by:
As I'm learning PHP, I'm making a fair number of mistakes in syntax. In perl, you can turn on reading these errors from the browser by adding this: use CGI::Carp 'fatalsToBrowser'; Is there...
4
by: Sanoski | last post by:
This might be a dumb question. I don't know. I'm new to all this. How do you find icons for your programs? All GUI applications have cool icons that represent various things. For instance, to save...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.