[REL] RunLocalWebServerTest

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
morfius
Posts: 26
Joined: 2011-11-10 13:01:06

[REL] RunLocalWebServerTest

Post by morfius »

This is just a sample. Practical implementation about the idea of this post

The most simple Local Web Server is available here (extract in any folder)

The script RunLocalWebServerTest.ifs is available here (copy to AMC Script dir)

Run the RunLocalWebServerTest.csproj in SharpDev or Visual Studio.
Run AMC and add a film. Select RunLocalWebServerTest.ifs as script.
The Main Program, with comments

Code: Select all

program RunLocalWebServerTest ;

const
  sRunLocalWebServer = 'RunLocalWebServer importer';

var
	gsBuscado, gsYear: string;
	gbRes: Boolean;
//------------------------------------------------------------------------------------
function findMovieFA(m: string; idFA: string; buscado: string; year: string; precision: string; mostrarAvisos: Boolean): Boolean;
var

command, parameters: string;
n: Integer;
ExpectedLines, Count: Integer;//debug
fIntercambio, fInicio: string;
aList: TStringList;
bNoFirstTime: Boolean;

begin
	ExpectedLines := 8;

	parameters := '"' + m + '" ' + year;

	//Check External program Version
  bNoFirstTime := True;//TODO Set a Option or Parameter
	if (bNoFirstTime = False) then
	begin
		bNoFirstTime := True;
		//Do something, like run without parameteres for get Version
		//aList := TStringList.Create;
		//aList.Text := GetPage('http://localhost:6969/CheckVer');
	end;

	aList := TStringList.Create;
	RaiseConnectionErrors(False);//Ignore Error, Script must catch them

	aList.Text := GetPage('http://localhost:6969/RunLocalWebServerTest?Text1=' + m + '?Year=' + year + '?Text2=Value2?Text3=Value3?Text4=Value4?Text5=Value5?Text6=Value6?Text7=Value7');

	n := aList.Count;
	if aList.Count > 0 then
	begin
		parameters := aList.Text;
		for n := 0 to (aList.Count - 1) do
		begin
			parameters := aList.GetString(n);
			Count := Length(parameters);
		end;
	end;

	//check number of returned lines
	if aList.Count = 2 then
	begin
		//show controled error message from external program
		ShowError(parameters);
		//1.- Too many results
		//2.- No results for search string
		//3.- Others
		exit;//function
	end;

	if aList.Count = 1 then
	//Versión
	begin
		ShowInformation(aList.Text);
		exit;//function
	end;

	if aList.Count <> ExpectedLines then
	begin
	//Error por ¿otras causas?
	//no se pudo escribir el archivo (se ejecuta desde un medio de solo lectura)
		ShowError('Local Web Serer its not Running Or Error in Response!!');
		exit;//function
	end;

	//OK continue
	//now you have aList array with results
	//Call your Main routine here
	//YourMainRoutine(aList);
	//To Work!!
	//To Work!!
	//To Work!!
	ShowInformation(aList.Text);
	//free memory
	aList.Free;

end;//function

//------------------------------------------------------------------------------------

begin

	gsBuscado := GetField(fieldURL);
	if Length(gsBuscado) > 0 then
	begin
		findMovieFA(gsBuscado, '', '', '', '', False);
		exit;
	end;
	gsBuscado := GetField(fieldTranslatedTitle);
	if gsBuscado = '' then
	begin
		gsBuscado := GetField(fieldOriginalTitle);
		if (GetOption('AutoSelect') = 0) or (gsBuscado = '') then
		begin
			gbRes := Input(sRunLocalWebServer, 'Pelicula:', gsBuscado);
			if (gbRes = False) then
				exit;
		end;
	end;
	gsYear := GetField(fieldYear);
	findMovieFA(gsBuscado, '', '', gsYear, '', False);
end.
One more complex implementation is available here

All files are open source and are hosted in SourceForge
That's all!
Post Reply