:-eval(consult('ContractLog/math.prova')).
:-eval(consult('ContractLog/list.prova')).
:-eval(consult('ContractLog/list_math.prova')).
:-eval(consult('ContractLog/datetime.prova')).
:-eval(consult('ContractLog/timeinterval.prova')).
:-eval(consult('ContractLog/ecaruntime.prova')).

server("http://www.google.de").



% ECA rules which ping a service with a procedural attachment.
% The time function is dependent on the acutal time
% if the web servcer is available trigger action
% if not trigger else action
eca(timeInterval(Y), rbsla.utils.WebsiteAvailable.testWebserver("http://www.google.de"), _,ok(),_,negok()).


%%---------------------- ACTION OF THE ECA -------------------------------


ok() :-
	server(X),
	println(["server ",X," available"]).

negok() :- println(["server not available"]).

%---------------------- CONDITION OF THE ECA ------------------------------


%--------------------- interval OF THE ECA --------------------------------
timeInterval(X) :-
	sysTime(DT),
	DT = [A,B,C,D,HOUR,F,G],
	X = DT,
	primePeriod(HOUR),
	!,
	interval(timespan(0,0,0,1), DT).

timeInterval(X) :-
	sysTime(DT),
	DT = [A,B,C,D,HOUR,F,G],
	X = DT,
	mainPeriod(HOUR),
	interval(timespan(0,0,0,3), DT).

timeIntervalError() :-
	sysTime(DT),
	interval(timespan(0,0,0,5), DT).
	


%two time periods
primePeriod(HOUR):-
	moreequ(HOUR,8),
	less(HOUR,18).

mainPeriod(HOUR) :-
	moreequ(HOUR,8).

mainPeriod(HOUR) :-
	less(HOUR , 8).
	
%-----------------------------------------------------------------------
% Start the ECA runtime
%-----------------------------------------------------------------------

start():-
	%hideTimer(), % hide the timer
	%showConsole(),
	startECARuntime(".\examples\function_tests\eca_runtime\ecaAttachment.prova").
	
:- solve(start()).
		
