unit Unit3;

interface

uses
  System.SysUtils, System.Classes, Sparkle.HttpServer.Module, System.IOUtils,
  WinApi.Windows,
  Sparkle.HttpServer.Context, Sparkle.Comp.Server,
  Aurelius.Engine.DatabaseManager, Entities, Aurelius.Engine.ObjectManager,
  Sparkle.Comp.HttpSysDispatcher, Aurelius.Drivers.Interfaces,
  Aurelius.Comp.Connection, XData.Comp.ConnectionPool, XData.Server.Module,
  XData.Comp.Server, Aurelius.Drivers.MSSQL, Sparkle.Comp.CorsMiddleware,
  Aurelius.Drivers.SQLite, Sparkle.Module.Static, Sparkle.Comp.StaticServer;

type
  TServerContainer = class(TDataModule)
    SparkleHttpSysDispatcher: TSparkleHttpSysDispatcher;
    XDataServer: TXDataServer;
    XDataConnectionPool: TXDataConnectionPool;
    AureliusConnection: TAureliusConnection;
    XDataServerCORS: TSparkleCorsMiddleware;
    SparkleStaticServer1: TSparkleStaticServer;
    procedure DataModuleCreate(Sender: TObject);
  end;

var
  ServerContainer: TServerContainer;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

procedure TServerContainer.DataModuleCreate(Sender: TObject);
var
  B: TBlobs;
  M: TObjectManager;
  Conn: IDBConnection;
  RS: TResourceStream;
begin
  Conn := XDataConnectionPool.GetPoolInterface.GetConnection;
  TDatabaseManager.Update(Conn);
  M := TObjectManager.Create(Conn);
  B := M.Find<TBlobs>.Take(1).UniqueResult;
  if B = nil then
  begin
    B := TBlobs.Create;
    B.Name := 'Blob1';
    B.Description.AsUnicodeString := 'This is blob content';
    RS := TResourceStream.Create(HInstance, 'TMSLOGO', RT_RCDATA);
    try
      B.Photo.LoadFromStream(RS);
    finally
      RS.Free;
    end;
    M.Save(B);
  end;
  M.Free;

  SparkleStaticServer1.RootDir := TPath.Combine(
    TPath.GetDirectoryName(ParamStr(0)), '..\..\images');
  SparkleHttpSysDispatcher.Active := True;
end;

end.
