i have now also added at first only at my dasBlog an XmlSerializerFactory:

public

class XmlSerializerFactory

{

private XmlSerializerFactory(){}

private static Hashtable serializers = new Hashtable();

public static XmlSerializer GetSerializer(Type t)

{

XmlSerializer xs =

null;

lock(serializers.SyncRoot)

{

xs = serializers[t]

as XmlSerializer;

if(xs == null)

{

xs =

new XmlSerializer(t);

serializers.Add(t,xs);

}

}

return xs;

}

public static XmlSerializer GetSerializer(Type t, string s)

{

XmlSerializer xs =

null;

lock(serializers.SyncRoot)

{

xs = serializers[t]

as XmlSerializer;

if(xs == null)

{

xs =

new XmlSerializer(t, s);

serializers.Add(t,xs);

}

}

return xs;

}

}

and

i'm using the factory for example in the DataManager:

BlogCoreData LoadBlogCore()

{

BlogCoreData data;

string fullPath = ResolvePath("blogdata.xml");

if (File.Exists(fullPath))

{

using (StreamReader reader = new StreamReader(FileUtils.OpenForRead(fullPath)))

{

XmlNamespaceUpgradeReader upg =

new XmlNamespaceUpgradeReader( reader, "", Data.NamespaceURI );

//XmlSerializer ser = new XmlSerializer(typeof(BlogCoreData));

//data = (BlogCoreData)ser.Deserialize(upg);

XmlSerializer ser = XmlSerializerFactory.GetSerializer(

typeof(BlogCoreData));

lock(ser)

{

data = (BlogCoreData)ser.Deserialize(upg);

}

 

}

}

else

{

data =

new BlogCoreData();

SaveBlogCore(data);

}

return data;

}

i think it is faster now, but i will check this at first before the code will go to the cvs..

Comments


Comments are closed