tags:

views:

16

answers:

2

Hello EveryOne,

I am using standalon application and I am using error reporting.

Once I am online there is no problem, but when I am in offline so how I can make provision

to store the error for the offline user.

And Once user will comes online how I will send this error messages..

I am using WPF Standalon Application.

Thanks...

A: 

Since you're app is offline, I assume that there is a component that is online? Have this component record the errors. When the app comes back on line it should query for them.

Preet Sangha
Right, but still I am confuge how i can handle this situation.
Jitendra Jadav
What is the confusing part.
Preet Sangha
A: 

You might want to look into serialization.

When you are offline, you want to serialize these "error logs" onto disk. Here are some extensions to serialize the data.

public static void Serialize(this object o, string fileName)
{
    Stream stream = File.Open(fileName, FileMode.Create);
    var serializer = new BinaryFormatter();
    serializer.Serialize(stream, o);
    stream.Close();
}

public static T Deserialize<T>(string fileName)
{
    T objectToDeSerialize;
    using (Stream stream = File.Open(fileName, FileMode.Open))
    {
        var serializer = new BinaryFormatter();
        objectToDeSerialize = (T) serializer.Deserialize(stream);
        stream.Close();
    }
    return objectToDeSerialize;
}

So you would have a Serializable class representing your "errors".

[Serializable]
public class Error
{
    public string Log { get; set; }
    // other properties...

    public Error(string log)
    {
        Log = log;
    }
}

Now all you need to do is write the errors to some file when you need to store the offline errors.

Error offlineError = new Error("Internet is not connected.");
offlineError.Serialize("inetError.err");

To read back the error for when you do become online again, just use this.

Error error = SerializableHelper.Deserialize<Error>("inetError.err");

enjoy.

Tri Q