2017-09-26 01:02:09 +02:00
|
|
|
unit TestServerControllerJSONRPCU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
MVCFramework, MVCFramework.Commons, MVCFramework.JSONRPC, JsonDataObjects;
|
|
|
|
|
|
|
|
type
|
|
|
|
TTestJSONRPCController = class(TMVCJSONRPCController)
|
|
|
|
public
|
2020-05-02 16:39:32 +02:00
|
|
|
function Subtract(Value1, Value2: Int64): Integer;
|
2017-09-26 01:02:09 +02:00
|
|
|
procedure MyNotify;
|
2020-05-02 16:39:32 +02:00
|
|
|
function Add(Value1, Value2, Value3: Int64): TJsonObject;
|
2017-09-28 00:14:34 +02:00
|
|
|
function GetListFromTo(aFrom, aTo: Int64): TJsonArray;
|
|
|
|
function MultiplyString(aString: string; Multiplier: Int64): string;
|
2017-09-26 01:02:09 +02:00
|
|
|
end;
|
|
|
|
|
2019-01-18 18:11:27 +01:00
|
|
|
TTestJSONRPCClass = class(TObject)
|
|
|
|
public
|
2020-05-02 16:39:32 +02:00
|
|
|
function Subtract(Value1, Value2: Int64): Integer;
|
2019-01-18 18:11:27 +01:00
|
|
|
procedure MyNotify;
|
2020-05-02 16:39:32 +02:00
|
|
|
function Add(Value1, Value2, Value3: Int64): TJsonObject;
|
2019-01-18 18:11:27 +01:00
|
|
|
function GetListFromTo(aFrom, aTo: Int64): TJsonArray;
|
|
|
|
function MultiplyString(aString: string; Multiplier: Int64): string;
|
|
|
|
function AddTimeToDateTime(aDateTime: TDateTime; aTime: TTime): TDateTime;
|
|
|
|
end;
|
|
|
|
|
2017-09-26 01:02:09 +02:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, MVCFramework.Logger, System.StrUtils;
|
|
|
|
|
|
|
|
{ TTestJSONRPCController }
|
|
|
|
|
2020-05-02 16:39:32 +02:00
|
|
|
function TTestJSONRPCController.Add(Value1, Value2, Value3: Int64): TJsonObject;
|
2017-09-26 01:02:09 +02:00
|
|
|
begin
|
|
|
|
Result := TJsonObject.Create;
|
2020-05-02 16:39:32 +02:00
|
|
|
Result.I['res'] := Value1 + Value2 + Value3;
|
2017-09-28 00:14:34 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TTestJSONRPCController.GetListFromTo(aFrom, aTo: Int64): TJsonArray;
|
|
|
|
var
|
2019-08-02 12:32:23 +02:00
|
|
|
I: Cardinal;
|
2017-09-28 00:14:34 +02:00
|
|
|
begin
|
|
|
|
Result := TJsonArray.Create;
|
|
|
|
for I := aFrom to aTo do
|
|
|
|
Result.Add(I);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TTestJSONRPCController.MultiplyString(aString: string;
|
|
|
|
Multiplier: Int64): string;
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
Result := aString;
|
|
|
|
for I := 2 to Multiplier do
|
|
|
|
begin
|
|
|
|
Result := Result + aString;
|
|
|
|
end;
|
2017-09-26 01:02:09 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestJSONRPCController.MyNotify;
|
|
|
|
begin
|
|
|
|
// this is a notify with no parameters and no result code
|
|
|
|
Self.ClassName;
|
|
|
|
end;
|
|
|
|
|
2020-05-02 16:39:32 +02:00
|
|
|
function TTestJSONRPCController.Subtract(Value1, Value2: Int64): Integer;
|
2017-09-26 01:02:09 +02:00
|
|
|
begin
|
2020-05-02 16:39:32 +02:00
|
|
|
Result := Value1 - Value2;
|
2017-09-26 01:02:09 +02:00
|
|
|
end;
|
|
|
|
|
2019-01-18 18:11:27 +01:00
|
|
|
{ TTestJSONRPCClass }
|
|
|
|
|
2020-05-02 16:39:32 +02:00
|
|
|
function TTestJSONRPCClass.Add(Value1, Value2, Value3: Int64): TJsonObject;
|
2019-01-18 18:11:27 +01:00
|
|
|
begin
|
|
|
|
Result := TJsonObject.Create;
|
2020-05-02 16:39:32 +02:00
|
|
|
Result.I['res'] := Value1 + Value2 + Value3;
|
2019-01-18 18:11:27 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TTestJSONRPCClass.AddTimeToDateTime(aDateTime: TDateTime;
|
|
|
|
aTime: TTime): TDateTime;
|
|
|
|
begin
|
|
|
|
Result := aDateTime + aTime;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TTestJSONRPCClass.GetListFromTo(aFrom, aTo: Int64): TJsonArray;
|
|
|
|
var
|
2019-08-02 12:32:23 +02:00
|
|
|
I: Cardinal;
|
2019-01-18 18:11:27 +01:00
|
|
|
begin
|
|
|
|
Result := TJsonArray.Create;
|
|
|
|
for I := aFrom to aTo do
|
|
|
|
Result.Add(I);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TTestJSONRPCClass.MultiplyString(aString: string;
|
|
|
|
Multiplier: Int64): string;
|
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
Result := aString;
|
|
|
|
for I := 2 to Multiplier do
|
|
|
|
begin
|
|
|
|
Result := Result + aString;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestJSONRPCClass.MyNotify;
|
|
|
|
begin
|
|
|
|
// this is a notify with no parameters and no result code
|
|
|
|
Self.ClassName;
|
|
|
|
end;
|
|
|
|
|
2020-05-02 16:39:32 +02:00
|
|
|
function TTestJSONRPCClass.Subtract(Value1, Value2: Int64): Integer;
|
2019-01-18 18:11:27 +01:00
|
|
|
begin
|
2020-05-02 16:39:32 +02:00
|
|
|
Result := Value1 - Value2;
|
2019-01-18 18:11:27 +01:00
|
|
|
end;
|
|
|
|
|
2017-09-26 01:02:09 +02:00
|
|
|
end.
|