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 ProjectDescription GetProjectDesription(Type projectType) { if (_instance == null) { _instance = new AvailableAssemblies(LibraryDir); } foreach (ProjectDescription pd in _instance._availableProjects) { if (pd.projectType == projectType) { return(pd); } } throw new SpectrumLoadException("Project not found"); }
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)); }
protected void ReadXml(XmlReader reader, string modelDirectory) { int dataBufferPos = 0; object[] args = new object[4]; args[2] = this; //reader.Read(); //declaration //reader.Read(); //root --> spectra node if (!reader.ReadToFollowing("spectra")) { return; } //XmlDocument doc = new XmlDocument(); //doc.Load(filePath); //this._name = doc.DocumentElement.Attributes["name"].Value; string modelClassName = ""; this._enabled = true; this._data = null; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "name": this._name = reader.Value; break; case "class": modelClassName = reader.Value; break; case "enabled": this._enabled = Convert.ToBoolean(reader.Value); break; case "dataLength": this._data = new int[int.Parse(reader.Value)]; this._weights = new double[this._data.Length]; break; } } if (this._data == null) { throw new SpectrumLoadException("Project files are damaged or this version is no more supported (missing dataLength node)"); } //string modelClassName = doc.DocumentElement.Attributes["class"].Value; //doc.GetElementsByTagName("modelclass")[0].Attributes["name"].Value; this._model = AvailableAssemblies.getModel(modelClassName); if (this._model.SpectrumType.GetInterface("ISpectrum") == null) { throw new SpectrumLoadException("invalid spectrumType. spectrumType must be implementation of ISpectrum"); } Assembly ass = Assembly.GetAssembly(this._model.SpectrumType); _spectra = new List <ISpectrum>(); string typeName = this._model.SpectrumType.ToString(); //int progress = 0; //int spectraCount = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(filePath), "spectra")).Length; while (reader.Read()) //spectrum { if (reader.Name == "spectrum") { XmlReader spectrumReader = reader.ReadSubtree(); BindingFlags bindingFlags = BindingFlags.CreateInstance; // = new object[] { spectrumReader, modelDirectory, this, dataBufferPos }; args[0] = spectrumReader; args[1] = modelDirectory; args[3] = dataBufferPos; SpectrumBase spectrum = (SpectrumBase)ass.CreateInstance(typeName, true, bindingFlags, null, args, null, null); if (spectrum != null) { _spectra.Add(spectrum); } dataBufferPos = spectrum.BufferEndPos + 1; } else { break; } if (OpenProgressChanged != null) { OpenProgressChanged(this, null); //new System.ComponentModel.ProgressChangedEventArgs((int)Math.Round(100 * ((double)++progress / (double)Spectra.Count)), parentProject)); } } }