unit TMS.ServerWizard.Configuration;

{$I bcl.inc}

interface

{$IFDEF DELPHIXE2_LVL}

uses
  TMS.ServerWizard.Types;

type
  TFileConfig = record
    ResourceName,
    UnitName : string;
  end;

  TProjectConfig = record
    Project,
    Server,
    Form,
    ConnectionModule : TFileConfig;
  end;

  TDataBaseDriverInfo = record
    UIName,
    ConnectionType,
    TypeName,
    DriverName,
    PreferredSQLDialect : string;
  end;

{$ifdef VER230} // XE2
  {$define XE2_OR_3}
{$endif}
{$ifdef VER240} // XE3
  {$define XE2_OR_3}
{$endif}

const
  // Note: Form resource names are automatically suffixed with FORM or UNIT
  // so define only the root name here.
  FileConfigs : array[TProjectKind] of TProjectConfig = (
    // pkVCL
    ( Project: (ResourceName: 'VCLPROJECTFILE'; UnitName: '');
      Server: (ResourceName: 'SERVER'; UnitName: 'Server');
      Form: (ResourceName: 'VCLFORM'; UnitName: 'MainForm');
      ConnectionModule: (ResourceName: 'CONNECTIONMODULE'; UnitName: 'ConnectionModule')),

    // pkFMX
    // Different sources based on XE2&3, or XE4+ - FMX changed, units changed,
    // form properties changed...
    {$ifdef XE2_OR_3}
      ( Project: (ResourceName: 'FMXXE2PROJECTFILE'; UnitName: '');
        Server: (ResourceName: 'SERVER'; UnitName: 'Server');
        Form: (ResourceName: 'FMXXE2FORM'; UnitName: 'MainFormFMX')),
    {$else}
      ( Project: (ResourceName: 'FMXPROJECTFILE'; UnitName: '');
        Server: (ResourceName: 'SERVER'; UnitName: 'Server');
        Form: (ResourceName: 'FMXFORM'; UnitName: 'MainFormFMX');
        ConnectionModule: (ResourceName: 'CONNECTIONMODULE'; UnitName: 'ConnectionModule')),
    {$endif}

    // pkService
    ( Project: (ResourceName: 'SERVICEPROJECTFILE'; UnitName: '');
      Server: (ResourceName: 'SERVER'; UnitName: 'Server');
      Form: (ResourceName: 'SERVICEFORM'; UnitName: 'ServiceModule');
      ConnectionModule: (ResourceName: 'CONNECTIONMODULE'; UnitName: 'ConnectionModule')),
    // pkConsole
    ( Project: (ResourceName: 'CONSOLEPROJECTFILE'; UnitName: '');
      Server: (ResourceName: 'SERVER'; UnitName: 'Server');
      Form: (ResourceName: ''; UnitName: '');
      ConnectionModule: (ResourceName: 'CONNECTIONMODULE'; UnitName: 'ConnectionModule'))
  );

  // Database drivers:
  DatabaseDrivers : array[0..16] of TDataBaseDriverInfo = (
    // Adapters
    ( UIName: 'Absolute Database'; ConnectionType: 'TABSDatabase'; TypeName: 'TAbsoluteDBConnectionAdapter'; DriverName: {Aurelius.Drivers.AbsoluteDB} 'AbsoluteDB'; PreferredSQLDialect: 'AbsoluteDB'; ),
    ( UIName: 'AnyDac'; ConnectionType: 'TADConnection'; TypeName: 'TAnyDacConnectionAdapter'; DriverName: 'AnyDac'; PreferredSQLDialect: ''; ),
    ( UIName: 'dbExpress'; ConnectionType: 'TSQLConnection'; TypeName: 'TDBExpressConnectionAdapter'; DriverName: 'dbExpress'; PreferredSQLDialect: ''; ),
    ( UIName: 'dbGo (ADO)'; ConnectionType: 'TADOConnection'; TypeName: 'TDbGoConnectionAdapter'; DriverName: 'dbGo'; PreferredSQLDialect: ''; ),
    ( UIName: 'Direct Oracle Access (DOA)'; ConnectionType: 'TOracleSession'; TypeName: 'TDoaConnectionAdapter'; DriverName: 'Doa'; PreferredSQLDialect: 'Oracle'; ),
    ( UIName: 'ElevateDB'; ConnectionType: 'TEDBDatabase'; TypeName: 'TElevateDBConnectionAdapter'; DriverName: 'ElevateDB'; PreferredSQLDialect: 'ElevateDB'; ),
    ( UIName: 'FIBPlus'; ConnectionType: 'TFIBDatabase'; TypeName: 'TFIBPlusConnectionAdapter'; DriverName: 'FIBPlus'; PreferredSQLDialect: 'Firebird'; ),
    ( UIName: 'FireDac'; ConnectionType: 'TFDConnection'; TypeName: 'TFireDacConnectionAdapter'; DriverName: 'FireDac'; PreferredSQLDialect: ''; ),
    ( UIName: 'IBObjects (IBO)'; ConnectionType: 'TIBODatabase'; TypeName: 'TIBObjectsConnectionAdapter'; DriverName: 'IBObjects'; PreferredSQLDialect: 'Firebird'; ),
    ( UIName: 'Interbase Express (IBX)'; ConnectionType: 'TIBDatabase'; TypeName: 'TIBExpressConnectionAdapter'; DriverName: 'IBExpress'; PreferredSQLDialect: 'Firebird'; ),
    ( UIName: 'NexusDB'; ConnectionType: 'TnxDatabase'; TypeName: 'TNexusDBConnectionAdapter'; DriverName: 'NexusDB'; PreferredSQLDialect: 'NexusDB'; ),
    ( UIName: 'SQL-Direct'; ConnectionType: 'TSDDatabase'; TypeName: 'TSQLDirectConnectionAdapter'; DriverName: 'SqlDirect'; PreferredSQLDialect: ''; ),
    ( UIName: 'UniDac'; ConnectionType: 'TUniConnection'; TypeName: 'TUniDacConnectionAdapter'; DriverName: 'UniDac'; PreferredSQLDialect: ''; ),
    ( UIName: 'Unified Interbase (UIB)'; ConnectionType: 'TUIBDatabase'; TypeName: 'TUIBConnectionAdapter'; DriverName: 'UIB'; PreferredSQLDialect: 'Firebird'; ),
    ( UIName: 'TMS RemoteDB Server'; ConnectionType: 'TRemoteDBDatabase'; TypeName: 'TRemoteDBConnectionAdapter'; DriverName: 'RemoteDB'; PreferredSQLDialect: ''; ),
    // Drivers
    ( UIName: 'SQLite'; ConnectionType: ''; TypeName: 'TSQLiteNativeConnectionAdapter'; DriverName: 'SQLite'; PreferredSQLDialect: 'SQLite'; ),
    ( UIName: 'MS SQL Server (MSSQL)'; ConnectionType: ''; TypeName: 'TMSSQLConnection'; DriverName: 'MSSQL'; PreferredSQLDialect: 'MSSQL'; )
  );

  // SQL dialect name and unit are the same
  SQLDialects : array[0..11] of string = (
    'AbsoluteDB',
    'DB2',
    'ElevateDB',
    'Firebird',
    'Firebird3',
    'Interbase',
    'MSSQL',
    'MySql',
    'NexusDB',
    'Oracle',
    'PostgreSQL',
    'SQLite'
  );

  function GetDataBaseDriverTypeFromUI(const DBUIName : string) : string;
  function GetPreferredSQLDialectForDatabase(const DBUIName : string) : string;
  function GetDriverNameForDatabaseUIName(const DBUIName : string) : string;
  function GetComponentTypeForDatabaseID(const DBID : string) : string;

{$ENDIF}

implementation

{$IFDEF DELPHIXE2_LVL}

uses
  System.SysUtils;

function GetDataBaseDriverTypeFromUI(const DBUIName : string) : string;
var
  I : Integer;
begin
  // Given a UI name, return the type
  for I := Low(DatabaseDrivers) to High(DatabaseDrivers) do
    if SameText(DatabaseDrivers[I].UIName, DBUIName) then
      Exit(DatabaseDrivers[i].TypeName);

  // Not found
//  assert(false);
  Result := '';
end;

function GetPreferredSQLDialectForDatabase(const DBUIName : string) : string;
var
  I : Integer;
begin
  // Given a UI name, return the type
  for I := Low(DatabaseDrivers) to High(DatabaseDrivers) do
    if SameText(DatabaseDrivers[I].UIName, DBUIName) then
      Exit(DatabaseDrivers[i].PreferredSQLDialect);

  // Not found - not an error
  Result := '';
end;

function GetDriverNameForDatabaseUIName(const DBUIName : string) : string;
var
  I : Integer;
begin
  // Given a UI name, return the type
  for I := Low(DatabaseDrivers) to High(DatabaseDrivers) do
    if SameText(DatabaseDrivers[I].UIName, DBUIName) then
      Exit(DatabaseDrivers[i].DriverName);

  // Not found - not an error
  Result := '';
end;

function GetComponentTypeForDatabaseID(const DBID : string) : string;
var
  I : Integer;
begin
  // Given a UI name, return the type
  for I := Low(DatabaseDrivers) to High(DatabaseDrivers) do
    if SameText(DatabaseDrivers[I].UIName, DBID) then
      Exit(DatabaseDrivers[i].ConnectionType);

  // Not found - not an error
  Result := '';
end;

{$ENDIF}

end.


