/// <summary> /// Loads a dxf file. /// </summary> /// <param name="stream">Stream.</param> /// <returns>Returns a DxfDocument. It will return null if the file has not been able to load.</returns> /// <remarks> /// Loading dxf files prior to AutoCad 2000 is not supported.<br /> /// On Debug mode it will raise any exception that might occur during the whole process.<br /> /// The caller will be responsible of closing the stream. /// </remarks> public static DxfDocument Load(Stream stream, bool isOld) { DxfReader dxfReader = new DxfReader(); #if DEBUG DxfDocument document = isOld ? dxfReader.ReadOld(stream) : dxfReader.Read(stream); //dxfReader.Read(stream); #else DxfDocument document; try { document = isOld?dxfReader.ReadOld(stream): dxfReader.Read(stream); //dxfReader.Read(stream); } catch { return(null); } #endif return(document); }
/// <summary> /// Loads a dxf file. /// </summary> /// <param name="file">File name.</param> /// <returns>Returns a DxfDocument. It will return null if the file has not been able to load.</returns> /// <exception cref="FileNotFoundException"></exception> /// <exception cref="IOException"></exception> /// <remarks> /// Loading dxf files prior to AutoCad 2000 is not supported.<br /> /// The Load method will still raise an exception if they are unable to create the FileStream.<br /> /// On Debug mode it will raise any exception that migh occur during the whole process. /// </remarks> public static DxfDocument Load(string file, bool isOld) { FileInfo fileInfo = new FileInfo(file); if (!fileInfo.Exists) { throw new FileNotFoundException("File " + fileInfo.FullName + " not found.", fileInfo.FullName); } Stream stream; try { stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } catch (Exception ex) { throw new IOException("Error trying to open the file " + fileInfo.FullName + " for reading.", ex); } DxfReader dxfReader = new DxfReader(); #if DEBUG DxfDocument document = isOld ? dxfReader.ReadOld(stream) : dxfReader.Read(stream); //dxfReader.Read(stream); stream.Close(); #else DxfDocument document; try { document = isOld?dxfReader.ReadOld(stream): dxfReader.Read(stream); //dxfReader.Read(stream); } catch { return(null); } finally { stream.Close(); } #endif document.name = Path.GetFileNameWithoutExtension(fileInfo.FullName); return(document); }