using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Data;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
namespace TdoCodeGenerator.TdoGeneratorDom{
#region Enums
[Serializable()]
public enum XmlLanguage
{
VbNet,
CSharpNet
}
[Serializable()]
public enum GenerationModeEnum
{
All,
SelectionOnly
}
#endregion Enums
#region TdoProjectSettings Class
[Serializable()]
public class TdoProjectSettings
{
#region Fields
[NonSerialized()]
private TdoProjectSource fSource;
[NonSerialized()]
private TdoProjectDestination fDestination;
[NonSerialized()]
internal bool fModified;
#endregion Fields
#region Constructors
public TdoProjectSettings()
{
this.fSource = new TdoProjectSource();
this.fDestination = new TdoProjectDestination();
this.fModified = false;
}
#endregion Constructors
#region Properties
public TdoProjectSource Source
{
get
{
return fSource;
}
set
{
this.fSource = value;
}
}
public TdoProjectDestination Destination
{
get
{
return fDestination;
}
set
{
this.fDestination = value;
}
}
public bool Modified
{
get
{
bool modified = this.fModified;
modified |= this.Source.Modified;
modified |= this.Destination.Modified;
return modified;
}
}
#endregion Properties
}
#endregion TdoProjectSettings Class
#region TdoProjectSource Class
[Serializable()]
public class TdoProjectSource
{
#region Fields
[NonSerialized()]
private string fDataBase;
[NonSerialized()]
private string fServer;
[NonSerialized()]
private bool fIntegratedSecurity;
[NonSerialized()]
private string fUserName;
[NonSerialized()]
private string fPassword;
[NonSerialized()]
internal bool fModified;
#endregion Fields
#region Constructors
public TdoProjectSource()
{
this.fServer = String.Empty;
this.fDataBase = String.Empty;
this.fIntegratedSecurity = true;
this.fUserName = null;
this.fPassword = null;
this.fModified = false;
}
#endregion Constructors
#region Properties
public string Server
{
get
{
return this.fServer;
}
set
{
if (this.fServer != value) this.fModified = true;
this.fServer = value;
}
}
public bool IntegratedSecurity
{
get
{
return this.fIntegratedSecurity;
}
set
{
if (this.fIntegratedSecurity != value) this.fModified = true;
this.fIntegratedSecurity = value;
if (this.fIntegratedSecurity)
{
this.fUserName = null;
this.fPassword = null;
}
}
}
public string DataBase
{
get
{
return this.fDataBase;
}
set
{
if (this.fDataBase != value) this.fModified = true;
this.fDataBase = value;
}
}
public string UserName
{
get
{
return this.fUserName;
}
set
{
if (this.fUserName != value) this.fModified = true;
this.fUserName = value;
if (value != null) this.fIntegratedSecurity = false;
}
}
public string Password
{
get
{
return this.fPassword;
}
set
{
if (this.fPassword != value) this.fModified = true;
this.fPassword = value;
if (value != null) this.fIntegratedSecurity = false;
}
}
public string ConnectionString
{
get
{
string connectionString = string.Empty;
String datasource = String.Empty;
if (!String.IsNullOrEmpty(this.fServer))
{
datasource = this.fServer;
}
string database = "master";
if (!String.IsNullOrEmpty(this.fDataBase))
database = this.fDataBase;
string security = String.Empty;
if (this.fIntegratedSecurity)
{
security = "Integrated Security=SSPI";
}
else
{
security = String.Format("User Id={0};Password={1}", this.fUserName, this.fPassword);
}
connectionString = string.Format("Data Source={0};Initial Catalog={1};{2};Connection Timeout={3}", datasource, database, security,TdoCodeGenerator.Properties.Settings.Default.SQLServerCommandTimeOut);
return connectionString;
}
}
public bool Modified
{
get
{
return this.fModified;
}
}
#endregion Properties
}
#endregion TdoProjectSource Class
#region TdoProjectDestination Class
[Serializable()]
public class TdoProjectDestination
{
#region Fields
[NonSerialized()]
private XmlLanguage fLanguage;
[NonSerialized()]
private bool fCreateOneFileForClass;
[NonSerialized()]
private string fBaseNameSpace;
[NonSerialized()]
private string fXmlRootNameSpace;
[NonSerialized()]
private string fOutputFolder;
[NonSerialized()]
internal bool fModified;
private GenerationModeEnum fGenerationMode;
#endregion Fields
#region Constructors
public TdoProjectDestination()
{
this.fBaseNameSpace = String.Empty;
this.fCreateOneFileForClass = false;
this.fLanguage = XmlLanguage.CSharpNet;
this.fOutputFolder = String.Empty;
this.fXmlRootNameSpace = String.Empty;
this.fModified = false;
this.fGenerationMode = GenerationModeEnum.All;
}
#endregion Constructors
#region Properties
public bool Modified
{
get
{
return this.fModified;
}
}
public XmlLanguage Language
{
get
{
return this.fLanguage;
}
set
{
if (this.fLanguage != value) this.fModified = true;
this.fLanguage = value;
}
}
public bool CreateOneFileForClass
{
get
{
return this.fCreateOneFileForClass;
}
set
{
if (this.fCreateOneFileForClass!=value) this.fModified=true;
this.fCreateOneFileForClass = value;
}
}
public string BaseNameSpace
{
get
{
return this.fBaseNameSpace;
}
set
{
if (this.fBaseNameSpace != value) this.fModified = true;
this.fBaseNameSpace = value;
}
}
public string XmlRootNameSpace
{
get
{
return this.fXmlRootNameSpace;
}
set
{
if (this.fXmlRootNameSpace != value) this.fModified = true;
this.fXmlRootNameSpace = value;
}
}
public string OutputFolder
{
get
{
return this.fOutputFolder;
}
set
{
if (this.fOutputFolder != value) this.fModified = true;
this.fOutputFolder = value;
}
}
public GenerationModeEnum GenerationMode
{
get
{
return this.fGenerationMode;
}
set
{
if (this.fGenerationMode != value) this.fModified = true;
this.fGenerationMode = value;
}
}
#endregion Properties
}
#endregion TdoProjectDestination Class
#region TdoData Class
[Serializable()]
public class TdoData
{
#region Fields
[NonSerialized()]
private TdoStringCollection fTables;
[NonSerialized()]
private TdoStringCollection fViews;
[NonSerialized()]
private TdoStringCollection fStoredProcedures;
[NonSerialized()]
private TdoStringCollection fTableValuedFunctions;
[NonSerialized()]
private TdoStringCollection fScalarValuedFunctions;
internal bool fModified;
#endregion Fields
#region Constructors
public TdoData()
{
this.fTables = new TdoStringCollection();
this.fViews = new TdoStringCollection();
this.fStoredProcedures = new TdoStringCollection();
this.fTableValuedFunctions = new TdoStringCollection();
this.fScalarValuedFunctions = new TdoStringCollection();
this.fModified = false;
}
#endregion Constructors
#region Properties
public bool Modified
{
get
{
bool modified = this.fModified;
modified |= this.fTables.Modified;
modified |= this.fViews.Modified;
modified |= this.fStoredProcedures.Modified;
modified |= this.fTableValuedFunctions.Modified;
modified |= this.fScalarValuedFunctions.Modified;
return modified;
}
}
public TdoStringCollection Tables
{
get
{
return this.fTables;
}
set
{
this.fTables = value;
}
}
public TdoStringCollection Views
{
get
{
return this.fViews;
}
set
{
this.fViews = value;
}
}
public TdoStringCollection StoredProcedures
{
get
{
return this.fStoredProcedures;
}
set
{
this.fStoredProcedures = value;
}
}
public TdoStringCollection TableValuedFunctions
{
get
{
return this.fTableValuedFunctions;
}
set
{
fTableValuedFunctions = value;
}
}
public TdoStringCollection ScalarValuedFunctions
{
get
{
return this.fScalarValuedFunctions;
}
set
{
this.fScalarValuedFunctions = value;
}
}
#endregion Properties
}
#endregion TdoData Class
#region TdoStringCollection
[Serializable()]
public class TdoStringCollection : StringCollection
{
#region Fields
[NonSerialized()]
internal bool fModified;
#endregion Fields
#region Constructors
public TdoStringCollection()
{
this.fModified = false;
}
#endregion Constructors
#region Properties
public bool Modified
{
get
{
return this.fModified;
}
}
#endregion Properties
#region Methods
public new int Add(string value)
{
this.fModified = true;
return base.Add(value);
}
public new void AddRange(string[] values)
{
this.fModified = true;
this.AddRange(values);
}
public new void Clear()
{
this.fModified = true;
base.Clear();
}
public new void Insert(int index, string value)
{
this.fModified = true;
base.Insert(index, value);
}
public new void Remove(string value)
{
this.fModified=true;
base.Remove(value);
}
public new void RemoveAt(int index)
{
this.fModified = true;
base.RemoveAt(index);
}
public new string this[int index]
{
get
{
return base[index];
}
set
{
if (base[index]!=value) this.fModified = true;
base[index] = value;
}
}
#endregion Methods
}
#endregion TdoStringCollection
#region TdoProjectClass Class
[Serializable()]
public class TdoProjectClass
{
#region Fields
[NonSerialized()]
private string fName;
[NonSerialized()]
private string fPath;
[NonSerialized()]
internal string fOldPath;
[NonSerialized()]
private TdoProjectSettings fSettings;
[NonSerialized()]
private TdoData fData;
[NonSerialized()]
internal bool fModified;
#endregion Fields
#region Constructors
public TdoProjectClass()
{
this.fName = String.Empty;
this.fPath = String.Empty;
this.fSettings = new TdoProjectSettings();
this.Data = new TdoData();
this.fModified = false;
}
#endregion Constructors
#region Properties
[XmlAttribute()]
public string Name
{
get
{
return this.fName;
}
set
{
if (this.fName != value)
{
this.fName = value;
this.fModified = true;
this.Path = String.Empty;
}
}
}
public TdoProjectSettings Settings
{
get
{
return this.fSettings;
}
set
{
this.fSettings = value;
}
}
public TdoData Data
{
get
{
return this.fData;
}
set
{
this.fData = value;
}
}
[XmlIgnore()]
public string Path
{
get
{
return this.fPath;
}
set
{
if (this.fPath != value)
{
this.fModified = true;
this.fOldPath = this.fPath;
this.fPath = value;
}
}
}
public bool Modified
{
get
{
bool modified = this.fModified;
modified |= this.Settings.Modified;
modified |= this.Data.Modified;
return modified;
}
}
#endregion Properties
#region Methods
/// <summary>
/// Renames the specified new name.
/// </summary>
/// <param name="newName">The new name.</param>
public void Rename(string newName)
{
this.Name = newName;
}
/// <summary>
/// Saves this instance.
/// </summary>
public void Save()
{
if (!this.Modified) return;
string absPath = this.Settings.Destination.OutputFolder;
this.Settings.Destination.OutputFolder = TdoCodeGenerator.Generator.TdoDiscovery.getRelativePath(System.IO.Path.GetDirectoryName(this.Path), absPath);
XmlSerializer ser = new XmlSerializer(typeof(TdoProjectClass));
StreamWriter streamWriter = new StreamWriter(this.fPath);
ser.Serialize(streamWriter, this);
streamWriter.Close();
this.Settings.Destination.OutputFolder = absPath;
this.fModified = false;
this.Data.fModified = false;
this.Settings.fModified = false;
this.Data.Tables.fModified = false;
this.Data.Views.fModified = false;
this.Data.StoredProcedures.fModified = false;
this.Data.TableValuedFunctions.fModified = false;
this.Data.ScalarValuedFunctions.fModified = false;
this.Settings.Source.fModified = false;
this.Settings.Destination.fModified = false;
}
#endregion Methods
#region Static Methods
public static TdoProjectClass Open(string path)
{
XmlSerializer ser = new XmlSerializer(typeof(TdoProjectClass));
StreamReader streamReader = new StreamReader(path);
TdoProjectClass result = (TdoProjectClass)ser.Deserialize(streamReader);
streamReader.Close();
result.Path = path;
result.Settings.Destination.OutputFolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), result.Settings.Destination.OutputFolder);
if (result.Settings.Destination.OutputFolder.EndsWith("\\.\\"))
result.Settings.Destination.OutputFolder = result.Settings.Destination.OutputFolder.Substring(0, result.Settings.Destination.OutputFolder.Length - 3);
result.fModified = false;
result.Data.fModified = false;
result.Settings.fModified = false;
result.Data.Tables.fModified = false;
result.Data.Views.fModified = false;
result.Data.StoredProcedures.fModified = false;
result.Data.TableValuedFunctions.fModified = false;
result.Data.ScalarValuedFunctions.fModified = false;
result.Settings.Destination.fModified = false;
result.Settings.Source.fModified = false;
return result;
}
#endregion Static Methods
}
#endregion TdoProjectClass Class
}
|