Search Addins in sub directory

Nov 17, 2008 at 4:58 PM
Hi!!!


I have add to MEF the possibility to search Addins in subdirectories.

In System.ComponentModel.Composition.DirectoryPartCatalog I have Add a function called IEnumerable GetFiles(string path, string filter) and modifief the function Initialize() :

Default:

 

foreach (string file in Directory.GetFiles(path, f))

 

{

 

this.AddAssemblyGuarded(file);

 

}

New:

 

foreach (string file in GetFiles(path, f))

 

{

 

this.AddAssemblyGuarded(file);

 

}


The function GetFiles()

 

private IEnumerable GetFiles(string path, string filter)

 

{

 

string[] m_pluginsDeclarationFile = Directory.GetDirectories(path);

 

 

for (int a = 0; a < m_pluginsDeclarationFile.Length; a++)

 

{

 

if (Directory.Exists(m_pluginsDeclarationFile[a]))

 

{

 

string[] files = Directory.GetFiles(m_pluginsDeclarationFile[a], filter);

 

 

for (int i = 0; i < files.Length; i++)

 

{

 

yield return Path.GetFullPath(files[i]);

 

}

}

}

}




NB: Sorry for my english








Nov 18, 2008 at 11:24 PM
Would you be interested in creating a small demo application and posting it to the MEFContrib project?   I'd be glad to sign you up as a developer and assist you in getting your contribution integrated into the existing MEFContrib library.

Bill
Nov 19, 2008 at 5:16 PM
Yes I want !!!!!


Thanx.

Teddy Albina






From: notifications@codeplex.com
To: teddyalbina@hotmail.fr
Date: Tue, 18 Nov 2008 16:24:32 -0800
Subject: Re: Search Addins in sub directory [MEF:40133]

.ExternalClass {font-family:Verdana;font-size:0.75em;} .ExternalClass #EC_ThreadNotificationFooter {border-top:1px solid #ccc;color:gray;} .ExternalClass #EC_ThreadNotificationPostBody {margin-bottom:2em;} .ExternalClass {font-family:Verdana;font-size:0.75em;} .ExternalClass #EC_ThreadNotificationFooter {color:gray;border-top:1px solid #ccc;} .ExternalClass #EC_ThreadNotificationPostBody {margin-bottom:2em;} From: BillKrat
Would you be interested in creating a small demo application and posting it to the MEFContrib project? I'd be glad to sign you up as a developer and assist you in getting your contribution integrated into the existing MEFContrib library.

Bill
Read the full discussion online.
To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)
To start a new discussion for this project, email MEF@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Discutez sur Messenger où que vous soyez ! Mettez Messenger sur votre mobile !
Apr 11, 2009 at 4:29 PM
Edited Apr 11, 2009 at 4:34 PM
I also needed the DirectoryCatalog to search in sub-direcotories so here is my solution.
I just added an additional constructors to set the _includeSubdirectories variable and made a small change in the existing GetFiles method
 that uses the functionality already available in the Directory class to search in subdirectories.

public DirectoryCatalog(string path, bool includeSubdirectories)
    : this(path, "*.dll", includeSubdirectories)
{
}

public DirectoryCatalog(string path, string searchPattern, bool includeSubdirectories)
{
    Requires.NotNullOrEmpty(path, "path");
    this._includeSubdirectories = includeSubdirectories;
    this.Initialize(path, searchPattern);
}

private bool _includeSubdirectories = false;

private string[] GetFiles()
{
    SearchOption searchOption = (this._includeSubdirectories) ?
        SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
    string[] files = Directory.GetFiles(this._fullPath, this._searchPattern, searchOption);
    return Array.ConvertAll<string, string>(files, (file) => file.ToUpperInvariant());
}

That's all.
Actually I do not see why there is not an option in the DirectoryCatalog to search in subdirectories (like for example the IncludeSubdirectories property in the FileSystemWatcher class).
I hope that the MEF team will add this in a future drop.

EDIT:

Oh, I forgot. At first I thought that I could inherit the DirectoryCatalog and override a method, but it turned out that I cannot do that because most of the methods are private. So I had to modify the source. That makes me wonder if this is on purpose so that the catalog cannot be extended or someone just forgot (or did not have the time) to provide appropriate extension points.