//*********************************************************************
// //
// SQL Power Injector 1.2 Copyright (c) 2006-2007 Francois Larouche //
// //
// Author : francois.larouche@sqlpowerinjector.com //
// Web Site: www.sqlpowerinjector.com //
// //
//*******************************************************************//
using System;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
namespace SQLPowerInjector{
/// <summary>
/// Summary description for Session.
/// </summary>
[XmlRootAttribute("SQL_Power_Injector_Settings", Namespace="", IsNullable=false)]
public class SPinjSettings
{
#region Members
#region Private
private bool _useCookie;
private bool _autoDetectEncoding;
private uint _startingLength;
private uint _startingCount;
private byte _numberThreads;
private bool _characterSetCaseInsensitive;
private int _htmlMessageLength;
private bool _trapErrorString;
private bool _useProxy;
private ushort _ttInitialDelay;
private ushort _ttAutoPopDelay;
private Referer_Type _refererType;
private string _manualRefererUri;
private ushort _userAgentSelectedIndex;
private string _proxyAddress;
private ushort _proxyPort;
#endregion
#region Constants
const uint STARTING_LENGTH_MAX = 1000000;
const uint STARTING_COUNT_MAX = 1000000;
const byte NUMBER_THREADS_MAX = 50;
const int HTML_MESSAGE_LENGTH_MAX = 100000000;
const int TOOLTIP_INITIAL_DELAY_MAX = 32000;
const int TOOLTIP_AUTOPOP_DELAY_MAX = 32000;
const ushort PROXY_PORT_MAX = 65535;
#endregion
#endregion
#region Public Enums
public enum Referer_Type
{
None = 0,
Itself = 1,
Manual = 2
}
#endregion
#region Constructor
public SPinjSettings()
{
_useCookie = false;
_autoDetectEncoding = true;
_startingLength = 50;
_startingCount = 100;
_numberThreads = 1;
_characterSetCaseInsensitive = false;
_htmlMessageLength = 256;
_trapErrorString = false;
_useProxy = false;
_ttInitialDelay = 500;
_ttAutoPopDelay = 32000;
_refererType = Referer_Type.Itself;
_manualRefererUri = "";
_userAgentSelectedIndex = 0;
_proxyAddress = "";
_proxyPort = 8080;
}
#endregion
#region Public Attributes
public bool UseCookie
{
get { return _useCookie; }
set { _useCookie = value; }
}
public bool AutoDetectEncoding
{
get { return _autoDetectEncoding; }
set { _autoDetectEncoding = value; }
}
public uint StartingLength
{
get { return _startingLength; }
set
{
if(value <= STARTING_LENGTH_MAX)
_startingLength = value;
else
_startingLength = 50;
}
}
public uint StartingCount
{
get { return _startingCount; }
set
{
if(value <= STARTING_COUNT_MAX)
_startingCount = value;
else
_startingCount = 100;
}
}
public byte NumberThreads
{
get { return _numberThreads; }
set
{
if(value <= NUMBER_THREADS_MAX)
_numberThreads = value;
else
_numberThreads = 1;
}
}
public bool CharacterSetCaseInSensitive
{
get { return _characterSetCaseInsensitive; }
set { _characterSetCaseInsensitive = value; }
}
public int HtmlMessageLength
{
get { return _htmlMessageLength; }
set
{
if(value <= HTML_MESSAGE_LENGTH_MAX)
_htmlMessageLength = value;
else
_htmlMessageLength = 256;
}
}
public bool TrapErrorString
{
get { return _trapErrorString; }
set { _trapErrorString = value; }
}
public bool UseProxy
{
get { return _useProxy; }
set { _useProxy = value; }
}
public ushort TooltipInitialDelay
{
get { return _ttInitialDelay; }
set
{
if(value <= TOOLTIP_INITIAL_DELAY_MAX)
_ttInitialDelay = value;
else
_ttInitialDelay = 500;
}
}
public ushort TooltipAutoPopDelay
{
get { return _ttAutoPopDelay; }
set
{
if(value <= TOOLTIP_AUTOPOP_DELAY_MAX)
_ttAutoPopDelay = value;
else
_ttAutoPopDelay = 50000;
}
}
[XmlElementAttribute("RefererType", typeof(Referer_Type))]
public Referer_Type RefererType
{
get { return _refererType; }
set { _refererType = value; }
}
public string ManualRefererUri
{
get { return _manualRefererUri; }
set { _manualRefererUri = value; }
}
public string ProxyAddress
{
get { return _proxyAddress; }
set { _proxyAddress = value; }
}
public ushort ProxyPort
{
get { return _proxyPort; }
set
{
if(value <= PROXY_PORT_MAX)
_proxyPort = value;
else
_proxyPort = 8080;
}
}
public ushort UserAgentSelectedIndex
{
get { return _userAgentSelectedIndex; }
set
{
if(value >= 0)
_userAgentSelectedIndex = value;
else
_userAgentSelectedIndex = 0;
}
}
#endregion
public bool SaveSettings(SPinjSettings SettingsToSave, string XMLFileName)
{
bool settingsSavedSuccessfully = false;
settingsSavedSuccessfully = Utilities.SerializeXML(SettingsToSave, XMLFileName);
return settingsSavedSuccessfully;
}
public static SPinjSettings LoadSettings(string XMLFileName)
{
return LoadSerializedSettings(XMLFileName);
}
private static SPinjSettings LoadSerializedSettings(string XMLFileName)
{
SPinjSettings loadedSettings = new SPinjSettings();
TextReader txrTextReader = null;
try
{
XmlSerializer xserDocumentSerializer = new XmlSerializer(typeof(SPinjSettings));
txrTextReader = new StreamReader(XMLFileName);
loadedSettings = (SPinjSettings)xserDocumentSerializer.Deserialize(txrTextReader);
}
catch(InvalidOperationException ex)
{
throw(new MyException(ex.Message, ex.InnerException));
}
catch(Exception ex)
{
throw(ex);
}
finally
{
//Make sure to close the file even if an exception is raised...
if (txrTextReader != null)
txrTextReader.Close();
}
return loadedSettings;
}
}
}
|