public FileService(ConverterOptions options, IMessageBroker broker, IConverter converter, ILogger <FileService> log) { _options = options; _broker = broker; _converter = converter; _log = log; }
/// <summary> /// Creates a new instance of a Converter, initializes with specified arguments. /// </summary> /// <param name="geoConverter"></param> /// <param name="logger"></param> /// <param name="serializerOptions"></param> /// <param name="options"></param> public Converter(IGeoLocationConverter geoConverter, ILogger <Converter> logger, IOptions <JsonSerializerOptions> serializerOptions, IOptions <ConverterOptions> options) { _geoConverter = geoConverter; _logger = logger; _serialzerOptions = serializerOptions.Value; _options = options.Value; }
private void Convert(string path) { ConverterOptions options = GetConverterOptions(); if (path != null) { if (File.Exists(path)) { MarkdownPath = path; _htmlPath = null; Markdown = File.ReadAllText(path).Replace("\t", " "); ConvertMarkdownAndFillTextFields(Markdown, path); if (_useContentScanner) { print(ContentScanner.ParseScanrResults(ContentScanner.ScanMarkdown(Markdown))); } if (_saveOutputToHtml) { _htmlPath = DragonUtil.GetFullPathWithoutExtension(path) + ".html"; Converter.ConvertMarkdownFileToHtmlFile(path, _htmlPath, options); } UIManager.Instance.HideLoadingScreen(); UIManager.Instance.SetStatusText("Converted markdown! Copy HTML on right side or start Image Linker (experimental)."); } } else { UIManager.Instance.HideLoadingScreen(); UIManager.Instance.SetStatusText("No valid markdown chosen!"); } }
public void GetPageSettings_PaperSizeSetNull_ExpectDefault() { var convertOptions = new ConverterOptions(); var actual = SettingsConverter.GetPageSettings(convertOptions); Assert.Equal(794, actual.Width); Assert.Equal(1123, actual.Height); }
public void Should_throw_argumentnullexception() { var options = new ConverterOptions { SitePath = "Test" }; var converter = new Converter(options); Assert.Throws <ArgumentNullException>(() => converter.SetParser(null), "converter"); }
public void GetPageSettings_MarginsSetNull_ExpectDefault() { var convertOptions = new ConverterOptions(); var actual = SettingsConverter.GetPageSettings(convertOptions); Assert.Equal(38, actual.Left); Assert.Equal(38, actual.Top); Assert.Equal(38, actual.Right); Assert.Equal(38, actual.Bottom); }
internal static void AddReference(this ConverterOptions opts, string name) { if (File.Exists(name)) { opts.References.Add(name); } else { throw new InvalidOperationException(String.Format("File {0} not exist", name)); } }
public void GetPageSettings_PaperSizeSetA5Portrait_ExpectA5Portrait() { var convertOptions = new ConverterOptions { Paper = new Paper { Size = "A5" } }; var actual = SettingsConverter.GetPageSettings(convertOptions); Assert.Equal(794, actual.Height); Assert.Equal(562, actual.Width); }
public void GetPageSettings_PaperSizeSetA4Landscape_ExpectA4Landscape() { var convertOptions = new ConverterOptions { Paper = new Paper { Size = "A4", Orientation = "Landscape" } }; var actual = SettingsConverter.GetPageSettings(convertOptions); Assert.Equal(794, actual.Height); Assert.Equal(1123, actual.Width); }
public void Converter_Obj_Tests2() { var objFile = Path.Combine(LoaderTests.SampleRootPath, "buildings/buildings.obj"); var gltfFile = EnsureOuputPath(objFile); var options = new ConverterOptions(); options.SeparateBinary = true; var converter = new ModelConverter(objFile, gltfFile, options); var model = converter.Run(); Assert.NotNull(model); Assert.True(model.Materials.Count > 0); }
public static void Main(string[] args) { var cmdOptions = new Options(); var parser = new CommandLine.Parser(); if (parser.ParseArguments(args, cmdOptions)) { if (cmdOptions.Verbose) { ConfigureTrace(); } var options = new ConverterOptions { SitePath = cmdOptions.SitePath, SiteConfiguration = SiteConfigurationParser.LoadSiteConfiguration("config.yml") }; var watch = new Stopwatch(); watch.Start(); var converter = new Converter(options); if (cmdOptions.InitializeSite) { converter.InitializeSite(); Console.WriteLine("Site [{0}] generated", cmdOptions.SitePath); } if (cmdOptions.GenerateSite) { converter.ConvertAll(); } if (!string.IsNullOrWhiteSpace(cmdOptions.FileToGenerate)) { converter.ConvertSingleFile(cmdOptions.FileToGenerate); } watch.Stop(); Console.WriteLine(""); Console.WriteLine("Finished in {0}", watch.Elapsed); } else { Console.WriteLine(cmdOptions.GetUsage()); Environment.Exit(1); } }
static void Main(string[] args) { var exe = Path.ChangeExtension(Assembly.GetExecutingAssembly().Location, "exe"); // force switch to exe on .net core var exeDir = Path.GetDirectoryName(exe); Directory.SetCurrentDirectory(exeDir); CreateContextMenu(exe); if (args.Length == 0 || string.IsNullOrEmpty(args[0]) || !File.Exists(args[0])) { return; } string logPath = args[0]; string outputPath = Path.Combine(exeDir, Guid.NewGuid().ToString() + Constants.KML_EXTENSION); var configPath = Path.Combine(exeDir, "config.json"); if (!File.Exists(configPath)) { return; } var config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(configPath)); var options = new ConverterOptions() { AltitudeOffset = config.AltitudeOffset, AltitudeMode = config.AltitudeMode, LogLines = File.ReadAllLines(logPath), OutputStream = File.Create(outputPath), FullName = Path.GetFileNameWithoutExtension(logPath), Name = Path.GetFileNameWithoutExtension(logPath).Split("-")[0], AltitudeHeader = config.AltitudeHeader, DateHeader = config.DateHeader, GPSHeader = config.GPSHeader, GPSSpeedHeader = config.GPSSpeedHeader, TimeHeader = config.TimeHeader, PathColor = config.PathColor, GPSSpeedFactor = config.GPSSpeedFactor, GPSSpeedLabel = config.GPSSpeedLabel, }; var converter = new Converter(options); converter.Convert(); if (!string.IsNullOrEmpty(config.GoogleEarthExe) && File.Exists(config.GoogleEarthExe)) { Process.Start(config.GoogleEarthExe, outputPath); } }
public async Task Post_EndpointsReturnSuccessAndHtmlContentType() { var client = _factory.CreateClient(); var convertOptions = new ConverterOptions { Content = File.ReadAllText("test.md"), To = "html" }; var jsonString = JsonSerializer.Serialize(convertOptions); var response = await client.PostAsync("/api/markdown", new StringContent(jsonString, Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); // Status Code 200-299 Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType.ToString()); }
public void Converter_Mat_Tests() { var objFile = Path.Combine(LoaderTests.SampleRootPath, "plants/indoor plant_02.obj"); var gltfFile = EnsureOuputPath(objFile); var options = new ConverterOptions { SeparateBinary = true, SeparateTextures = true }; var converter = new ModelConverter(objFile, gltfFile, options); var model = converter.Run(); Assert.NotNull(model); Assert.True(model.Materials.Count > 0); }
public static void Main(string[] args) { var cmdOptions = new Options(); var parser = new CommandLine.Parser(); if (parser.ParseArguments(args, cmdOptions)) { if (cmdOptions.Verbose) ConfigureTrace(); var options = new ConverterOptions { SitePath = cmdOptions.SitePath, SiteConfiguration = SiteConfigurationParser.LoadSiteConfiguration("config.yml") }; var watch = new Stopwatch(); watch.Start(); var converter = new Converter(options); if (cmdOptions.InitializeSite) { converter.InitializeSite(); Console.WriteLine("Site [{0}] generated", cmdOptions.SitePath); } if (cmdOptions.GenerateSite) { converter.ConvertAll(); } if (!string.IsNullOrWhiteSpace(cmdOptions.FileToGenerate)) { converter.ConvertSingleFile(cmdOptions.FileToGenerate); } watch.Stop(); Console.WriteLine(""); Console.WriteLine("Finished in {0}", watch.Elapsed); } else { Console.WriteLine(cmdOptions.GetUsage()); Environment.Exit(1); } }
public async Task Post_EndpointsReturnFailAndNonSupportMessage() { var client = _factory.CreateClient(); var convertOptions = new ConverterOptions { Content = File.ReadAllText("test.md"), To = "jpg" }; var jsonString = JsonSerializer.Serialize(convertOptions); var response = await client.PostAsync("/api/markdown", new StringContent(jsonString, Encoding.UTF8, "application/json")); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString()); var streamContent = response.Content as StreamContent; Assert.NotNull(streamContent); }
public void Converter_GLB_Tests3() { var objFile = Path.Combine(LoaderTests.SampleRootPath, "buildings/buildings.obj"); var gltfFile = EnsureOuputPath(objFile, "building_glb"); var options = new ConverterOptions(); options.GLB = true; if (options.GLB) { gltfFile = Path.ChangeExtension(gltfFile, "glb"); } if (File.Exists(gltfFile)) { File.Delete(gltfFile); } var converter = new ModelConverter(objFile, gltfFile, options); var model = converter.Run(); Assert.NotNull(model); Assert.True(model.Materials.Count > 0); }
public string ConvertToHtml(string markdownPath, string htmlPath, ConverterOptions options) { Console.WriteLine("Converting " + markdownPath + " to RW WordPress ready HTML..."); if (htmlPath == null) { htmlPath = DragonUtil.GetFullPathWithoutExtension(markdownPath) + ".html"; } if (DragonUtil.CheckFolderWritePermission(Path.GetDirectoryName(htmlPath))) { Converter.ConvertMarkdownFileToHtmlFile(markdownPath, htmlPath, options); Console.WriteLine("Saved HTML to custom location: " + htmlPath); } else { ColoredConsole.WriteLineWithColor("Conversion aborted, can't write to " + htmlPath, ConsoleColor.Red); } return(htmlPath); }
private void ConvertMarkdownAndFillTextFields(string markdown, string path) { Debug.Log(path); if (markdown.Length == 0) { return; } Markdown = markdown; ConverterOptions options = GetConverterOptions(); HTML = Converter.ConvertMarkdownStringToHtml(Markdown, options, path); UIManager.Instance.SetImageLinkButtonVisible(true); UIManager.Instance.SetMarkdownGroupVisible(true); UIManager.Instance.SetHtmlGroupVisible(true); UIManager.Instance.SetCopyHtmlTopButtonVisible(true); UIManager.Instance.SetPasteHtmlTopButtonVisible(true); UIManager.Instance.SetHemingwayButtonVisible(true); UIManager.Instance.SetAnalysisButtonVisible(true); UIManager.Instance.LoadMarkdownPage(0); UIManager.Instance.LoadHtmlPage(0); }
/// <summary> /// Initializes a new instance of the <see cref="OpenSaveGameCommand"/> class. /// </summary> /// <param name="options">The options.</param> public OpenSaveGameCommand(ConverterOptions options) : base(options) { }
/// <summary> /// Initializes a new instance of the <see cref="SaveCommand"/> class. /// </summary> /// <param name="options">The options.</param> public SaveCommand(ConverterOptions options) : base(options) { }
/// <summary> /// Initializes a new instance of the <see cref="LogViewModel"/> class. /// </summary> /// <param name="view">The view.</param> /// <param name="options">The options.</param> public LogViewModel(IView view, ConverterOptions options) : base(view, "Convert", options) { }
/// <summary> /// Convert incoming options into page settings for rendering. /// </summary> /// <param name="converterOptions">Options from request</param> /// <returns>Page settings for rendering PDF</returns> public static PageSettings GetPageSettings(ConverterOptions converterOptions) { var options = new PageSettings(); if (converterOptions.Paper != null) { var paperSize = converterOptions.Paper.Size.ToLower(); switch (paperSize) { case "custom": options.Width = LengthConverter.ToCssPixels(converterOptions.Paper.Width); options.Height = LengthConverter.ToCssPixels(converterOptions.Paper.Height); break; case "a0": options.Width = 3179; options.Height = 4494; break; case "a1": options.Width = 2245; options.Height = 3179; break; case "a2": options.Width = 1587; options.Height = 2245; break; case "a3": options.Width = 1123; options.Height = 1587; break; case "a4": options.Width = 794; options.Height = 1123; break; case "a5": options.Width = 562; options.Height = 794; break; case "a6": options.Width = 397; options.Height = 562; break; case "letter": options.Width = 816; options.Height = 1055; break; case "legal": options.Width = 816; options.Height = 1346; break; default: throw new ArgumentException("Unknown page size."); } if (!string.IsNullOrWhiteSpace(converterOptions.Paper.Orientation) && converterOptions.Paper.Orientation.ToLower() == "landscape") { var temp = options.Width; options.Width = options.Height; options.Height = temp; } } if (converterOptions.Margins != null) { if (!string.IsNullOrWhiteSpace(converterOptions.Margins.Left)) { options.Left = LengthConverter.ToCssPixels(converterOptions.Margins.Left); } if (!string.IsNullOrWhiteSpace(converterOptions.Margins.Right)) { options.Right = LengthConverter.ToCssPixels(converterOptions.Margins.Right); } if (!string.IsNullOrWhiteSpace(converterOptions.Margins.Top)) { options.Top = LengthConverter.ToCssPixels(converterOptions.Margins.Top); } if (!string.IsNullOrWhiteSpace(converterOptions.Margins.Bottom)) { options.Bottom = LengthConverter.ToCssPixels(converterOptions.Margins.Bottom); } } return(options); }
public SaveGamePickerViewModel(ConverterOptions options, IView view) : base(view, "File/Folder paths", options) { this.BuildConversionOptions(); }
public override bool Execute() { if (SourceAidlFiles.Length == 0) // nothing to do { return(true); } var opts = new ConverterOptions() { Verbose = true, ParcelableHandling = ParcelableHandling.Ignore, }; if (!string.IsNullOrEmpty(ParcelableHandlingOption)) { opts.ParcelableHandling = ToParcelableHandling(ParcelableHandlingOption); } if (!string.IsNullOrEmpty(OutputNamespace)) { opts.OutputNS = OutputNamespace; } foreach (var file in References) { opts.AddReference(file.ItemSpec); } foreach (var file in SourceAidlFiles) { opts.AddFile(file.ItemSpec); } var tool = new AidlCompiler(); using (var fsw = TextWriter.Null /*File.AppendText (Path.Combine (IntermediateOutputDirectory, "AidlFilesWrittenAbsolute.txt"))*/) { tool.FileWritten += (file, source) => Log.LogDebugMessage("Written ... {0}", file); string outPath = Path.Combine(IntermediateOutputDirectory, "aidl"); var ret = tool.Run(opts, assemblyFile => AssemblyDefinition.ReadAssembly(assemblyFile), (dir, file) => { var dst = Path.GetFullPath(Path.Combine(outPath, Path.ChangeExtension(file, ".cs"))); if (!dst.StartsWith(outPath)) { dst = Path.Combine(outPath, Path.ChangeExtension(Path.GetFileName(file), ".cs")); } string dstdir = Path.GetDirectoryName(dst); if (!Directory.Exists(dstdir)) { Directory.CreateDirectory(dstdir); } fsw.WriteLine(dst); fsw.Flush(); return(dst); }); if (ret.LogMessages.Count > 0) { foreach (var p in ret.LogMessages) { Log.LogError("{0} {1}: {2}", Path.GetFullPath(p.Key), p.Value.Location, p.Value.ToString()); } } } return(true); }
public ModFilesProvider(ConverterOptions options) { this.options = options; }
/// <summary> /// Initializes a new instance of the <see cref="SummaryViewModel"/> class. /// </summary> /// <param name="view">The view.</param> /// <param name="options">The options.</param> public SummaryViewModel(IView view, ConverterOptions options) : base(view, "Summary", options) { }
/// <summary> /// Initializes a new instance of the <see cref="ConvertCommand"/> class. /// </summary> /// <param name="options">The options.</param> public ConvertCommand(ConverterOptions options) : base(options) { }
public void Should_throw_argumentnullexception() { var options = new ConverterOptions {SitePath = "Test"}; var converter = new Converter(options); Assert.Throws<ArgumentNullException>(() => converter.SetTemplater(null), "templater"); }
//used to handle file private void button2_Click(object sender, System.EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Files(*.XLS)|*.XLS"; saveFileDialog.AddExtension = true; saveFileDialog.DefaultExt = ".XLS"; if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.CheckPathExists) { GroupingGridExcelConverterControl converter = new GroupingGridExcelConverterControl(); //Properties //ExportStyle if (checkBox1.Checked) { //by default ExportStyle is true converter.ExportBorders = this.checkBox4.Checked; } else { converter.ExportStyle = false; } if (colorPickerButton1.SelectedColor != Color.Empty) { converter.HeaderBackColor = this.colorPickerButton1.SelectedColor; } if (colorPickerButton2.SelectedColor != Color.Empty) { converter.CaptionBackColor = this.colorPickerButton2.SelectedColor; } //by default ExportPreviewRows is false converter.ExportPreviewRows = this.checkBox2.Checked; converter.ExportGroupPlusMinus = this.checkBox5.Checked; converter.ExportRecordPlusMinus = this.checkBox6.Checked; //Hook QueryExportPreviewRowInfo event for non display elements. if (this.checkBox3.Checked) { //must handle the QueryExportPreviewRowInfo event when the ConverterOptions is //not Visible converter.QueryExportPreviewRowInfo += new GroupingGridExcelConverterControl.GroupingGridExportPreviewRowQueryInfoEventHandler(converter_QueryExportPreviewRowInfo); } else { converter.QueryExportPreviewRowInfo -= new GroupingGridExcelConverterControl.GroupingGridExportPreviewRowQueryInfoEventHandler(converter_QueryExportPreviewRowInfo); } ConverterOptions options = (ConverterOptions)this.comboBox1.SelectedItem; converter.GroupingGridToExcel(this.gridGroupingControl1, saveFileDialog.FileName, options); converter.Dispose(); if (MessageBox.Show("Do you wish to open the xls file now?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = saveFileDialog.FileName; proc.Start(); } } }
/// <summary> /// Initializes a new instance of the <see cref="PathPickerViewModel"/> class. /// </summary> /// <param name="options">The options.</param> /// <param name="view">The view.</param> public PathPickerViewModel(ConverterOptions options, IView view) : base(view, "File/Folder paths", options) { this.BuildConversionOptions(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationProvider"/> class. /// </summary> /// <param name="options">The options.</param> public ConfigurationProvider(ConverterOptions options) { this.options = options; }
public IActionResult Post(ConverterOptions converterOptions) { System.IO.Stream resultStream = null; var startTime = DateTime.Now; var tempFileGuid = Guid.NewGuid(); _logger.LogInformation($"Conversion started: {tempFileGuid} from MD to {converterOptions.To.ToUpper()} / {startTime}"); var htmlFileName = tempFileGuid + ".html"; var cssFileTheme = System.IO.Path.Combine(_env.WebRootPath, "css/markdown.css"); var cssContent = System.IO.File.ReadAllText(cssFileTheme); var resultedContent = converterOptions.To.ToLower() != "html" ? string.Concat("<style>", cssContent, "</style>\n\n", converterOptions.Content) : converterOptions.Content; var file = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(resultedContent)); Aspose.Html.Cloud.Sdk.Api.Model.AsposeResponse response; try { response = _importApi.PostImportMarkdownToHtml(file, htmlFileName); } catch (AggregateException ae) { ae.Handle((x) => { _logger.LogError($"Error file uploading {tempFileGuid}. {x.Message}"); return(true); }); throw; } catch (Exception ex) { _logger.LogError($"Error file uploading {tempFileGuid}. {ex.Message}"); throw; } switch (converterOptions.To.ToLower()) { case "pdf": _logger.LogInformation($"Converter options: {converterOptions.Paper.Size} {converterOptions.Paper.Width}x{converterOptions.Paper.Height}"); var options = SettingsConverter.GetPageSettings(converterOptions); _logger.LogInformation($"Calculated options: {options}"); var streamResponse = _conversionApi.GetConvertDocumentToPdf(htmlFileName, options.Width, options.Height, options.Left, options.Bottom, options.Right, options.Top); if (streamResponse != null && streamResponse.Status == "OK") { try { resultStream = streamResponse.ContentStream; } catch (Exception ex) { _logger.LogError($"Conversion error: {ex.Message}"); throw; } _contentType = "application/pdf"; } break; case "html": try { if (response != null && response.Status == "OK") { resultStream = _storageApi.DownloadFile(htmlFileName).ContentStream; } } catch (Exception ex) { _logger.LogError("Error file downloading {0} {1}", tempFileGuid, ex.Message); throw; } _contentType = "text/html; charset=utf-8"; break; default: throw new NotImplementedException($"MD-to-{converterOptions.To} is not supported."); } if (resultStream == null) { _logger.LogError("Error MD to PDF conversion {0} {1}", tempFileGuid, htmlFileName); throw new Exception("Error MD to PDF conversion"); } var finishTime = DateTime.Now; _logger.LogInformation(message: $"Conversion completed: {tempFileGuid} / {finishTime}"); _logger.LogInformation(message: $"Conversion time: {tempFileGuid} / {finishTime.Subtract(startTime).Milliseconds}ms"); //TODO: Implement gather stats _statisticalService.IncrementCounter(converterOptions.MachineId); return(File(resultStream, _contentType)); }
/// <summary> /// Initializes a new instance of the <see cref="PreferencesViewModel"/> class. /// </summary> /// <param name="options">The options.</param> /// <param name="view">The view.</param> /// <param name="category">The category.</param> public PreferencesViewModel(ConverterOptions options, IView view, PreferenceCategory category) : base(view, category.FriendlyName, options) { this.Category = category; }
/// <summary> /// Initializes a new instance of the <see cref="InstallConverterModCommand"/> class. /// </summary> /// <param name="options">The options.</param> public InstallConverterModCommand(ConverterOptions options) : base(options) { }
/// <summary> /// Initializes a new instance of the <see cref="CommandBase"/> class. /// </summary> /// <param name="options">The options.</param> protected CommandBase(ConverterOptions options) { this.options = options; }