Namespace webservicestudio
{
Using system;
Using system. componentmodel;
Using system. IO;
Using system. reflection;
Using system. xml. serialization;
[Typeconverter (typeof (expandableobjectconverter)] // provides a type converter that converts extensible objects to other forms of representation.
Public class configuration
{
Private customhandler [] dataeditors;
Private invokeproperties invokesettings = new invokeproperties ();
Private Static configuration masterconfig = NULL;
Private customhandler [] proxyproperties;
Private customhandler [] typeconverters;
Private uiproperties uisettings;
Private wsdlproperties wsdlsettings;
Public configuration copy ()
{
Memorystream stream = new memorystream ();
Xmlserializer serializer = new xmlserializer (typeof (configuration ));
Serializer. serialize (Stream) stream, masterconfig );
Stream. Position = 0l;
Return (serializer. deserialize (Stream) as configuration );
}
Private Static string getconfigfilename ()
{
Return (assembly. getexecutingassembly (). Location + ". Options ");
}
Internal string [] getproxybasetypes ()
{
Customhandler [] proxyproperties = This. proxyproperties;
String [] strarray = new string [(proxyproperties! = NULL )? (Proxyproperties. Length + 1): 1];
Strarray [0] = "";
For (INT I = 1; I <strarray. length; I ++)
{
Strarray [I] = proxyproperties [I-1]. typename;
}
Return strarray;
}
Public static void loadmasterconfig ()
{
Try
{
Filestream stream = file. openread (getconfigfilename ());
Streamreader textreader = new streamreader (Stream );
Xmlserializer serializer = new xmlserializer (typeof (configuration ));
Masterconfig = serializer. deserialize (textreader) as configuration; // reverse instantiation, C # The best Function
Stream. Flush ();
Stream. Close ();
}
Catch
{
}
If (masterconfig = NULL)
{
Masterconfig = new configuration ();
}
If (masterconfig. dataeditors = NULL)
{
Masterconfig. dataeditors = new customhandler [0];
}
If (masterconfig. typeconverters = NULL)
{
Masterconfig. typeconverters = new customhandler [0];
}
If (masterconfig. wsdlsettings = NULL)
{
Masterconfig. wsdlsettings = new wsdlproperties ();
}
If (masterconfig. uisettings = NULL)
{
Masterconfig. uisettings = new uiproperties ();
}
}
Public static void savemasterconfig ()
{
Filestream stream = file. openwrite (getconfigfilename ());
Streamwriter writer = new streamwriter (Stream );
New xmlserializer (typeof (configuration). serialize (textwriter) writer, masterconfig); // save it to a file
Stream. setlength (stream. position );
Stream. Flush (); // refresh the cache to truly write data to the disk
Stream. Close ();
}
[Browsable (false)]
Public customhandler [] dataeditors
{
Get
{
Return this. dataeditors;
}
Set
{
This. dataeditors = value;
}
}
[Browsable (false)]
Public invokeproperties invokesettings
{
Get
{
Return this. invokesettings;
}
Set
{
This. invokesettings = value;
}
}
Internal static configuration masterconfig
{
Get
{
If (masterconfig = NULL)
{
Loadmasterconfig ();
}
Return masterconfig;
}
Set
{
Masterconfig = value;
Savemasterconfig ();
}
}
[Browsable (false)]
Public customhandler [] proxyproperties
{
Get
{
Return this. proxyproperties;
}
Set
{
This. proxyproperties = value;
}
}
[Browsable (false)]
Public customhandler [] typeconverters
{
Get
{
Return this. typeconverters;
}
Set
{
This. typeconverters = value;
}
}
Public uiproperties uisettings
{
Get
{
Return this. uisettings;
}
Set
{
This. uisettings = value;
}
}
Public wsdlproperties wsdlsettings
{
Get
{
Return this. wsdlsettings;
}
Set
{
This. wsdlsettings = value;
}
}
}
}