public IExternalExcelApplication Create() { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Create"); IExternalExcelApplication result = default(IExternalExcelApplication); try { result = this.CreateInternal(); } catch (Exception ex) { Log.Exception(PROC, ex); } return(result); }
public static IExternalExcelApplication Create() { ModuleProc PROC = new ModuleProc("ExternalExcelLibraryFactory", "Create"); IExternalExcelApplication result = default(IExternalExcelApplication); try { if (_activeLibraryLoader == null) { lock (_librariesLock) { if (_activeLibraryLoader == null) { try { IEnumerable <IExternalExcelApplicationLoader> libraryLoaders = null; try { libraryLoaders = MEFHelper.GetExportedValues <IExternalExcelApplicationLoader>(); } catch { libraryLoaders = GetAssemblyLoaders(); } if (libraryLoaders != null) { _libraryLoaders = (from l in libraryLoaders orderby l.LibraryOrder select l).ToArray(); if (_libraryLoaders != null) { // load the first matched library until find valid one foreach (IExternalExcelApplicationLoader libraryLoader in _libraryLoaders) { if (libraryLoader != null) { if (libraryLoader.IsLoadedProperly) { Log.Info(PROC, "Excel Library : " + libraryLoader.LibraryName + " (Loaded)"); _activeLibraryLoader = libraryLoader; break; } else { Log.Info(PROC, "Excel Library : " + libraryLoader.LibraryName + " (Unable to load)"); } } } } } } catch (Exception ex) { Log.Exception(PROC, ex); } } } } // still no external loaders found (then take ExcelPackage as a rescuer) if (_activeLibraryLoader == null) { _activeLibraryLoader = new OpenXmlExcelApplicationLoader(); } if (_activeLibraryLoader != null) { IExternalExcelApplication library = null; try { library = _activeLibraryLoader.Create(); } catch { library = null; } if (library != null) { result = library; Log.Info(PROC, "Excel Library : " + _activeLibraryLoader.LibraryName + " (Created)"); } } } catch (Exception ex) { Log.Exception(PROC, ex); } return(result); }