Пример #1
0
 private ILogFile OpenWith(string fileName, IFileFormatPlugin plugin)
 {
     try
     {
         return(plugin.Open(fileName, _taskScheduler));
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Plugin {0} threw an unexpected exception while trying to open {1}: {2}",
                         plugin,
                         fileName,
                         e);
         return(null);
     }
 }
Пример #2
0
 private ILogFile OpenWith(string fileName, IFileFormatPlugin plugin)
 {
     try
     {
         // We do NOT want plugins to mess with the global service container
         // so they get a little clone to play with :)
         var clonedContainer = _services.CreateChildContainer();
         return(plugin.Open(clonedContainer, fileName));
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Plugin {0} threw an unexpected exception while trying to open {1}: {2}",
                         plugin,
                         fileName,
                         e);
         return(null);
     }
 }
Пример #3
0
        private static bool SupportsByFileExtension(IFileFormatPlugin plugin, string fileName)
        {
            try
            {
                var extensions = plugin.SupportedExtensions ?? Enumerable.Empty <string>();
                foreach (var extension in extensions)
                {
                    if (fileName.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Log.DebugFormat("Plugin {0} claims that it supports {1}...", plugin, fileName);
                        return(true);
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Plugin {0} threw an unexpected exception: {1}", plugin, e);
                return(false);
            }
        }
Пример #4
0
        private static bool SupportsByRegex(IFileFormatPlugin plugin, string fileName)
        {
            try
            {
                var regexes = (plugin as IFileFormatPlugin2)?.SupportedFileNames ?? Enumerable.Empty <Regex>();
                foreach (var regex in regexes)
                {
                    if (regex.IsMatch(fileName))
                    {
                        Log.DebugFormat("Plugin {0} claims that it supports {1}...", plugin, fileName);
                        return(true);
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Plugin {0} threw an unexpected exception: {1}", plugin, e);
                return(false);
            }
        }
Пример #5
0
 private static bool Supports(IFileFormatPlugin plugin, string fileName)
 {
     return(SupportsByRegex(plugin, fileName) ||
            SupportsByFileExtension(plugin, fileName));
 }