#if ADVANTAGE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Advantage.Data.Provider;
using System.Net;
namespace Sdaleo.Systems.Advantage
{
///
/// Handles Advantage, to be
/// used by all our Advantage Functions
///
public class AdvantageCredential : IComparable, ICloneable, IConnectDb, IClearConnectionPool
{
public enum ServerType
{
REMOTE,
LOCAL,
REMOTE_LOCAL
}
#region IConnectDb
///
/// Let Callers know this is a Advantage Connection Object
///
public DBSystem DBType { get { return DBSystem.ADVANTAGE; } }
///
/// Check to see if the Credential Object consists of valid input
///
public bool IsValid
{
get
{
if (!ValidationConsts.IsValidFileNameNPath(DataSource))
return false;
if (!ValidationConsts.Generic.IsValidServerName(User))
return false;
return true;
}
}
///
///
///
public string ConnectionString { get { return _UDL.ConnectionString; } }
///
/// Advantage the File Name and Path as the Datasource
///
public string DataSource { get { return _UDL.DataSource; } }
///
/// Advantage doesn't use User
///
public string User { get { return _UDL.Username; } }
///
/// Advantage Server Type
///
public ServerType Type
{
get
{
try
{
ServerType type = (ServerType) Enum.Parse(typeof(ServerType), _UDL.ServerType.Replace('|','_'));
return type;
}
catch (Exception) { /* ignore */ }
return ServerType.LOCAL;
}
}
///
/// Advantage doesn't really support DBMS like behaviors
///
public bool SupportsDBMS { get { return false; } }
///
/// Advantage doesn't support DBMS like behaviors
///
public IamDBMS DBMS { get { return null; } }
///
/// Advantage * not implemented *
///
public bool SupportsTimeouts { get { return false; } }
///
/// Advantage * not implemented *
///
public IsupportTimeouts Timeouts { get { return null; } }
#endregion
private UDL _UDL = null;
#region AdvantageCredential Credential Constructors
///
/// Create a Advantage Connection from an UDL Object
///
///
internal AdvantageCredential(UDL udl)
{
if (udl != null)
_UDL = udl;
}
///
/// Create a Advantage Connection
///
public AdvantageCredential(string FileNameNPathInclUNCPath, string UserID, string Password, ServerType type)
{
string serverType = type.ToString().ToUpper().Replace('_', '|');
if (!String.IsNullOrEmpty(FileNameNPathInclUNCPath) && FileNameNPathInclUNCPath.StartsWith(@"\\"))
{
int n = FileNameNPathInclUNCPath.IndexOf(@"\", @"\\".Length);
if(n != -1)
{
IPAddress ipaddress;
string hostname = FileNameNPathInclUNCPath.Substring(@"\\".Length, n - @"\\".Length);
if(IPAddress.TryParse(hostname, out ipaddress))
{
serverType = ServerType.REMOTE.ToString();
if (!hostname.Contains(":"))
{
// Add Port Number to Ip Address * Required by Advantage * default port is 6262
FileNameNPathInclUNCPath = FileNameNPathInclUNCPath.Replace(hostname, hostname + ":6262");
}
}
}
}
_UDL = new UDL(FileNameNPathInclUNCPath, UserID, Password, serverType);
}
#endregion
#region ICloneable Members
public object Clone()
{
AdvantageCredential credential = new AdvantageCredential((UDL)this._UDL.Clone());
return credential;
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
AdvantageCredential otherCredential = obj as AdvantageCredential;
if (otherCredential != null)
{
int nCompare = _UDL.CompareTo(otherCredential._UDL);
return nCompare;
}
else
{
throw new ArgumentException("Object is not a AdvantageCredential");
}
}
#endregion
#region IClearConnectionPool Members
public void ClearConnectionPool(IConnectDb credential)
{
AdsConnection.FlushConnectionPool(credential.ConnectionString);
}
#endregion
}
}
#endif