|
/*
* FileName: PreviewHandlerHostFactory.cs
* Author: Alexei Bouravtsev
* Profiles: http://www.linkedin.com/pub/alexei-bouravtsev/13/201/293
* http://aleksey-buravtsev.moikrug.ru/
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace PreviewHandlers
{
public class PreviewHandlerHostFactory
{
public static PreviewHandlerHostBase Create(
string fileName,
List<Tuple<PreviewHandlerHostBase, List<string>, bool>> previewHandlerHostMapping
)
{
PreviewHandlerHostBase previewHandlerHost = null;
string extension = Path.GetExtension(fileName.ToLower());
if (!string.IsNullOrEmpty(extension))
{
string lowPointlessExt = extension.ToLower().Replace(@".", string.Empty);
foreach (var mapping in previewHandlerHostMapping)
{
if (mapping.Item2 != null)
foreach (var ext in mapping.Item2)
{
if (lowPointlessExt == ext)
{
previewHandlerHost = mapping.Item1;
break;
}
}
if (previewHandlerHost != null)
break;
}
}
if (previewHandlerHost == null)
{
var defaultHandlerHostMapping = previewHandlerHostMapping.FirstOrDefault(t => t.Item3);
if (defaultHandlerHostMapping != null)
previewHandlerHost = defaultHandlerHostMapping.Item1;
}
return previewHandlerHost;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a Russian (Moscow Aviational Institute 1996-2002) Software Engineer living in Moscow, Russia. I have a long experience in Windows programming and have been developing large GUI, Real Time Enterprise Client/Server C# applications and SQL Server/Oracle databases.
My point of interests is high load enterprise applications.