Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Greetings...

In advance i would like to thanks to all those who have viewed this question and tried to help me in achieving my task.

I felt that i should modify my question to include the objective of my Addin which would enable others to guide me through the process.

I am trying to create an Addin for Outlook 2007 in C# using Visual Studio 2010.

Below is the Task that I am trying to achieve.
1. Copy Data from an Application (entire data is in codes format, example as below)

1.TEST/TEST MR
2 XY 400 E 13NOV 2 CPHARN HK1 0630 0740 13NOV E SK/2EY42J
3 XY 413 L 15NOV 4 ARNCPH HK1 2120 2230 15NOV E SK/2EY42J

2. Convert the above data to understandable format for layman. (example as below)
Carrier		Flight	Class	Dep.Date	Day	From				To			Status	Dep.Time	Arr.Time	Arr.Date
XYZ Airlines 	 400	E	13NOV		Tue	Copenhagen - Denmark	Stockholm - Sweden	Used	0630	0740	13NOV
XYZ Airlines 	 413	L	15NOV		Thu	Stockholm - Sweden	Copenhagen - Denmark	Used	2120	2230	15NOV


3. Paste the converted data on the current location of cursor in the email with just a click of button on the ribbon of outlook 2007.

The main challenge that i am facing is that i have a large amount of Data (IATA 3 Letter Airport Code and there respective Airport name) the data stretches to about 10K records.

I need help to know how can i include this data in my c# code instead of saving the data in an external source like excel, SQL, etc.

Your help/assistance in this would be really grateful.

Wahed.
Posted
Updated 13-Nov-12 7:58am
v2

You have to realize the trade off between hardcoding data (faster speed, but only up to a certain cap) vs external (can be update easily).

Given your question, I don't think it involves any SQL at all, CSV files should be sufficient.
 
Share this answer
 
v2
Comments
Jason Gleim 10-Nov-12 21:58pm    
Given that the data won't change very often, you might want to put it into an XML file. Then you could read it into a collection of objects in code and use linq to search the data very fast. You can include the xml file in the application setup.

You could also do a web request on a background thread to check for an updated file at a given URL and pull it down if it finds one available. Or, pull down the original file that way... that way each client starts with a current copy... IF you can count on Internet access.
wahed2102 10-Nov-12 23:52pm    
Looks interesting.

Can you please help me out with an example or point me to one.

Thnaks
So here is a utility class I use a lot to serialize and deserialize objects into and out of xml files:
C#
/// <summary>
/// Utility class to help store and retrieve objects into and out of an XML file.
/// </summary>
    public static class StorageManager<t>
    {
        public static void Store(string filename, T obj, FileMode mode)
        {
            try
            {
                FileStream fileStream = new FileStream(filename, mode);
                using (fileStream)
                {

                    DataContractSerializer serializer = new DataContractSerializer(typeof(T));
                    serializer.WriteObject(fileStream, obj);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(">>> STORAGE FATAL ERROR - " + ex.Message + " <<<");
            }
        }
        public static T Retrieve(string filename)
        {
            try
            {
                T obj = default(T);
                if (File.Exists(filename))
                {
                    using (FileStream fileStream = new FileStream(filename, FileMode.Open))
                    {
                        DataContractSerializer serializer = new DataContractSerializer(typeof(T));
                        obj = (T)serializer.ReadObject(fileStream);
                    }
                }
                return obj;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(">>> ISO STORAGE FATAL ERROR - " + ex.Message + " <<<");
                return default(T);
            }
        }
    }</t>


To use this class, you need to create a class that holds the object you want to serialize. Something like this:
C#
/// <summary>
/// Class to hold a group of sensor readings taken at the same time that we will save out to XML
/// </summary>
[Serializable]
public class DataPoint
{
    public DateTime SampleTime;
    public string SampleName;
    public string SampleDataType;
    public string SampleValue;
}


Calling the storage manager to save a collection of DataPoints is pretty easy:
C#
StorageManager<Collection<DataPoint>>.Store(@"C:\temp\data.xml", _collectionOfDataPoints, FileMode.Append);


Retrieving the data is almost as easy:
C#
Collection<datapoint> collectionOfDataPoints = StorageManager<collection><datapoint>>.Retrieve(@"C:\temp\data.xml");</datapoint></collection></datapoint>


There are some limits to this approach... for example, the objects must be serializable. There are some which are not (like Dictionary and Type) and you have to either change how you are storing them or otherwise work around it. You can get a lot more in depth with the DataContractSerializer if you really want to but I find it works great on its own if you keep the class you are serializing simple.

Once you have the objects in a collection, you can use a LINQ query to find what you want. There are tons of examples out there on Google for that so I wont go into it.

I would suggest that you create your airport code class in a class library. Then link it into your main project. You can also, then, link it into a management project where you would be able to enter the data (or otherwise import it) then use the storagehelper to serialize it out to an xml file that you can import into your app with the storage manager class. This way you have a behind-the-scenes app which will allow you to manage the airport codes XML file while your main program will simply consume that data into an in-memory collection which can be queried with LINQ.

As for updating the file using a web site, it can be as simple as uploading the file to a web site then having your app hit that URL and download the file. Again, there are lots of examples on how to form a web request and download a file into your app using a webclient or a stream.

Just remember that if this is running on Vista or higher, you can't save the file into the app directory. You will have to save it into the AppData folder which you can easily get from the Environment namespace.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900