From 9f7aa3bacb40c4201c3c1bfac3a768758c7a2be4 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 17 Feb 2022 13:25:43 -0800 Subject: [PATCH] Changed queue to be a file library in appdata fixed queue test --- .../ApplicationView/ApplicationController.cs | 4 +- .../Utilities/ManifestFileHandler.cs | 43 ++++++++++++------- .../ExportItemWindowTests.cs | 4 +- .../LibraryActionTests.cs | 3 +- .../PartPreviewTests.cs | 7 ++- .../PrintQueueTests.cs | 4 +- .../ReSliceTests.cs | 6 +-- .../MatterControl/MatterControlUtilities.cs | 7 ++- 8 files changed, 45 insertions(+), 33 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 15e2a5f26..1aee65f97 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -864,8 +864,8 @@ namespace MatterHackers.MatterControl forceAddQueue = true; #endif // only add the queue if there are items in it - var queueDirectory = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Queue"); - LegacyQueueFiles.ImportFromLegacy(queueDirectory); + var queueDirectory = LegacyQueueFiles.QueueDirectory; + LegacyQueueFiles.ImportFromLegacy(); if (forceAddQueue || Directory.Exists(queueDirectory)) { // make sure the queue directory exists diff --git a/MatterControlLib/Utilities/ManifestFileHandler.cs b/MatterControlLib/Utilities/ManifestFileHandler.cs index fb70b172f..b91f62479 100644 --- a/MatterControlLib/Utilities/ManifestFileHandler.cs +++ b/MatterControlLib/Utilities/ManifestFileHandler.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.IO; +using System.Linq; using MatterHackers.MatterControl.DataStorage; using Newtonsoft.Json; @@ -55,41 +56,47 @@ namespace MatterHackers.MatterControl { get { - throw new NotImplementedException(); - } - } + var queueDirectory = LegacyQueueFiles.QueueDirectory; + return Directory.EnumerateFiles(queueDirectory).Count(); + } + } public void AddItem(string filePath) { - throw new NotImplementedException(); - } + var queueDirectory = LegacyQueueFiles.QueueDirectory; + Directory.CreateDirectory(queueDirectory); + var destFile = Path.Combine(queueDirectory, Path.GetFileName(filePath)); + File.Copy(filePath, destFile, true); + } - public string GetFirstItem() + public string GetFirstItem() { - throw new NotImplementedException(); + return new DirectoryInfo(LegacyQueueFiles.QueueDirectory).GetFiles().OrderBy(f => f.LastWriteTime).Select(f => f.FullName).FirstOrDefault(); } public IEnumerable GetItemNames() { - throw new NotImplementedException(); - } - } + return new DirectoryInfo(LegacyQueueFiles.QueueDirectory).GetFiles().Select(f => f.FullName); + } + } public class LegacyQueueFiles { + public static string QueueDirectory => Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Queue"); + public List ProjectFiles { get; set; } - public static void ImportFromLegacy(string destPath) + public static void ImportFromLegacy() { - var filePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "default.mcp"); + var legacyQueuePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "default.mcp"); - if (!File.Exists(filePath)) + if (!File.Exists(legacyQueuePath)) { // nothing to do return; } - string json = File.ReadAllText(filePath); + string json = File.ReadAllText(legacyQueuePath); LegacyQueueFiles newProject = JsonConvert.DeserializeObject(json); if (newProject.ProjectFiles.Count == 0) @@ -97,10 +104,11 @@ namespace MatterHackers.MatterControl return; } - Directory.CreateDirectory(destPath); + var queueDirectory = QueueDirectory; + Directory.CreateDirectory(queueDirectory); foreach (var printItem in newProject.ProjectFiles) { - var destFile = Path.Combine(destPath, Path.ChangeExtension(printItem.Name, Path.GetExtension(printItem.FileLocation))); + var destFile = Path.Combine(queueDirectory, Path.ChangeExtension(printItem.Name, Path.GetExtension(printItem.FileLocation))); if (!File.Exists(destFile) && File.Exists(printItem.FileLocation)) { @@ -108,6 +116,9 @@ namespace MatterHackers.MatterControl File.Copy(printItem.FileLocation, destFile, true); } } + + // and rename the .mcp file no that we have migrated it + File.Move(legacyQueuePath, Path.ChangeExtension(legacyQueuePath, ".bak")); } } } \ No newline at end of file diff --git a/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs b/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs index a476600fa..bac7705f6 100644 --- a/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs +++ b/Tests/MatterControl.AutomationTests/ExportItemWindowTests.cs @@ -17,7 +17,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitForFirstDraw() .AddAndSelectPrinter("Airwolf 3D", "HD") //Navigate to Downloads Library Provider - .NavigateToFolder("Print Queue Row Item Collection") + .NavigateToFolder("Queue Row Item Collection") .InvokeLibraryAddDialog(); //Get parts to add @@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl.Tests.Automation var printer = testRunner.FirstPrinter(); //Navigate to Downloads Library Provider - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); testRunner.InvokeLibraryAddDialog(); //Get parts to add diff --git a/Tests/MatterControl.AutomationTests/LibraryActionTests.cs b/Tests/MatterControl.AutomationTests/LibraryActionTests.cs index 1c486624d..29d7209fc 100644 --- a/Tests/MatterControl.AutomationTests/LibraryActionTests.cs +++ b/Tests/MatterControl.AutomationTests/LibraryActionTests.cs @@ -31,7 +31,6 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.PrintQueue; using NUnit.Framework; namespace MatterHackers.MatterControl.Tests.Automation @@ -51,7 +50,7 @@ namespace MatterHackers.MatterControl.Tests.Automation bool exportWindowExists1 = testRunner.WaitForName("Export Item Window", 0); Assert.IsTrue(exportWindowExists1 == false, "Export window does not exist"); - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); testRunner.ClickByName("Queue Export Button"); SystemWindow containingWindow; GuiWidget exportWindow = testRunner.GetWidgetByName("Export Item Window", out containingWindow, 5); diff --git a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs index f9fe5251c..cf11006d6 100644 --- a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs +++ b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs @@ -278,12 +278,11 @@ namespace MatterHackers.MatterControl.Tests.Automation int expectedCount = QueueData.Instance.ItemCount + 1; - testRunner.SaveBedplateToFolder("Test PartA", "Print Queue Row Item Collection") + testRunner.SaveBedplateToFolder("Test PartA.mcx", "Queue Row Item Collection") .NavigateToLibraryHome() - .NavigateToFolder("Print Queue Row Item Collection"); + .NavigateToFolder("Queue Row Item Collection"); - testRunner.Delay(200); - Assert.IsTrue(testRunner.WaitForName("Row Item Test PartA"), "The part we added should be in the library"); + Assert.IsTrue(testRunner.WaitForName("Row Item Test PartA.mcx"), "The part we added should be in the library"); Assert.AreEqual(expectedCount, QueueData.Instance.ItemCount, "Queue count should increase by one after Save operation"); return Task.CompletedTask; diff --git a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs index 57b04c376..0c744ebe6 100644 --- a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs @@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddAndSelectPrinter(); - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); // Select both items testRunner.SelectListItems("Row Item 2013-01-25_Mouthpiece_v2.stl"); @@ -141,7 +141,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddAndSelectPrinter(); - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); // Select both items testRunner.SelectListItems("Row Item Batman.stl", "Row Item 2013-01-25_Mouthpiece_v2.stl"); diff --git a/Tests/MatterControl.AutomationTests/ReSliceTests.cs b/Tests/MatterControl.AutomationTests/ReSliceTests.cs index ec3107b52..4d462854d 100644 --- a/Tests/MatterControl.AutomationTests/ReSliceTests.cs +++ b/Tests/MatterControl.AutomationTests/ReSliceTests.cs @@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.Tests.Automation }; // Add a cube to the bed - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); testRunner.ClickByName("Row Item cube_20x20x20.stl"); testRunner.ClickByName("Print Library Overflow Menu"); testRunner.ClickByName("Add to Bed Menu Item"); @@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.AreEqual(0, scene.Children.Count); // Add a cylinder - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); testRunner.ClickByName("Row Item cylinder_5x20.stl"); testRunner.ClickByName("Print Library Overflow Menu"); testRunner.ClickByName("Add to Bed Menu Item"); @@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.AreEqual(0, scene.Children.Count); // add the cube - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); testRunner.ClickByName("Row Item cube_20x20x20.stl"); testRunner.ClickByName("Print Library Overflow Menu"); testRunner.ClickByName("Add to Bed Menu Item"); diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index d754ec496..ff3a15ddd 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -317,6 +317,9 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Start New Design"); } + // and close the product tour offer + testRunner.ClickByName("Cancel Wizard Button"); + if (removeDefaultPhil) { testRunner.VerifyAndRemovePhil(); @@ -327,7 +330,7 @@ namespace MatterHackers.MatterControl.Tests.Automation public static void ChangeToQueueContainer(this AutomationRunner testRunner) { - testRunner.NavigateToFolder("Print Queue Row Item Collection"); + testRunner.NavigateToFolder("Queue Row Item Collection"); } public class PrintEmulatorProcess : Process @@ -721,7 +724,7 @@ namespace MatterHackers.MatterControl.Tests.Automation break; case "Cloud Library Row Item Collection": - case "Print Queue Row Item Collection": + case "Queue Row Item Collection": case "Local Library Row Item Collection": break; }