-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,997 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using DotNetNuke.Collections.Internal; | ||
using DotNetNuke.Framework.Reflections; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Satrabel.OpenContent.Components.FileIndexer | ||
{ | ||
public class FileIndexerManager | ||
{ | ||
|
||
private static readonly ILogAdapter Logger = AppConfig.Instance.LogAdapter.GetLogAdapter(typeof(FileIndexerManager)); | ||
private static NaiveLockingList<IFileIndexer> _fileIndexers; | ||
|
||
public static void RegisterFileIndexers() | ||
{ | ||
_fileIndexers = new NaiveLockingList<IFileIndexer>(); | ||
|
||
foreach (IFileIndexer fi in GetFileIndexers()) | ||
{ | ||
_fileIndexers.Add(fi); | ||
} | ||
} | ||
|
||
private static IEnumerable<IFileIndexer> GetFileIndexers() | ||
{ | ||
var typeLocator = new TypeLocator(); | ||
IEnumerable<Type> types = typeLocator.GetAllMatchingTypes(IsValidDataSourceProvider); | ||
|
||
foreach (Type filterType in types) | ||
{ | ||
IFileIndexer filter; | ||
try | ||
{ | ||
filter = Activator.CreateInstance(filterType) as IFileIndexer; | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.Error($"Unable to create {filterType.FullName} while GetFileIndexers. {e.Message}"); | ||
filter = null; | ||
} | ||
|
||
if (filter != null) | ||
{ | ||
yield return filter; | ||
} | ||
} | ||
} | ||
|
||
private static bool IsValidDataSourceProvider(Type t) | ||
{ | ||
return t != null && t.IsClass && !t.IsAbstract && t.IsVisible && typeof(IFileIndexer).IsAssignableFrom(t); | ||
} | ||
|
||
public static IFileIndexer GetFileIndexer(string file) | ||
{ | ||
if (string.IsNullOrEmpty(file)) | ||
return null; | ||
|
||
var fileIndexer = _fileIndexers.SingleOrDefault(ds => ds.CanIndex(file)); | ||
return fileIndexer; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Satrabel.OpenContent.Components.FileIndexer | ||
{ | ||
public interface IFileIndexer | ||
{ | ||
// return true if this fileindexer can handle this kind of file (based on the file extension) | ||
bool CanIndex(string file); | ||
|
||
//return a text representation of the content of the file for indexing | ||
string GetContent(string file); | ||
} | ||
} |
Oops, something went wrong.