Tuesday, July 03, 2007

Some days ago I was working on procedures that need be executed in a second thread to avoid blocking the application GUI, so I implemented something simple to search files in a "iterative" way.

El otro dia estaba viendo procedimientos que necesitan ejecutar en un segundo hilo para no bloquear la aplicacion, e implemente algo muy sencillo para buscar archivos de manera "iterativa":



using System;
using System.Collection.Generic;
using System.IO;

public class FileSeeker
{

public static string[] RetrieveFilesFrom(string directory, string searchPattern,int level)
{
List filenames = new List();
Stack directories = new Stack()

directories.Push(directory);

while(directories.count!=0)
{
string currentDirectory = directoriesStack.Pop();

foreach(string file in Directory.GetFiles(currentDirectory,searchPattern))
filenames.Add(file);


if((level==-1) || (directories.count != level))
{
foreach(string subDirectory in Directory.GetDirectories(currentDirectory))
directories.Push(subDirectory);
}

}
return filenames.ToArray();
}

}

public class Program
{

public static void Main(string[] args)
{
foreach(string path in FileSeeker.RetrieveFilensFrom(@"C:\Program Files\", "*.exe",-1)
Console.WriteLine(path);
Console.Read();
}

}




Now I'm encapsulating all the behavior in a component with more features, like search using regular expressions, file size, creation time, etc. As soon I finish it, I will write an article for elguille's site.

Did you hear about Prado?



Since I started working with WebForms on ASP.NET, I knew that was the kind of web programing that I really want to do, people call it "event driven". Who cares about html tags if we have the viewstate and all the infraestructure that works on it...

When I started my practice time, I reached the PHP with Ajax using the Xajax framework, really nice times with such a nice framework (believe me, it's awesome) I couldn't stop telling my coworkers: ...it's kind of the code behind..., I make all my webpages with client events that fire server methods: using a couple of lines in javascript and the xajax engine, but ...

During the last two weeks I've been hearing about PRADO in my (then), future work place, PRADO ... it's a framework who won the Zend competition ... Let's check it out! ... Read about it on the web ... Oh, it's inspired in ASP.NET 2.0!!! so ... if it supports all of that beautiful stuff, could we program event driven websites with PHP transparently? ... The answer is Yes!!!

But the event driven part is not all of it. If you would like to work on software components (like I do) and do it the dotNet code-way (like I do), you will be pleased to find that PRADO is software component based, and provides:

A kind of using token (implement as a static method in a core class) to offset the lack of namespace in php:

Prado::using('This.Is.Del.I.Cio.Us.MyClass');

Properties with setter and getter methods:

class TControl extends TComponent {
public function getID() {
...
}
public function setID($value) {
...
}
}


used as:

$id = $component->ID;
$component->ID = $id;

or

$id = $component->getID();
$component->setID( $id );

Event:

$callback = 'myFunctionName'; or $callback = array($unsub,'myFunctionName');

$MyComponent->OnClick = $callback;
$MyComponent->OnClick->add( $callback );
$MyComponent->OnClick[] = $callback;
$MyComponent->attachEventHandler( 'OnClick' , $callback );

This is just the tip of the iceberg, PRADO is a UNIQUE framework, you should try it out. It doesn't support MVC, but it brings event driven to php in an easy an fun way.
If it's inspired on ASP.NET, how else could it be? :-)

Prado is here!