Guest User

Untitled

a guest
Feb 16th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.47 KB | None | 0 0
  1. program cbserver;
  2.  
  3. {$I Synopse.inc}
  4.  
  5. uses
  6.   {$I SynDprUses.inc}
  7.   Classes, SysUtils,
  8.   SynCommons, SynLog, mORMot, mORMotHttpServer, mORMotSQLite3, SynSQLite3Static, SynDB;
  9.  
  10. type
  11.  
  12.   { ICBService }
  13.  
  14.   ICBService = interface(IInvokable)
  15.     ['{2061324A-51C8-48FC-82CC-D21ECC3D16E1}']
  16.     function Test2: RawUTF8;
  17.   end;
  18.  
  19.   { TCBService }
  20.  
  21.   TCBService = class(TInjectableObjectRest, ICBService)
  22.     function Test2: RawUTF8;
  23.   end;
  24.  
  25. const
  26.   ROOT_NAME = 'root';
  27.   DEFAULT_PORT = '1044';
  28.  
  29. var
  30.   aServer: TSQLRestServer;
  31.   aHTTPServer: TSQLHttpServer;
  32.   aModel: TSQLModel;
  33.  
  34.   { TCBService }
  35.  
  36. function TCBService.Test2: RawUTF8;
  37. begin
  38.   Result := 'sss';
  39. end;
  40.  
  41. begin
  42. TInterfaceFactory.RegisterInterfaces([TypeInfo(ICBService)]);
  43.  
  44. with TSQLLog.Family do begin
  45.   Level := LOG_VERBOSE;
  46.   EchoToConsole := LOG_VERBOSE; // log all events to the console
  47. end;
  48. aModel := TSQLModel.Create([], ROOT_NAME);
  49. try
  50.   aServer := TSQLRestServerDB.Create(aModel, 'cbs.db3', false);
  51.   try
  52.     aServer.CreateMissingTables;
  53.     aServer.ServiceDefine(TCBService, [ICBService], sicShared);
  54.     aHTTPServer := TSQLHttpServer.Create(AnsiString(DEFAULT_PORT), [aServer], '+', useHttpApiRegisteringURI);
  55.     try
  56.       writeln(#10'Background server is running.'#10);
  57.       writeln('Press [Enter] to close the server.'#10);
  58.       readln;
  59.     finally
  60.       aHTTPServer.Free;
  61.     end;
  62.     sleep(100);
  63.   finally
  64.     aServer.Free;
  65.   end;
  66. finally
  67.   aModel.Free;
  68. end;
  69.  
  70.  
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment