AODL.Document.Import.ImportHandler.GetFirstImporter C# (CSharp) Method

GetFirstImporter() public method

Gets the first importer that match the parameter criteria.
public GetFirstImporter ( DocumentTypes documentType, string loadPath ) : IImporter
documentType DocumentTypes Type of the document.
loadPath string The save path.
return IImporter
		public IImporter GetFirstImporter(DocumentTypes documentType, string loadPath)
		{
			string targetExtension			= ExportHandler.GetExtension(loadPath);

			foreach(IImporter iImporter in this.LoadImporter())
			{
				foreach(DocumentSupportInfo documentSupportInfo in iImporter.DocumentSupportInfos)
					if (documentSupportInfo.Extension.ToLower().Equals(targetExtension.ToLower()))
						if (documentSupportInfo.DocumentType == documentType)
							return iImporter;
			}

			throw new AODLException("No importer available for type "+documentType.ToString()+" and extension "+targetExtension);
		}

Usage Example

Example #1
0
		/// <summary>
		/// Loads the document by using the specified importer.
		/// </summary>
		/// <param name="file">The the file.</param>
		public void Load(string file)
		{
			this._isLoadedFile				= true;

			this.Styles = new StyleCollection();
			this._fields = new FieldsCollection();
			this.Content = new ContentCollection();
			

			this._xmldoc					= new XmlDocument();
			this._xmldoc.LoadXml(TextDocumentHelper.GetBlankDocument());
			this.NamespaceManager			= TextDocumentHelper.NameSpace(this._xmldoc.NameTable);

			ImportHandler importHandler		= new ImportHandler();
			m_importer				= importHandler.GetFirstImporter(DocumentTypes.TextDocument, file);
			m_dirInfo = m_importer.DirInfo;
			if (m_importer != null)
			{
				if (m_importer.NeedNewOpenDocument)
					this.New();
				m_importer.Import(this,file);

				if (m_importer.ImportError != null)
					if (m_importer.ImportError.Count > 0)
					foreach(object ob in m_importer.ImportError)
					if (ob is AODLWarning)
				{
					if (((AODLWarning)ob).Message != null)
						Console.WriteLine("Err: {0}", ((AODLWarning)ob).Message);
					if (((AODLWarning)ob).Node != null)
					{
						XmlTextWriter writer	= new XmlTextWriter(Console.Out);
						writer.Formatting		= Formatting.Indented;
						((AODLWarning)ob).Node.WriteContentTo(writer);
					}
				}
			}
			this._formCollection.Clearing += FormsCollection_Clear;
			this._formCollection.Removed += FormsCollection_Removed;
		}
All Usage Examples Of AODL.Document.Import.ImportHandler::GetFirstImporter