public ConvertResult Convert(ref DocumentObject document, ConvertFileType convertType) { try { string path = DocumentSettings.GetStorePath(document.FileName); _storePolicy.Copy(path, document.StorePath); string tmpName = document.Id + convertType.ToSuffix(); var convertPath = DocumentSettings.GetConvertPath(tmpName); int result = _documentConverter.Convert(path, convertPath, convertType); if (File.Exists(tmpName)) { File.Delete(tmpName); } return new ConvertResult{ ErrorCode = result, SourcePath = document.StorePath, TargetPath = convertPath }; } catch (Exception ex) { _logger.Error(ex.Message); _logger.Error(ex.StackTrace); throw; } }
public ConvertResult Convert(ref DocumentObject document, ConvertFileType convertType) { try { string path = DocumentSettings.GetStorePath(document.FileName); _storePolicy.Copy(path, document.StorePath); string tmpName = document.Id + convertType.ToSuffix(); var convertPath = DocumentSettings.GetConvertPath(tmpName); int result = _documentConverter.Convert(path, convertPath, convertType); if (File.Exists(tmpName)) { File.Delete(tmpName); } return(new ConvertResult { ErrorCode = result, SourcePath = document.StorePath, TargetPath = convertPath }); } catch (Exception ex) { _logger.Error(ex.Message); _logger.Error(ex.StackTrace); throw; } }
public static string ToSuffix(this ConvertFileType fileType) { switch (fileType) { case ConvertFileType.WordToHtml: case ConvertFileType.ExcelToHtml: case ConvertFileType.PPTToHtml: case ConvertFileType.PdfToHtml: case ConvertFileType.TextToHtml: case ConvertFileType.WordPDFtoHtml: case ConvertFileType.ExcelPDFToHtml: case ConvertFileType.PPTPDFToHtml: case ConvertFileType.TextPDFToHtml: return(".html"); case ConvertFileType.CadToBmp: return(".bmp"); case ConvertFileType.CadToJpg: return(".jpg"); case ConvertFileType.CadToPng: return(".png"); case ConvertFileType.CadToSvg: return(".svg"); default: return(string.Empty); } }
public int Convert(Stream from, Stream to, ConvertFileType convertFileType) { _logger.Debug("转换文件 : " + from + "到: " + to); try { IConverter converter = _container.Resolve <IConverter>(convertFileType); return(converter.Convert(from, to)); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); throw; } }
public int Convert(Stream from, Stream to, ConvertFileType convertFileType) { _logger.Debug("转换文件 : " + from + "到: " + to); try { IConverter converter = _container.Resolve<IConverter>(convertFileType); return converter.Convert(from, to); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); throw; } }
public int Convert(string from, string to, ConvertFileType convertFileType) { _logger.Debug("转换文件 : " + from + "到: " + to); if (!File.Exists(from)) { throw new ConverterException(ErrorMessages.FileNotExist); } try { IConverter converter = _container.Resolve <IConverter>(convertFileType); return(converter.Convert(@from, to)); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); throw; } }
public int Convert(string from, string to, ConvertFileType convertFileType) { _logger.Debug("转换文件 : " + from + "到: " + to); if (!File.Exists(from)) { throw new ConverterException(ErrorMessages.FileNotExist); } try { IConverter converter = _container.Resolve<IConverter>(convertFileType); return converter.Convert(@from, to); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); throw; } }
public static void Register <U>(this ConverterContainer container, ConvertFileType convertFileType) where U : IConverter { container.Register(convertFileType, typeof(U)); }
public static T Resolve <T>(this ConverterContainer container, ConvertFileType convertFileType) where T : IConverter { return((T)container.GetInstance(convertFileType)); }
internal IConverter GetInstance(ConvertFileType convertFileType) { var convererType = _dictionaries[convertFileType]; return(Activator.CreateInstance(convererType) as IConverter); }
internal void Register(ConvertFileType filetype, Type converter) { _dictionaries.Add(filetype, converter); }
internal void Register(ConvertFileType filetype, Type converter) { _dictionaries.Add(filetype, converter); }
internal IConverter GetInstance(ConvertFileType convertFileType) { var convererType = _dictionaries[convertFileType]; return Activator.CreateInstance(convererType) as IConverter; }