public void ShouldGetColorsSuccessfully() { // Arrange var model = new Model3MF("TestData/ReadmeMulti.3mf"); // Act var colors = model.Colors; // Assert Assert.AreEqual(2, colors.Count); }
public void ShouldGetReadmeSuccessfully() { // Arrange var model = new Model3MF("TestData/ReadmeMulti.3mf"); // Act var readme = model.Readme; // Assert Assert.IsFalse(string.IsNullOrEmpty(readme)); }
private void DropCallback(string id, string req) { ClearCreateExtractionPath(); var trimmedJsDataUrl = req.Trim(new char[] { '[', ']', '"' }); var model3mf = Model3MF.FromBase64DataUrl(trimmedJsDataUrl); model3mf.ExtractPrintProject(_extractionPath); _webview.Return(id, RPCResult.Success, "{ projectFolderUrl: '/extracted' }"); }
public void ShouldGetMeshObjectsSuccessfully() { // Arrange var model = new Model3MF("TestData/ReadmeMulti.3mf"); // Act var meshes = model.Meshes; // Assert Assert.AreEqual(11, meshes.Count); }
private void HandleExtractCommand(FileInfo model, DirectoryInfo dir, bool overwrite) { if (dir.Exists) { Console.WriteLine("Please use a new directory for the extraction!"); } else { dir.Create(); var model3mf = new Model3MF(model.FullName); model3mf.ExtractPrintProject(dir.FullName); } }
public void ShouldLoadModelsSuccessfully() { try { // Act var model = new Model3MF("TestData/PlainMulti.3mf"); model = new Model3MF("TestData/ReadmeMulti.3mf"); } catch (Exception ex) { // Assert Assert.Fail("Expected no exception, but got: " + ex.Message); } }
public void ShouldSetAttachmentSuccessfully() { // Arrange var builder = new Model3MFBuilder(); // Act builder.Set3D2PFile("TestData/3D2P.json"); builder.Write3MF("TestData/Test.3mf", true); // Assert var model = new Model3MF("TestData/Test.3mf"); Assert.IsTrue(model.GetAttachment("/Metadata/3D2P.json") != null); }
public void ShouldSetReadmeSuccessfully() { // Arrange var builder = new Model3MFBuilder(); // Act builder.SetReadme("TestData/README.md"); builder.Write3MF("TestData/Test.3mf", true); // Assert var model = new Model3MF("TestData/Test.3mf"); Assert.IsFalse(string.IsNullOrEmpty(model.Readme)); }
public void ShouldAddStlsSuccessfully() { // Arrange var builder = new Model3MFBuilder(); // Act builder.AddStl("TestData/Test1.stl"); builder.AddStl("TestData/Test2.stl"); builder.Write3MF("TestData/Test.3mf", true); // Assert var model = new Model3MF("TestData/Test.3mf"); Assert.AreEqual(2, model.Meshes.Count); }
public IActionResult OnPost([FromBody] string base64DataUrl) { var result = Content(""); if (!string.IsNullOrEmpty(base64DataUrl)) { var tempProjectFolder = Guid.NewGuid().ToString(); var tempFolder = Path.Combine(_extractionPath, tempProjectFolder); Directory.CreateDirectory(tempFolder); var model3mf = Model3MF.FromBase64DataUrl(base64DataUrl); model3mf.ExtractPrintProject(tempFolder); result = Content(tempProjectFolder); } return(result); }
public void Run(FileInfo model) { var is3MF = model?.Extension.ToUpper() == ".3MF"; if (model == null || is3MF) { // System.CommandLine parses and executes the CLI arguments // in a new Task. Because of this, it is necessary to execute // a new STA Thread to run the webview. Will throw exceptions otherwise. Thread thread = new Thread(() => { var initScript = @"window.printProject = {}; window.printProject.dropCallback = dropCallback;"; if (is3MF) { ClearCreateExtractionPath(); var model3mf = new Model3MF(model.FullName); model3mf.ExtractPrintProject(_extractionPath); initScript += "window.printProject.projectFolderUrl='/extracted';"; } var hostedContent = new HostedContent(); using (_webview = new Webview(false, true)) { _webview .SetTitle("3D2P") .SetSize(1024, 800, WebviewHint.None) .SetSize(800, 800, WebviewHint.Min) .Bind("dropCallback", DropCallback) .InitScript(initScript) .Navigate(hostedContent) .Run(); } }); #if Windows thread.SetApartmentState(ApartmentState.STA); #endif thread.Start(); thread.Join(); } else { Console.WriteLine("This is a 3MF viewer. Please provide a '.3mf' file! Or use '-h' for help."); } }
public void ShouldExtractModelSuccesfully() { // Arrange var builder = new Model3MFBuilder(); builder.AddStl("TestData/Test1.stl"); builder.AddStl("TestData/Test2.stl"); builder.Set3D2PFile("TestData/3D2P.json"); builder.SetReadme("TestData/README.md"); builder.Write3MF("TestData/Test.3mf", true); var model = new Model3MF("TestData/Test.3mf"); // Act model.ExtractPrintProject("TestData/extracted"); // Assert Assert.IsTrue(File.Exists("TestData/extracted/stl/Test1.stl"), "Test1.stl not found!"); Assert.IsTrue(File.Exists("TestData/extracted/stl/Test2.stl"), "Test2.stl not found!"); Assert.IsTrue(File.Exists("TestData/extracted/3D2P.json"), "3D2P.json not found!"); Assert.IsTrue(File.Exists("TestData/extracted/README.md"), "README.md not found!"); Assert.IsTrue(File.ReadAllBytes("TestData/extracted/stl/Test1.stl").Length > 100); }