?
Solved

Serialization alternatives/options.

Posted on 2003-03-09
5
Medium Priority
?
232 Views
Last Modified: 2011-09-20
I'm looking into creating an email client with C#. I want all the data stored in one file, but don't want to have to use a seperate data source (Access DB, SqlServer, etc).  I'm leary about using the standard serialization, because it would seem that everytime something is changed (new messages, message moved, etc), i would have to rewrite the file (i may be wrong on this).  In the event that say, new mail has been retrieved, and the program was closed abnormally (prior to a save), these new messages would be lost.  I liked the idea of the IStorage interface in C++, and was wondering if there was any equivalent in C#. I also looked into using XML, but this would seem to store everything in plain text.  Can anyone offer any insights into any possible storage options?

Thanks,
Joe Krill
0
Comment
Question by:jkrill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Pickle
ID: 8099684
If you are looking to store emails, XML would be an ideal storage medium.

1. All email is plaintext, even attachements are UU or BinHex encoded to plaintext anyways.

2. All of the .NET data access components are backended by XML so you would still be able to use DataSets, DataTables, DataRows, etc...

I would hope that you don't expect your program to just die without any notice or chance to write to disk.  The only time I could see this happening is if they shut down the computer without closing your program.  But even MS Outlook will not let you shutdown your computer without first closing it.

If you just make sure that in the destructor of your main form or one of your main objects that you write the DataSet out to disk you should be just fine.  That destructor will still get called in the instance of almost any error or problem that your application may encounter.

Let me know if you have any, more-specific questions.
0
 
LVL 2

Author Comment

by:jkrill
ID: 8100183
XML would be perfect, except for the fact that I don't want the data stored in plain text on the disk.  Is XML capable of this?
0
 
LVL 1

Expert Comment

by:Pickle
ID: 8100469
Just do this to encrypt the xml as you write it out to disk:
     //Create the file stream to handle the output file.
     FileStream fout = new FileStream(@"C:\mailstore.mls", FileMode.OpenOrCreate, FileAccess.Write);

     RijndaelManaged rm = new RijndaelManaged();
     
     byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
     byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

     //Create a CryptoStream, pass it the NetworkStream, and encrypt it with the Rijndael class.
     CryptoStream encStream = new CryptoStream(NetStream, rm.CreateEncryptor(Key, IV), CryptoStreamMode.Write);
 
     myDataSet.WriteXml(encStream);
 
     encStream.Close();  
     fout.Close();

You can just do this backwards to pull it back into a DataSet...

If you want more info on the Key and IV look up RijndaelManaged in the Visual Studio help.
0
 
LVL 1

Accepted Solution

by:
Pickle earned 800 total points
ID: 8100488
Sorry, screwed up on one of the lines, I was using this code previously to encrypt data over a network connection.  This should work:

   //Create the file stream to handle the output file.
    FileStream fout = new FileStream(@"C:\mailstore.mls", FileMode.OpenOrCreate, FileAccess.Write);

    RijndaelManaged rm = new RijndaelManaged();
   
    byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
    byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

    //Create a CryptoStream, pass it the FileStream, and encrypt it with the Rijndael class.
    CryptoStream encStream = new CryptoStream(fout, rm.CreateEncryptor(Key, IV), CryptoStreamMode.Write);

    myDataSet.WriteXml(encStream);

    encStream.Close();  
    fout.Close();
0
 
LVL 2

Author Comment

by:jkrill
ID: 8100515
Perfect - exactly what I was looking for.  Thank You!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question