2016-06-22 17:49:16 +02:00
// ***************************************************************************
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2016 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// *************************************************************************** }
2015-01-14 11:39:44 +01:00
unit MVCFramework. RESTAdapter;
interface
uses
System. Rtti, System. TypInfo, MVCFramework. RESTClient, MVCFramework,
2015-01-19 15:28:04 +01:00
IdIOHandler, System. Classes, System. SysUtils;
2015-01-14 11:39:44 +01:00
2015-01-17 17:19:09 +01:00
const
URL_SEPARATOR = '/' ;
2015-01-14 11:39:44 +01:00
type
RESTResourceAttribute = class( MVCHTTPMethodAttribute)
private
FURL: string ;
FHTTPMethodType: TMVCHTTPMethodType;
procedure SetURL( const Value: string ) ;
procedure SetHTTPMethodType( const Value: TMVCHTTPMethodType) ;
public
constructor Create( AMVCHTTPMethod: TMVCHTTPMethodType; AURL: string ) ;
property URL: string read FURL write SetURL;
2015-02-17 09:40:55 +01:00
property HTTPMethodType: TMVCHTTPMethodType read FHTTPMethodType
write SetHTTPMethodType;
2015-01-14 11:39:44 +01:00
end ;
BodyAttribute = class( TCustomAttribute)
private
FOwnsObject: boolean ;
procedure SetOwnsObject( const Value: boolean ) ;
public
constructor Create( AOwnsObject: boolean = true ) ;
property OwnsObject: boolean read FOwnsObject write SetOwnsObject;
end ;
ParamAttribute = class( TCustomAttribute)
private
FParamType: string ;
FCustomFormat: string ;
2015-01-17 17:19:09 +01:00
FParamMatch: string ;
2015-01-14 11:39:44 +01:00
procedure SetCustomFormat( const Value: string ) ;
procedure SetParamType( const Value: string ) ;
2015-01-17 17:19:09 +01:00
procedure SetParamMatch( const Value: string ) ;
2015-01-14 11:39:44 +01:00
public
2015-02-17 09:40:55 +01:00
constructor Create( AParamMatch: string ; AParamType: string = '' ;
ACustomFormat: string = '' ) ;
2015-01-17 17:19:09 +01:00
property ParamMatch: string read FParamMatch write SetParamMatch;
2015-01-14 11:39:44 +01:00
property ParamType: string read FParamType write SetParamType;
property CustomFormat: string read FCustomFormat write SetCustomFormat;
2015-01-17 17:19:09 +01:00
function FmtParamMatch: string ;
2015-01-14 11:39:44 +01:00
end ;
HeadersAttribute = class( TCustomAttribute)
private
FKey: string ;
FValue: string ;
procedure SetKey( const Value: string ) ;
procedure SetValue( const Value: string ) ;
public
constructor Create( AKey: string ; AValue: string ) ;
property Key: string read FKey write SetKey;
property Value: string read FValue write SetValue;
end ;
2015-02-17 09:40:55 +01:00
MappingAttribute = class( TCustomAttribute)
private
FClass: TClass;
public
constructor Create( AClass: TClass) ;
function GetType: TRttiType;
end ;
2015-01-14 11:39:44 +01:00
IRESTAdapter< T> = interface
[ '{AAA41F40-69DB-419B-9922-F59F990CBDB5}' ]
function ResourcesService: T;
procedure AddRequestHeaders( AObj: TRttiObject) ;
procedure AddRequestHeader( AKey: string ; AValue: string ) ;
2015-02-17 09:40:55 +01:00
procedure MapResult( AResp: IRESTResponse; AMethod: TRttiMethod;
ARTTIType: TRttiType; out AResult: TValue) ;
2015-01-14 11:39:44 +01:00
end ;
2015-06-16 15:13:59 +02:00
TRESTAdapter< T: IInvokable> = class( TVirtualInterface, IRESTAdapter< T> )
2015-01-14 11:39:44 +01:00
private
FRESTClient: TRESTClient;
2015-06-16 15:13:59 +02:00
FRESTClientOwner: boolean ;
2015-01-14 11:39:44 +01:00
procedure SetRESTClient( const Value: TRESTClient) ;
2015-06-16 15:13:59 +02:00
procedure SetRESTClientOwner( const Value: boolean ) ;
2015-01-14 11:39:44 +01:00
protected
2015-06-16 15:13:59 +02:00
procedure DoInvoke( Method: TRttiMethod; const Args: TArray< TValue> ;
out Result : TValue) ;
2015-01-14 11:39:44 +01:00
procedure AddRequestHeaders( AObj: TRttiObject) ;
procedure AddRequestHeader( AKey: string ; AValue: string ) ;
2015-02-17 09:40:55 +01:00
procedure MapResult( AResp: IRESTResponse; AMethod: TRttiMethod;
ARTTIType: TRttiType; out AResult: TValue) ;
2015-01-17 17:19:09 +01:00
function GetURL( AMethod: TRttiMethod; const Args: TArray< TValue> ) : string ;
2015-02-17 09:40:55 +01:00
function GetBodyAsString( AMethod: TRttiMethod;
const Args: TArray< TValue> ) : string ;
2015-01-14 11:39:44 +01:00
public
constructor Create;
destructor Destroy; override ;
2015-06-16 15:13:59 +02:00
function Build( ARESTClient: TRESTClient; const ARESTClientOwner: boolean = false ) : T; overload ;
2015-02-17 09:40:55 +01:00
function Build( const AServerName: string ; const AServerPort: Word = 8 0 ;
AIOHandler: TIdIOHandler = nil ) : T; overload ;
2015-01-14 11:39:44 +01:00
function ResourcesService: T;
property RESTClient: TRESTClient read FRESTClient write SetRESTClient;
2015-06-16 15:13:59 +02:00
property RESTClientOwner: boolean read FRESTClientOwner write SetRESTClientOwner;
2015-01-14 11:39:44 +01:00
end ;
2015-02-17 09:40:55 +01:00
IAsynchRequest = interface
[ '{3E720356-F2B7-4C32-8051-B7723263740F}' ]
procedure SetAlwaysProc( const Value: TProc) ;
procedure SetErrorProc( const Value: TProc< Exception> ) ;
procedure SetSuccessProc( const Value: TProc< TValue> ) ;
procedure SetSynchronized( const Value: boolean ) ;
function GetAlwaysProc: TProc;
function GetErrorProc: TProc< Exception> ;
function GetSuccessProc: TProc< TValue> ;
function GetSynchronized: boolean ;
property SuccessProc: TProc< TValue> read GetSuccessProc
write SetSuccessProc;
property ErrorProc: TProc< Exception> read GetErrorProc write SetErrorProc;
property AlwaysProc: TProc read GetAlwaysProc write SetAlwaysProc;
property Synchronized: boolean read GetSynchronized write SetSynchronized;
end ;
TAsynchRequest = class( TInterfacedObject, IAsynchRequest)
2015-01-19 15:28:04 +01:00
private
FSynchronized: boolean ;
2015-02-17 09:40:55 +01:00
FSuccessProc: TProc< TValue> ;
2015-01-19 15:28:04 +01:00
FErrorProc: TProc< Exception> ;
FAlwaysProc: TProc;
procedure SetAlwaysProc( const Value: TProc) ;
procedure SetErrorProc( const Value: TProc< Exception> ) ;
2015-02-17 09:40:55 +01:00
procedure SetSuccessProc( const Value: TProc< TValue> ) ;
2015-01-19 15:28:04 +01:00
procedure SetSynchronized( const Value: boolean ) ;
2015-02-17 09:40:55 +01:00
function GetAlwaysProc: TProc;
function GetErrorProc: TProc< Exception> ;
function GetSuccessProc: TProc< TValue> ;
function GetSynchronized: boolean ;
2015-01-19 15:28:04 +01:00
public
2015-03-13 09:59:54 +01:00
constructor Create( ASuccProc: TProc< TValue> = nil ;
2015-02-17 09:40:55 +01:00
AProcErr: TProc< Exception> = nil ; AProcAlways: TProc = nil ;
2015-01-19 15:28:04 +01:00
ASynchronized: boolean = false ) ;
2015-02-17 09:40:55 +01:00
property SuccessProc: TProc< TValue> read GetSuccessProc
write SetSuccessProc;
property ErrorProc: TProc< Exception> read GetErrorProc write SetErrorProc;
property AlwaysProc: TProc read GetAlwaysProc write SetAlwaysProc;
property Synchronized: boolean read GetSynchronized write SetSynchronized;
2015-01-19 15:28:04 +01:00
end ;
2015-01-14 11:39:44 +01:00
implementation
uses
2015-01-19 15:28:04 +01:00
ObjectsMappers,
2015-01-14 11:39:44 +01:00
{$IF CompilerVersion < 27}
Data. DBXJSON,
Data. SqlExpr,
DBXCommon,
{$ELSE}
System. JSON,
{$ENDIF}
RTTIUtilsU, DuckListU,
Generics. Collections;
{ TRESTAdapter }
2016-06-22 17:49:16 +02:00
function TRESTAdapter< T> . Build( ARESTClient: TRESTClient;
const ARESTClientOwner: boolean = false ) : T;
2015-01-14 11:39:44 +01:00
begin
RESTClient : = ARESTClient;
2015-06-16 15:13:59 +02:00
RESTClientOwner : = ARESTClientOwner;
2015-01-14 11:39:44 +01:00
Result : = ResourcesService;
end ;
procedure TRESTAdapter< T> . AddRequestHeader( AKey, AValue: string ) ;
begin
if CompareText( AKey, 'ContentType' ) = 0 then
FRESTClient. ContentType( AValue)
else if CompareText( AKey, 'ContentEncoding' ) = 0 then
FRESTClient. ContentEncoding( AValue)
else if CompareText( AKey, 'Accept' ) = 0 then
FRESTClient. Accept( AValue)
else
FRESTClient. RequestHeaders. Values[ AKey] : = AValue;
end ;
procedure TRESTAdapter< T> . AddRequestHeaders( AObj: TRttiObject) ;
var
_attr: TCustomAttribute;
begin
for _attr in AObj. GetAttributes do
if _attr is HeadersAttribute then
2015-02-17 09:40:55 +01:00
AddRequestHeader( HeadersAttribute( _attr) . Key,
HeadersAttribute( _attr) . Value) ;
2015-01-14 11:39:44 +01:00
end ;
2015-02-17 09:40:55 +01:00
function TRESTAdapter< T> . Build( const AServerName: string ;
const AServerPort: Word ; AIOHandler: TIdIOHandler) : T;
2015-01-14 11:39:44 +01:00
var
ARESTClient: TRESTClient;
begin
ARESTClient : = TRESTClient. Create( AServerName, AServerPort, AIOHandler) ;
2015-06-16 15:13:59 +02:00
Result : = Build( ARESTClient, true ) ;
2015-01-14 11:39:44 +01:00
end ;
constructor TRESTAdapter< T> . Create;
begin
2015-06-16 15:13:59 +02:00
inherited Create( TypeInfo( T) , DoInvoke) ;
2015-01-14 11:39:44 +01:00
end ;
destructor TRESTAdapter< T> . Destroy;
begin
2016-06-22 17:49:16 +02:00
// Ezequiel J. M<> ller (If it is created outside, it must be destroyed out)
// d.spinetti added RESTClientOwner to manage desctruction of RESTClient and free its associated memory
2015-06-16 15:13:59 +02:00
if RESTClientOwner and Assigned( FRESTClient) then
FRESTClient. Free;
2015-01-14 11:39:44 +01:00
inherited ;
end ;
2015-06-16 15:13:59 +02:00
procedure TRESTAdapter< T> . DoInvoke( Method: TRttiMethod;
2015-02-17 09:40:55 +01:00
const Args: TArray< TValue> ; out Result : TValue) ;
2015-01-14 11:39:44 +01:00
var
Resp: IRESTResponse;
_restresourceattr: RESTResourceAttribute;
2015-01-17 17:19:09 +01:00
URL: string ;
Body: string ;
2015-02-17 09:40:55 +01:00
AsynchClass: IAsynchRequest;
_mappingattr: MappingAttribute;
2015-01-14 11:39:44 +01:00
begin
// Implementation of RESTClient DoGet DoPut ecc...
2015-02-17 09:40:55 +01:00
if not TRTTIUtils. HasAttribute< RESTResourceAttribute> ( Method,
_restresourceattr) then
raise Exception. CreateFmt( 'No REST Resource specified in method %s' ,
[ Method. Name ] ) ;
2015-01-14 11:39:44 +01:00
// headers can be more than one
2016-06-22 17:49:16 +02:00
// FRESTClient.RequestHeaders.Clear; //Ezequiel J. M<> ller (You can not clear the header, because I can use other.)
2015-01-14 11:39:44 +01:00
// Interface
AddRequestHeaders( TRTTIUtils. ctx. GetType( TypeInfo( T) ) ) ;
// Method
AddRequestHeaders( Method) ;
2015-01-17 17:19:09 +01:00
// URL and Body
URL : = GetURL( Method, Args) ;
Body : = GetBodyAsString( Method, Args) ;
2015-01-19 15:28:04 +01:00
// Asynch way to do
2015-02-17 09:40:55 +01:00
if Args[ Length( Args) - 1 ] . TryAsType< IAsynchRequest> ( AsynchClass) then
begin
2015-01-19 15:28:04 +01:00
FRESTClient. Asynch(
procedure( ARESTResponse: IRESTResponse)
var
ResValue: TValue;
begin
2015-02-17 09:40:55 +01:00
if TRTTIUtils. HasAttribute< MappingAttribute> ( Method, _mappingattr) then
MapResult( ARESTResponse, Method, _mappingattr. GetType, ResValue)
else
ResValue : = TValue. From( ARESTResponse) ;
if Assigned( AsynchClass. SuccessProc) then
AsynchClass. SuccessProc( ResValue) ;
end , AsynchClass. ErrorProc, AsynchClass. AlwaysProc,
AsynchClass. Synchronized) ;
end ;
2015-01-19 15:28:04 +01:00
2015-01-14 11:39:44 +01:00
case _restresourceattr. HTTPMethodType of
httpGET:
2015-01-17 17:19:09 +01:00
Resp : = FRESTClient. doGET( URL, [ ] ) ;
2015-01-14 11:39:44 +01:00
httpPUT:
2015-01-17 17:19:09 +01:00
Resp : = FRESTClient. doPUT( URL, [ ] , Body) ;
2015-01-14 11:39:44 +01:00
httpPOST:
2015-01-17 17:19:09 +01:00
Resp : = FRESTClient. doPOST( URL, [ ] , Body) ;
2015-01-14 11:39:44 +01:00
end ;
2015-01-17 17:19:09 +01:00
// if the response code is > 400 raise exception
// if Resp.ResponseCode >= 400 then
// raise Exception.CreateFmt
// ('Error on execute request ''%s''. Message: %d %s ',
// [URL, Resp.ResponseCode, Resp.BodyAsString]);
2015-01-14 11:39:44 +01:00
// if is a procedure no need a return type
if Assigned( Method. ReturnType) then
2015-02-17 09:40:55 +01:00
MapResult( Resp, Method, Method. ReturnType, Result ) ;
2015-01-14 11:39:44 +01:00
end ;
2015-02-17 09:40:55 +01:00
function TRESTAdapter< T> . GetBodyAsString( AMethod: TRttiMethod;
const Args: TArray< TValue> ) : string ;
2015-01-17 17:19:09 +01:00
var
_parameters: TArray< TRttiParameter> ;
I: Integer ;
_parameter: TRttiParameter;
_param: BodyAttribute;
2015-12-22 12:15:43 +01:00
_attrlistof: MapperListOf;
2015-01-17 17:19:09 +01:00
Arg: TValue;
2015-01-14 11:39:44 +01:00
begin
2015-01-17 17:19:09 +01:00
_parameters : = AMethod. GetParameters;
for I : = 0 to Length( _parameters) - 1 do
begin
_parameter : = _parameters[ I] ;
// ARG := ARGS[I+1] because
// Args RTTI for the arguments of the interface method that has been called. The first argument (located at index 0) represents the interface instance itself.
Arg : = Args[ I + 1 ] ;
if TRTTIUtils. HasAttribute< BodyAttribute> ( _parameter, _param) then
2015-01-19 15:28:04 +01:00
try
if Arg. IsObject then
2015-12-22 12:15:43 +01:00
begin
if TRTTIUtils. HasAttribute< MapperListOf> ( AMethod, _attrlistof) then
2016-06-22 17:49:16 +02:00
Exit( Mapper. ObjectListToJSONArrayString( WrapAsList( Arg. AsObject) , true ) )
2015-12-22 12:15:43 +01:00
else
Exit( Mapper. ObjectToJSONObjectString( Arg. AsObject) ) ;
end
2015-01-19 15:28:04 +01:00
else
Exit( TRTTIUtils. TValueAsString( Arg, '' , '' ) ) ;
finally
if _param. OwnsObject and Arg. IsObject then
Arg. AsObject. Free;
end ;
2015-01-17 17:19:09 +01:00
end ;
2015-01-14 11:39:44 +01:00
end ;
2015-02-17 09:40:55 +01:00
function TRESTAdapter< T> . GetURL( AMethod: TRttiMethod;
const Args: TArray< TValue> ) : string ;
2015-01-14 11:39:44 +01:00
var
2015-01-17 17:19:09 +01:00
_restresourceattr: RESTResourceAttribute;
IURL: string ;
SplitUrl: TArray< string > ;
URLDict: TDictionary< string , string > ;
Split: string ;
_parameters: TArray< TRttiParameter> ;
2015-01-14 11:39:44 +01:00
I: Integer ;
_parameter: TRttiParameter;
_param: ParamAttribute;
2015-01-17 17:19:09 +01:00
Arg: TValue;
2015-01-14 11:39:44 +01:00
begin
2015-01-17 17:19:09 +01:00
_restresourceattr : = TRTTIUtils. GetAttribute< RESTResourceAttribute> ( AMethod) ;
IURL : = _restresourceattr. URL;
SplitUrl : = IURL. Split( [ URL_SEPARATOR] ) ;
URLDict : = TDictionary< string , string > . Create;
try
for Split in SplitUrl do
if not Split. IsEmpty then
URLDict. Add( Split, Split) ;
_parameters : = AMethod. GetParameters;
// ARG := ARGS[I+1] because
// Args RTTI for the arguments of the interface method that has been called. The first argument (located at index 0) represents the interface instance itself.
for I : = 0 to Length( _parameters) - 1 do
begin
_parameter : = _parameters[ I] ;
Arg : = Args[ I + 1 ] ;
if TRTTIUtils. HasAttribute< ParamAttribute> ( _parameter, _param) then
2015-02-17 09:40:55 +01:00
URLDict[ _param. FmtParamMatch] : = TRTTIUtils. TValueAsString( Arg,
_param. ParamType, _param. CustomFormat) ;
2015-01-17 17:19:09 +01:00
end ;
for Split in SplitUrl do
if not Split. IsEmpty then
Result : = Result + URL_SEPARATOR + URLDict[ Split] ;
2015-02-17 09:40:55 +01:00
if IURL. EndsWith( URL_SEPARATOR) and not( Result . EndsWith( URL_SEPARATOR) ) then
2015-01-17 17:19:09 +01:00
Result : = Result + URL_SEPARATOR;
finally
URLDict. Free;
2015-01-14 11:39:44 +01:00
end ;
end ;
2015-02-17 09:40:55 +01:00
procedure TRESTAdapter< T> . MapResult( AResp: IRESTResponse; AMethod: TRttiMethod;
ARTTIType: TRttiType; out AResult: TValue) ;
2015-01-14 11:39:44 +01:00
var
_attrlistof: MapperListOf;
begin
2015-02-17 09:40:55 +01:00
if ARTTIType. TypeKind = tkClass then
2015-01-14 11:39:44 +01:00
begin
2015-01-17 17:19:09 +01:00
// ListOf
if TRTTIUtils. HasAttribute< MapperListOf> ( AMethod, _attrlistof) then
begin
2015-02-17 09:40:55 +01:00
AResult : = TRTTIUtils. CreateObject( ARTTIType. QualifiedName) ;
Mapper. JSONArrayToObjectList( WrapAsList( AResult. AsObject) ,
_attrlistof. Value, AResp. BodyAsJsonValue as TJSONArray, false ) ;
2015-01-17 17:19:09 +01:00
end
// JSONValue
2015-02-17 09:40:55 +01:00
else if ARTTIType. AsInstance. MetaclassType. InheritsFrom( TJSONValue) then
2015-01-17 17:19:09 +01:00
AResult : = TJSONObject. ParseJSONValue( AResp. BodyAsString)
// Object
else
2015-02-17 09:40:55 +01:00
AResult : = Mapper. JSONObjectToObject( ARTTIType. QualifiedName,
AResp. BodyAsJsonObject)
2015-01-14 11:39:44 +01:00
end
else
2015-01-17 17:19:09 +01:00
// IRESTResponse
2015-02-17 09:40:55 +01:00
if ARTTIType. QualifiedName = TRTTIUtils. ctx. GetType( TypeInfo( IRESTResponse) )
. QualifiedName then
2015-01-17 17:19:09 +01:00
AResult : = AResult. From( AResp)
else // else a simple BodyAsString
AResult : = AResp. BodyAsString
2015-01-14 11:39:44 +01:00
end ;
function TRESTAdapter< T> . ResourcesService: T;
var
pInfo: PTypeInfo;
begin
pInfo : = TypeInfo( T) ;
if QueryInterface( GetTypeData( pInfo) . Guid, Result ) < > 0 then
begin
2015-02-17 09:40:55 +01:00
raise Exception. CreateFmt
( 'RESTAdapter is unable to cast %s to its interface' ,
[ string( pInfo. Name ) ] ) ;
2015-01-14 11:39:44 +01:00
end ;
end ;
procedure TRESTAdapter< T> . SetRESTClient( const Value: TRESTClient) ;
begin
FRESTClient : = Value;
end ;
2015-06-16 15:13:59 +02:00
procedure TRESTAdapter< T> . SetRESTClientOwner( const Value: boolean ) ;
begin
FRESTClientOwner : = Value;
end ;
2015-01-14 11:39:44 +01:00
{ RESTResourceAttribute }
2015-02-17 09:40:55 +01:00
constructor RESTResourceAttribute. Create( AMVCHTTPMethod: TMVCHTTPMethodType;
AURL: string ) ;
2015-01-14 11:39:44 +01:00
begin
FURL : = AURL;
FHTTPMethodType : = AMVCHTTPMethod;
end ;
2015-02-17 09:40:55 +01:00
procedure RESTResourceAttribute. SetHTTPMethodType
( const Value: TMVCHTTPMethodType) ;
2015-01-14 11:39:44 +01:00
begin
FHTTPMethodType : = Value;
end ;
procedure RESTResourceAttribute. SetURL( const Value: string ) ;
begin
FURL : = Value;
end ;
{ BodyAttribute }
constructor BodyAttribute. Create( AOwnsObject: boolean ) ;
begin
2015-01-17 17:19:09 +01:00
inherited Create;
2015-01-14 11:39:44 +01:00
FOwnsObject : = AOwnsObject;
end ;
procedure BodyAttribute. SetOwnsObject( const Value: boolean ) ;
begin
FOwnsObject : = Value;
end ;
{ ParamAttribute }
2015-02-17 09:40:55 +01:00
constructor ParamAttribute. Create( AParamMatch: string ;
AParamType, ACustomFormat: string ) ;
2015-01-14 11:39:44 +01:00
begin
2015-01-17 17:19:09 +01:00
inherited Create;
FParamMatch : = AParamMatch;
2015-01-14 11:39:44 +01:00
FParamType : = AParamType;
FCustomFormat : = ACustomFormat;
end ;
2015-01-17 17:19:09 +01:00
function ParamAttribute. FmtParamMatch: string ;
begin
Result : = '{' + ParamMatch + '}' ;
end ;
2015-01-14 11:39:44 +01:00
procedure ParamAttribute. SetCustomFormat( const Value: string ) ;
begin
FCustomFormat : = Value;
end ;
2015-01-17 17:19:09 +01:00
procedure ParamAttribute. SetParamMatch( const Value: string ) ;
begin
FParamMatch : = Value;
end ;
2015-01-14 11:39:44 +01:00
procedure ParamAttribute. SetParamType( const Value: string ) ;
begin
FParamType : = Value;
end ;
{ HeadersAttribute }
constructor HeadersAttribute. Create( AKey: string ; AValue: string ) ;
begin
FKey : = AKey;
FValue : = AValue;
end ;
procedure HeadersAttribute. SetKey( const Value: string ) ;
begin
FKey : = Value;
end ;
procedure HeadersAttribute. SetValue( const Value: string ) ;
begin
FValue : = Value;
end ;
2015-01-19 15:28:04 +01:00
{ TAsynchRequest }
2015-03-13 09:59:54 +01:00
constructor TAsynchRequest. Create( ASuccProc: TProc< TValue> = nil ;
2015-02-17 09:40:55 +01:00
AProcErr: TProc< Exception> = nil ; AProcAlways: TProc = nil ;
2015-01-19 15:28:04 +01:00
ASynchronized: boolean = false ) ;
begin
inherited Create;
2015-03-13 09:59:54 +01:00
FSuccessProc : = ASuccProc;
2015-01-19 15:28:04 +01:00
FErrorProc : = AProcErr;
FAlwaysProc : = AProcAlways;
FSynchronized : = ASynchronized;
end ;
2015-02-17 09:40:55 +01:00
function TAsynchRequest. GetAlwaysProc: TProc;
begin
Result : = FAlwaysProc;
end ;
function TAsynchRequest. GetErrorProc: TProc< Exception> ;
begin
Result : = FErrorProc;
end ;
function TAsynchRequest. GetSuccessProc: TProc< TValue> ;
begin
Result : = FSuccessProc;
end ;
function TAsynchRequest. GetSynchronized: boolean ;
begin
Result : = FSynchronized;
end ;
2015-01-19 15:28:04 +01:00
procedure TAsynchRequest. SetAlwaysProc( const Value: TProc) ;
begin
FAlwaysProc : = Value;
end ;
procedure TAsynchRequest. SetErrorProc( const Value: TProc< Exception> ) ;
begin
FErrorProc : = Value;
end ;
2015-02-17 09:40:55 +01:00
procedure TAsynchRequest. SetSuccessProc( const Value: TProc< TValue> ) ;
2015-01-19 15:28:04 +01:00
begin
FSuccessProc : = Value;
end ;
procedure TAsynchRequest. SetSynchronized( const Value: boolean ) ;
begin
FSynchronized : = Value;
end ;
2015-02-17 09:40:55 +01:00
{ MappingAttribute }
constructor MappingAttribute. Create( AClass: TClass) ;
begin
FClass : = AClass;
end ;
function MappingAttribute. GetType: TRttiType;
begin
Result : = TRTTIUtils. ctx. GetType( FClass) ;
end ;
2015-01-14 11:39:44 +01:00
end .