public static IProject getProject(string fileName, ReturnAttributeValue gav) { if (_instance == null) { _instance = new AvailableAssemblies(LibraryDir); } //XmlReader reader; string projectClassName = String.Empty; Stream stream = null; try { XmlReader reader = ProjectBase.getXmlReader(fileName, out stream); reader.ReadToFollowing("project"); if (reader.MoveToFirstAttribute()) { do { switch (reader.Name) { case "class": projectClassName = reader.Value; break; //case "spectraCount": break; } if (gav != null) { gav(reader.Name, reader.Value); } } while (reader.MoveToNextAttribute()); } if (projectClassName == String.Empty) { throw new SpectrumLoadException("This is not valid LT10 project"); } } catch (Exception) { throw new SpectrumLoadException("Project file is damaged, it is not a valid LT10 project file or file is in use by another process."); } finally { if (stream != null) { stream.Close(); } } object[] args = new object[] { fileName }; for (int i = 0; i < _instance._availableProjects.Count; i++) { //if (String.Equals(modelName, Path.GetFileNameWithoutExtension(_instance._availableModels[i].plugin.assemblyPath), string[] pluginClassNameSubs = _instance._availableProjects[i].plugin.className.Split(classSeparators); string[] projectClassNameSubs = projectClassName.Split(classSeparators); string pluginClassName = pluginClassNameSubs[pluginClassNameSubs.Length - 1]; projectClassName = projectClassNameSubs[projectClassNameSubs.Length - 1]; if (String.Equals(projectClassName, pluginClassName, StringComparison.CurrentCultureIgnoreCase)) { return((IProject)PluginServices.getPluginInstance(_instance._availableProjects[i].plugin, args)); } } throw new SpectrumLoadException(String.Format("Couldn't find project \"{0}\"!", projectClassName)); }
public static IGroupGUI GetGroupGUI(Type projectType, DataGridView grid, List <ISpectrum> spectra, GroupDefinition groupDefinition, GroupTabPage groupTabPage) { //find plugin with accurate project type AvailableGUIAssemblies assemblies = GetAvailableGUIAssembliesInstance(); foreach (GUIDescription gd in assemblies._availableGUIs) { if (gd.projectType == projectType) { return((IGroupGUI)PluginServices.getPluginInstance(gd.plugin, new object[] { grid, spectra, groupDefinition, groupTabPage })); } } //if there is no gui for this projectType use default gui return(new DefaultGroupGUI(grid, spectra, groupDefinition, groupTabPage)); }
//public static string LibraryDir = "D:\\shared_devel\\EVEL\\Release\\bin\\lib"; //public static string LibraryDir = "D:\\Devel\\.NET\\cs\\EVEL\\Release\\bin\\lib\\"; protected AvailableAssemblies(string path) { //LibraryDir = Path.Combine(Environment.CurrentDirectory, "lib"); //const string userRoot = "HKEY_CURRENT_USER"; //const string subkey = "Evel"; //const string keyName = userRoot + "\\" + subkey; //Microsoft.Win32.Registry.SetValue(keyName, "libpath", "E:\\dotnet\\projects\\EVEL\\Release\\bin\\lib"); //models this._availableModels = new List <ModelDescription>(); AvailablePlugin[] plugs = PluginServices.getPlugins(path, "IModel", null); foreach (AvailablePlugin plugin in plugs) { //using ( IModel model = (IModel)PluginServices.getPluginInstance(plugin);//) { ModelDescription md = new ModelDescription(); md.name = model.Name; md.description = model.Description; md.groupDefinitions = model.GroupsDefinition; md.projectType = model.ProjectType; md.plugin = plugin; this._availableModels.Add(md); //} } //projects this._availableProjects = new List <ProjectDescription>(); Type projectBaseType = typeof(ProjectBase); ConstructorInfo[] constructors = projectBaseType.GetConstructors(); plugs = PluginServices.getPlugins(path, "IProject", constructors); foreach (AvailablePlugin plugin in plugs) { IProject project = (IProject)PluginServices.getPluginInstance(plugin, new object[] { }); ProjectDescription pd = new ProjectDescription(); pd.name = project.Name; pd.description = project.Description; pd.experimentalMethodName = project.ExperimentalMethodName; pd.plugin = plugin; pd.projectType = project.GetType(); this._availableProjects.Add(pd); } }
private AvailableGUIAssemblies() { this._availableGUIs = new List <GUIDescription>(); Type defaultGroupGUIType = typeof(DefaultGroupGUI); ConstructorInfo[] constructors = defaultGroupGUIType.GetConstructors(); AvailablePlugin[] plugs = PluginServices.getPlugins(AvailableAssemblies.LibraryDir, "IGroupGUI", constructors); if (plugs != null) { foreach (AvailablePlugin plugin in plugs) { IGroupGUI gui = (IGroupGUI)PluginServices.getPluginInstance(plugin);//) { GUIDescription gd = new GUIDescription(); gd.plugin = plugin; gd.projectType = gui.ProjectType; this._availableGUIs.Add(gd); } } }
public static IProject getProject(string projectClassName, object[] args) { if (_instance == null) { _instance = new AvailableAssemblies(LibraryDir); } for (int i = 0; i < _instance._availableProjects.Count; i++) { //if (String.Equals(modelName, Path.GetFileNameWithoutExtension(_instance._availableModels[i].plugin.assemblyPath), string[] pluginClassNameSubs = _instance._availableProjects[i].plugin.className.Split(classSeparators); string[] projectClassNameSubs = projectClassName.Split(classSeparators); string pluginClassName = pluginClassNameSubs[pluginClassNameSubs.Length - 1]; projectClassName = projectClassNameSubs[projectClassNameSubs.Length - 1]; if (String.Equals(projectClassName, pluginClassName, StringComparison.CurrentCultureIgnoreCase)) { return((IProject)PluginServices.getPluginInstance(_instance._availableProjects[i].plugin, args)); } } throw new SpectrumLoadException(String.Format("Couldn't find project \"{0}\"!", projectClassName)); }