Skip to content

Commit

Permalink
File cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfland committed Oct 29, 2017
1 parent 4c9ce1b commit 3784802
Show file tree
Hide file tree
Showing 41 changed files with 1,059 additions and 1,058 deletions.
48 changes: 24 additions & 24 deletions RemObjects.Train/API/Async.pas
Expand Up @@ -9,7 +9,7 @@ interface
System.Collections.Generic,
System.IO,
System.Linq,
System.Text,
System.Text,
System.Threading.Tasks;

type
Expand Down Expand Up @@ -78,7 +78,7 @@ implementation
finally
lValue := nil;
end;

end;

method AsyncRegistration.&Register(aServices: IApiRegistrationServices);
Expand All @@ -87,23 +87,23 @@ implementation
aServices.AsyncWorker := lAsync;
aServices.RegisterValue('include', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(Self), 'Include'));
aServices.RegisterValue('sleep', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(Self), 'Sleep'));
aServices.RegisterValue('async',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
'async', @lAsync.CallAsync, 1, false, true));
aServices.RegisterValue('run',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
aServices.RegisterValue('async',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
'async', @lAsync.CallAsync, 1, false, true));
aServices.RegisterValue('run',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
'run', @lAsync.run, 1, false, true));
aServices.RegisterValue('runAsync',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
aServices.RegisterValue('runAsync',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
'runAsync', @lAsync.runAsync, 1, false, true));
aServices.RegisterValue('expand',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
aServices.RegisterValue('expand',
new RemObjects.Script.EcmaScript.Internal.EcmaScriptFunctionObject(aServices.Globals,
'expand', @lAsync.expand, 1, false, true));
aServices.RegisterValue('waitFor', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, (a,b,c) ->
begin
lAsync.WaitFor(a, Utilities.GetArgAsEcmaScriptObject(c, 0, a),
Utilities.GetArgAsInteger(c, 1, a));
exit Undefined.Instance;
aServices.RegisterValue('waitFor', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, (a,b,c) ->
begin
lAsync.WaitFor(a, Utilities.GetArgAsEcmaScriptObject(c, 0, a),
Utilities.GetArgAsInteger(c, 1, a));
exit Undefined.Instance;
end));
end;

Expand All @@ -127,7 +127,7 @@ implementation
lEngine.Engine.Run; // should do nothing now.
var lLogger := new DelayedLogger;
lEngine.Logger := lLogger;

CloneScope(aScope.LexicalScope, lEngine.Engine.GlobalObject);
for i: Integer := 1 to length(args) -1 do begin
args[i] := MakeSafe(aScope.Global, args[i]);
Expand All @@ -140,7 +140,7 @@ implementation
lRun.FuncBody := EcmaScriptInternalFunctionObject(lFunc):OriginalBody;
lRun.Args := args.Skip(1).ToArray;
if (lRun.FuncName = nil) and (lRun.FuncBody = nil) then aScope.Global.RaiseNativeError(NativeErrorType.ReferenceError, 'First parameter in async has to be function');

var lStart := new System.Threading.Tasks.Task(@lRun.Run);
lStart.Start();
fEngine.RegisterTask(lStart, String.Format('[{0}] async command', lStart.Id), lLogger);
Expand All @@ -157,11 +157,11 @@ implementation
var lItem := args.Get(ec, 0, i.ToString());
if lItem is TaskWrapper then begin
lTasks.Add(TaskWrapper(lItem).Task);
end else
end else
raise new Exception('Array element '+i+' in call to waitFor is not a task');
end;
if length(lTasks) = 0 then ec.Global.RaiseNativeError(NativeErrorType.ReferenceError, 'More than 0 items expected in the first parameter array');

if aTimeout <=0 then
System.Threading.Tasks.Task.WaitAll(lTasks.ToArray)
else
Expand Down Expand Up @@ -229,7 +229,7 @@ constructor AsyncWorker(aEngine: Engine);
finally
fEngine.Logger.Exit(true,'run', if lFail then FailMode.Yes else FailMode.No, lFail);
end;

end;

method AsyncWorker.runAsync(aScope: ExecutionContext; aSelf: Object; params args: array of Object): Object;
Expand All @@ -246,7 +246,7 @@ constructor AsyncWorker(aEngine: Engine);
try
var lTask := new Task(method begin
if fEngine.DryRun then exit;

new Engine(fEngine.Environment, lPath, System.IO.File.ReadAllText(lPath), Logger := lLogger).Run();
end);
lTask.Start;
Expand All @@ -261,10 +261,10 @@ constructor AsyncWorker(aEngine: Engine);
method AsyncWorker.expand(aScope: ExecutionContext; aSelf: Object; params args: array of Object): Object;
begin
var lArg := coalesce(Utilities.GetArgAsString(args, 0, aScope), '');


exit fEngine.Expand(aScope, lArg);
end;


end.
end.
96 changes: 48 additions & 48 deletions RemObjects.Train/API/FTP.pas
@@ -1,48 +1,48 @@
namespace RemObjects.Train.API;

interface

uses
RemObjects.Train,
RemObjects.Script.EcmaScript,
RemObjects.Script.EcmaScript.Internal,
System.Text,
System.Net,
System.IO;

type
[PluginRegistration]
FTPPlugIn = public class(IPluginRegistration)
private
protected
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('ftp.upload', SkipDryRun := true, SecretArguments := [1, 2])]
class method FtpUpload(aServices: IApiRegistrationServices;ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
end;

implementation

method FTPPlugIn.&Register(aServices: IApiRegistrationServices);
begin
var rov := aServices.RegisterObjectValue('ftp');
rov.AddValue('upload', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(FTPPlugIn), 'FtpUpload'));
end;

class method FTPPlugIn.FtpUpload(aServices: IApiRegistrationServices; ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
begin
aFileName := aServices.ResolveWithBase(ec, aFileName);
using client := new WebClient() do
begin
client.Credentials := new NetworkCredential(aUsername, aPassword);
using sr := new System.IO.FileStream(aFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read) do
begin
var ba := new Byte[sr.Length];
sr.Read(ba, 0, ba.Length - 1);
client.UploadData(aServer + '/' + aRemote, ba);
end;
end;
end;

end.
namespace RemObjects.Train.API;

interface

uses
RemObjects.Train,
RemObjects.Script.EcmaScript,
RemObjects.Script.EcmaScript.Internal,
System.Text,
System.Net,
System.IO;

type

[PluginRegistration]
FTPPlugIn = public class(IPluginRegistration)
private
protected
public
method &Register(aServices: IApiRegistrationServices);
[WrapAs('ftp.upload', SkipDryRun := true, SecretArguments := [1, 2])]
class method FtpUpload(aServices: IApiRegistrationServices;ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
end;

implementation

method FTPPlugIn.&Register(aServices: IApiRegistrationServices);
begin
var rov := aServices.RegisterObjectValue('ftp');
rov.AddValue('upload', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(FTPPlugIn), 'FtpUpload'));
end;

class method FTPPlugIn.FtpUpload(aServices: IApiRegistrationServices; ec: RemObjects.Script.EcmaScript.ExecutionContext; aServer, aUsername, aPassword, aFileName, aRemote: String);
begin
aFileName := aServices.ResolveWithBase(ec, aFileName);
using client := new WebClient() do
begin
client.Credentials := new NetworkCredential(aUsername, aPassword);
using sr := new System.IO.FileStream(aFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read) do
begin
var ba := new Byte[sr.Length];
sr.Read(ba, 0, ba.Length - 1);
client.UploadData(aServer + '/' + aRemote, ba);
end;
end;
end;

end.
10 changes: 5 additions & 5 deletions RemObjects.Train/API/Gac.pas
Expand Up @@ -70,11 +70,11 @@ interface
[PreserveSig()]
method Clone(out ppEnum: IAssemblyEnum): System.Int32;
end;

AssemblyCacheFlags = assembly flags (ASM_CACHE_GAC = 2);

CreateAssemblyNameObjectFlags = assembly enum(
CANOF_DEFAULT = 0,
CANOF_DEFAULT = 0,
CANOF_PARSE_DISPLAY_NAME = 1
);

Expand Down Expand Up @@ -111,15 +111,15 @@ interface
public
class method Register(aName: String);
class method Unregister(aFullName: String);
class method List(aDisplayName: String): sequence of String;
class method List(aDisplayName: String): sequence of String;
end;

implementation

class method MSWinGacUtil.&Register(aName: String);
begin
WithCache(aCache-> begin
var res := aCache.InstallAssembly(2, aName, 0);
var res := aCache.InstallAssembly(2, aName, 0);
if res <> 0 then Marshal.ThrowExceptionForHR(res);
end);
end;
Expand Down Expand Up @@ -164,4 +164,4 @@ implementation
aRun(lTmp);
end;

end.
end.
8 changes: 4 additions & 4 deletions RemObjects.Train/API/Images.pas
Expand Up @@ -33,12 +33,12 @@ implementation
begin
if String.IsNullOrEmpty(filemasklist) then filemasklist := '*';
basefolder := aServices.ResolveWithBase(ec,basefolder);
if not basefolder.EndsWith(System.IO.Path.DirectorySeparatorChar) then
if not basefolder.EndsWith(System.IO.Path.DirectorySeparatorChar) then
basefolder := basefolder + System.IO.Path.DirectorySeparatorChar;
var lDisk := new DiscUtils.Iso9660.CDBuilder();
lDisk.VolumeIdentifier := aDiskName;
lDisk.UseJoliet := true;
for each mask in filemasklist.Split([';'], StringSplitOptions.RemoveEmptyEntries) do
for each mask in filemasklist.Split([';'], StringSplitOptions.RemoveEmptyEntries) do
for each el in System.IO.Directory.EnumerateFiles(basefolder, mask, if aRecurse then System.IO.SearchOption.AllDirectories else System.IO.SearchOption.TopDirectoryOnly) do begin
var lFal := el;
if lFal.StartsWith(basefolder) then
Expand All @@ -52,10 +52,10 @@ implementation
begin
if String.IsNullOrEmpty(filemasklist) then filemasklist := '*';
basefolder := aServices.ResolveWithBase(ec,basefolder);
if not basefolder.EndsWith(System.IO.Path.DirectorySeparatorChar) then
if not basefolder.EndsWith(System.IO.Path.DirectorySeparatorChar) then
basefolder := basefolder + System.IO.Path.DirectorySeparatorChar;

raise new NotImplementedException;
end;

end.
end.
20 changes: 10 additions & 10 deletions RemObjects.Train/API/Ini.pas
Expand Up @@ -2,11 +2,11 @@

interface

uses
uses
RemObjects.Train,
RemObjects.Script.EcmaScript,
RemObjects.Script.EcmaScript,
System.Linq,
RemObjects.Script.EcmaScript.Internal,
RemObjects.Script.EcmaScript.Internal,
System.IO,
System.Runtime.InteropServices;

Expand Down Expand Up @@ -62,25 +62,25 @@ implementation
lProto.AddValue('deleteSection', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(IniPlugin), 'DeleteSection'));
lProto.AddValue('deleteValue', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(IniPlugin), 'DeleteValue'));
lProto.AddValue('keysInSection', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, typeOf(IniPlugin), 'KeysInSection'));
(*
(*
lProto.AddValue('keysInSection', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, method(ec: ExecutionContext; aSelf: Object; args: array of Object): Object begin
aServices.Logger.Enter('keysInSection', args);
try
try
var lSelf := aSelf as IniFileWrapper;
var lSec := lSelf.Ini.Item[Utilities.GetArgAsString(args, 0, ec)];
if lSec = nil then exit Undefined.Instance;
var lres := new EcmaScriptArrayObject(0,aServices .Globals);
for each el in lSec.KEys do
for each el in lSec.KEys do
lRes.AddValue(el);
exit Undefined.Instance;
finally
aServices.Logger.Exit('keysInSection');
end;
end));
end));
end));
end));
lProto.AddValue('deleteValue', RemObjects.Train.MUtilities.SimpleFunction(aServices.Engine, method(ec: ExecutionContext; aSelf: Object; args: array of Object): Object begin
aServices.Logger.Enter('deleteValue', args);
try
try
var lSelf := aSelf as IniFileWrapper;
var lSec := lSelf.Ini.Item[Utilities.GetArgAsString(args, 0, ec)];
if lSec = nil then exit Utilities.GetArgAsString(args, 2, ec);
Expand Down Expand Up @@ -159,4 +159,4 @@ implementation
exit aSelf.Sections.Select(a->a.Item1).ToArray;
end;

end.
end.
6 changes: 3 additions & 3 deletions RemObjects.Train/API/Innosetup.pas
Expand Up @@ -43,7 +43,7 @@ implementation
lPath := System.IO.Path.Combine(lPath, 'ISCC.exe');
if not System.IO.File.Exists(lPath) then raise new Exception(lPath+' could not be found');
if aServices.Engine.DryRun then exit;

var sb := new StringBuilder;
sb.AppendFormat('"{0}"', aFilename);
if not String.IsNullOrEmpty(aOptions:destinationFolder) then
Expand All @@ -53,7 +53,7 @@ implementation
if aOptions <> nil then begin
for each el in aOptions.defines do
sb.AppendFormat(' /d"{0}"', el);

sb.Append(aOptions.extraArgs);
end;

Expand All @@ -66,4 +66,4 @@ implementation
if n <> 0 then raise new Exception('InnoSetup failed');
end;

end.
end.
8 changes: 4 additions & 4 deletions RemObjects.Train/API/Interfaces.pas
Expand Up @@ -2,18 +2,18 @@

interface

uses
uses
RemObjects.Train,
RemObjects.Script.EcmaScript;

type
IApiRegistrationServices = public interface
method RegisterValue(aName: String; aValue: Object);
method RegisterValue(aName: String; aValue: Object);
method RegisterObjectValue(aName: String): EcmaScriptObject;
method RegisterProperty(aName: String; aGet: Func<Object>; aSet: Action<Object>);
method RegisterTask(aTask: System.Threading.Tasks.Task; aSignature: String; aLogger: DelayedLogger);
method UnregisterTask(aTask: System.Threading.Tasks.Task);

property WorkDir: String read;
property Environment: Environment read;
property Globals: GlobalObject read;
Expand All @@ -36,4 +36,4 @@ interface

implementation

end.
end.

0 comments on commit 3784802

Please sign in to comment.