|
Hi,
I've read the rest of this thread, and hopefully I understand what your problem is. As far as I can tell, your main problem is the size of the file created by your program. (Please correct me if I am wrong)
Firstly, I suspect you are using XML serialization, this will likely explain the size. Can you post the code you use to create the file, and a small sample (just a few lines) from an output file so I can take a look at what's going on.
If my guess is correct, and you are using XML serialization, you might consider using binary serialization instead. This will almost certainly drastically reduce the size of the saved file. If you're not sure how to do this, post your code and I'll point out what needs to be changed.
Simon
Simon
|
|
|
|
|
Hi Simon!
Yes, the file size is at least 16x larger than it should be!
I am using binary serialization as far as I know.
I already tried using char arrays (like the original app) instead of strings.
That doesn't help at all.
Here's the start of the code that writes the first small class:
public void SerializeNow()
{
header c=new header();
Stream s=File.Open(@"C:\baduga\manure.tmp",FileMode.Append);
BinaryFormatter b=new BinaryFormatter();
FileStream hread=new FileStream(@"c:\baduga\races.txt",FileMode.Open); //read races.txt
StreamReader hread1=new StreamReader(hread);
string temp;
string[] t=new string[1435];
int a=0,x=0,y;
while((temp=hread1.ReadLine())!=null)
{
if(temp.StartsWith("JJGENDRACE"))
{
c.entries=a;
b.Serialize(s,c);
for(y=0;y<c.entries;y++)>
{
b.Serialize(s,h[y]);
}
a=x=0;
}
else
{
t[x]=temp;
if(t[x]=="") t[x]="0";
x++;
if(x==1435)
{
if(a==0)
{
c.track=t[0];
c.date=t[1];
c.race=t[2];
c.distance=int.Parse(t[5].Trim('-'));
c.distanceD=c.distance/220;
c.surface=t[6];
c.type=t[8];
c.sex=t[9];
c.formtype=t[10];
c.purse=int.Parse(t[11]);
c.purseD=c.purse/5000;
if(c.purseD>50) c.purseD=50;
c.claimprice=int.Parse(t[12]);
c.trackrecord=float.Parse(t[14]);
c.simulT=t[20];
c.simulR=t[21];
c.breed=t[22];
c.poly=t[24];
c.par2f=int.Parse(t[213]);
c.par4f=int.Parse(t[214]);
c.par6f=int.Parse(t[215]);
c.parspeed=int.Parse(t[216]);
c.parLf=int.Parse(t[217]);
}
|
|
|
|
|
With serialzation, all public members of the object are serialized. Is this what you want? If you have some members you don't want to be serialized you can mark them with attributes to prevent this.
Check that your problem is not with your code logic. Step through carefully and check that you aren't accidently serializing more than you meant too. (Like the same object twice).
If you switch to xml serialization you can look at the data and check that only the correct stuff is there. Then once your happy with the data being outputed, switch back to binary again.
Comments on the code (Numbers indicate line in code I'm talking about):
1) The for loop here is incomplete. I'm assuming you just want to loop through all objects in the array h, buy maybe more code is missing.
2) the variable a is never assigned a value other than 0. What is it's purpose?
3) For every line read in that starts with JJGENDRACE you are serializing the whole of the array h. I don't know whats in this array as you haven't included it's defination or population code, but why are you serializing the same array every time? This will be a huge waste of space if you are just serializing the same data over and over again.
General comment: The variable names c, s, b, t, a, x and y are not very useful. If you used more descriptive veriable names that would help other people to read your code.
public void SerializeNow()
{
header c = new header();
Stream s = File.Open(@"C:\baduga\manure.tmp", FileMode.Append);
BinaryFormatter b = new BinaryFormatter();
FileStream hread = new FileStream(@"c:\baduga\races.txt", FileMode.Open);
StreamReader hread1 = new StreamReader(hread);
string temp;
string[] t = new string[1435];
int a = 0, x = 0, y;
while ((temp = hread1.ReadLine()) != null)
{
if (temp.StartsWith("JJGENDRACE"))
{
2) c.entries = a;
b.Serialize(s, c);
1) for (y = 0; y
{
3) b.Serialize(s, h[y]);
}
a = x = 0;
}
else
{
t[x] = temp;
if (t[x] == "")
t[x] = "0";
x++;
if (x == 1435)
{
if (a == 0)
{
c.track = t[0];
c.date = t[1];
c.race = t[2];
c.distance = int.Parse(t[5].Trim('-'));
c.distanceD = c.distance / 220;
c.surface = t[6];
c.type = t[8];
c.sex = t[9];
c.formtype = t[10];
c.purse = int.Parse(t[11]);
c.purseD = c.purse / 5000;
if (c.purseD > 50)
c.purseD = 50;
c.claimprice = int.Parse(t[12]);
c.trackrecord = float.Parse(t[14]);
c.simulT = t[20];
c.simulR = t[21];
c.breed = t[22];
c.poly = t[24];
c.par2f = int.Parse(t[213]);
c.par4f = int.Parse(t[214]);
c.par6f = int.Parse(t[215]);
c.parspeed = int.Parse(t[216]);
c.parLf = int.Parse(t[217]);
}
}
}
}
}
Simon
|
|
|
|
|
For some reason it seems that I've got difficulties to understand the logic of the web service:
I need that a webpage or an application on client side will validate user's details (username, password). Validation is through db that seats on a server application. I want that the procedure will be:
calling a validation method through web service that will use the server's db. I understand how to connect the client or the website to the web service but don't understand how the web service connects to the server to use his db (or to call a function on the server that will do that).
Can someone help please?
thanks
y
|
|
|
|
|
IF it's a webpage, use AJAX, you can't call a webservice from the client. Unless you want to do it from the server, of course.
The webservice uses a standard mechanism to make requests via HTTP. It's all hidden from you, that's kind of the point.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
thanks Christian,
but to sharpen my misunderstanding :
if i want to use a function that on my server with an application that seats in the client computer :
1.i need a webrefference to the webservice in my client's application to create an instance of it right?
2. the webservice shld have a method that invokes method on the server
so how do i connect to the method on the server with the webservice (using a dll?)
sorry if i'm all upside down ...
|
|
|
|
|
johland wrote: need a webrefference to the webservice in my client's application to create an instance of it right?
Correct.
johland wrote: the webservice shld have a method that invokes method on the server
Well, every method that is marked as such in the webservice, invokes a method on the server. Automatically. .NET hides those details from you, so you call the method and create class instances as if they were local, and the framework handles the job of making calls to the webservice and getting the result. The only difference is you need to anticipate exceptions that can occur if the framework cannot find the webservice to call.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
If you don't like my answer, ask more questions so I understand where the problem is.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i think my first problem is phrasing
do these steps are right?
1.i want to use a method that seats on my server with another application
2.so i'm creating a webservice that call that method
this webservice will be part of the server solution so it will have access to the server db.
3.i want the client app to use this webservice so i add webreference to the client app and create instance of it and use its methods.
did i get it?
.
|
|
|
|
|
I was commenting on how my response got a 1/bad answer vote. If it wasn't you, then fair enough, but it seemed likely to me that it was.
Yes, you got it right. The framework handles all the messy stuff for you.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
sorry...didnt even noticed this feature exsits
|
|
|
|
|
I using System.Collections.HashTable to keep some information about my database.
The information that i collect in my HashTable is -
1. string ( as the key )
2. other string ( as the value )
my problem is that i want to scan the HashTable and when the value string is equal to some parameter i want to stop my scan and check the string key value.
How can i do it ?
Thanks for the help.
|
|
|
|
|
By iterating over the Keys collection.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can iterate the keys collection, and then retrieve and check the value for each key, reacting when you find your sought after value.
|
|
|
|
|
Hi friends........I've created a database application using C# and MS-Access........& the database part is working fine.........now is it possible to print the report directly to a PDF file from an Access database instead of using Crystal Report..........pls reply back asap..........THANKS
Thanks
|
|
|
|
|
Yes, you can buy a PDF library and use it to generate PDFs
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi All,
I have timespan object:
TimeSpan ts= new TimeSpan(0, 72, 1);
when i say :
MessageBox.Show(ts.ToString());
then i get: 01:12:02
What is that means?? 1 days, 12 hours and 2 minutes???
Thanx.
|
|
|
|
|
You're using this constructor:
public TimeSpan(int hours, int minutes, int seconds);
so you've created a timespan object for 72 minutes and 1 second.
which just happens to be exactly 1 hour, 12 minutes and 1 second.
(I'm assuming you've mistyped your output. it's 1 second, not 2)
KamarBand wrote: then i get: 01:12:02
Simon
|
|
|
|
|
Can Anyone Help
How to Remove the Duplicate Key(Repeated data) in CSV or Excel file using C# .
|
|
|
|
|
Iterate through the entries. Locate the duplicate. Remove it. Save the file.
You could locate it by adding all the entries to the collection, and checking for a clash with .ContainsKey each time.
Simon
|
|
|
|
|
|
is it a duplicate row or a duplicate entry in the "key" field?
If it's the latter maybe that attribute needs to be combined with another to form the key for the table
|
|
|
|
|
hi
in my solution, i created a table adapter and set select,insert,update,delete actions to my own stored procedures, then for add row, write the following code :
FrmCategory frm = new FrmCategory(false, false);
DsStack.CategoriesRow newRow = this.dt.NewCategoriesRow();
Session.SaveInSession("newCategory", newRow);
if (frm.ShowDialog() == DialogResult.OK)
{
newRow = Session.LoadFromSession("newCategory") as DsStack.CategoriesRow;
this.dt.Rows.Add(newRow);
this.adapter.Update(this.dt);
}
When my table in database is empty :
the first row add to table successfully, but the second row has not been add to database and the following error has shown me :
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
where does my problem and how to solve it ?
thanks
|
|
|
|
|
check your stored procedures!
Strahil Shorgov
|
|
|
|
|
Your Update method waiting for 1 record to be updated, but your update sp doesn't update any row.
Check you sp manually, sent the same values by parameter and watch the results.
|
|
|
|