Example #1
0
        public static void DeleteCacheData()
        {
            if (LibraryProviderSQLite.PreloadingCalibrationFiles)
            {
                return;
            }

            // delete everything in the GCodeOutputPath
            //   AppData\Local\MatterControl\data\gcode
            // delete everything in the temp data that is not in use
            //   AppData\Local\MatterControl\data\temp
            //     plateImages
            //     project-assembly
            //     project-extract
            //     stl
            // delete all unreference models in Library
            //   AppData\Local\MatterControl\Library
            // delete all old update downloads
            //   AppData\updates

            // start cleaning out unused data
            // MatterControl\data\gcode
            RemoveDirectory(DataStorage.ApplicationDataStorage.Instance.GCodeOutputPath);

            string userDataPath = DataStorage.ApplicationDataStorage.ApplicationUserDataPath;

            RemoveDirectory(Path.Combine(userDataPath, "updates"));

            HashSet <string> referencedPrintItemsFilePaths = new HashSet <string>();
            HashSet <string> referencedThumbnailFiles      = new HashSet <string>();

            // Get a list of all the stl and amf files referenced in the queue.
            foreach (PrintItemWrapper printItem in QueueData.Instance.PrintItems)
            {
                string fileLocation = printItem.FileLocation;
                if (!referencedPrintItemsFilePaths.Contains(fileLocation))
                {
                    referencedPrintItemsFilePaths.Add(fileLocation);
                    referencedThumbnailFiles.Add(PartThumbnailWidget.GetImageFileName(printItem));
                }
            }

            // Add in all the stl and amf files referenced in the library.
            foreach (PrintItem printItem in LibraryProviderSQLite.GetAllPrintItemsRecursive())
            {
                PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                string           fileLocation     = printItem.FileLocation;
                if (!referencedPrintItemsFilePaths.Contains(fileLocation))
                {
                    referencedPrintItemsFilePaths.Add(fileLocation);
                    referencedThumbnailFiles.Add(PartThumbnailWidget.GetImageFileName(printItemWrapper));
                }
            }

            // If the count is less than 0 then we have never run and we need to populate the library and queue still. So don't delete anything yet.
            if (referencedPrintItemsFilePaths.Count > 0)
            {
                CleanDirectory(userDataPath, referencedPrintItemsFilePaths, referencedThumbnailFiles);
            }
        }
        public void LibraryProviderSqlite_NavigationWorking()
        {
            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, null, "Local Library");

            testProvider.DataReloaded += (sender, e) => { dataReloaded = true; };
            Thread.Sleep(3000);             // wait for the library to finish initializing
            UiThread.InvokePendingActions();
            Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
            Assert.IsTrue(testProvider.ItemCount == 3, "Start with a new database for these tests.");

            // create a collection and make sure it is on disk
            dataReloaded = false;             // it has been loaded for the default set of parts
            string collectionName = "Collection1";

            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB
            Assert.IsTrue(dataReloaded == false);
            testProvider.AddCollectionToLibrary(collectionName);
            Assert.IsTrue(testProvider.CollectionCount == 1);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(NamedCollectionExists(collectionName));             // assert that the record does exist in the DB

            PrintItemWrapper itemAtRoot = testProvider.GetPrintItemWrapperAsync(0).Result;

            // add an item works correctly
            dataReloaded = false;
            Assert.IsTrue(!NamedItemExists(collectionName));
            Assert.IsTrue(dataReloaded == false);

            testProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
            Thread.Sleep(3000);             // wait for the add to finish
            UiThread.InvokePendingActions();

            Assert.IsTrue(testProvider.ItemCount == 4);
            Assert.IsTrue(dataReloaded == true);
            string fileNameWithExtension = Path.GetFileNameWithoutExtension(meshPathAndFileName);

            Assert.IsTrue(NamedItemExists(fileNameWithExtension));

            // make sure the provider locater is correct

            // remove item works
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveItem(0);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(!NamedItemExists(fileNameWithExtension));

            // remove collection gets rid of it
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveCollection(0);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(testProvider.CollectionCount == 0);
            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB

            //MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
        }
        public void LoadCalibrationPrints()
        {
            if (this.ActivePrinter.Make != null && this.ActivePrinter.Model != null)
            {
                // Load the calibration file names
                List <string> calibrationPrintFileNames = LoadCalibrationPartNamesForPrinter(this.ActivePrinter.Make, this.ActivePrinter.Model);

                var libraryProvider = new LibraryProviderSQLite(null, null, null, "Local Library");
                libraryProvider.EnsureSamplePartsExist(calibrationPrintFileNames);

                var queueItems = QueueData.Instance.GetItemNames();

                // Finally, ensure missing calibration parts are added to the queue if missing
                var filenamesWithoutExtensions = calibrationPrintFileNames.Select(f => Path.GetFileNameWithoutExtension(f));
                foreach (string nameOnly in filenamesWithoutExtensions)
                {
                    if (queueItems.Contains(nameOnly))
                    {
                        continue;
                    }

                    // Find the first library item with the given name and add it to the queue
                    PrintItem libraryItem = libraryProvider.GetLibraryItems(nameOnly).FirstOrDefault();
                    if (libraryItem != null)
                    {
                        QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem));
                    }
                }

                libraryProvider.Dispose();
            }
        }
        public void LibraryProviderSqlite_NavigationWorking()
        {
            Datastore.Instance.Initialize();
            LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null);

            Thread.Sleep(3000);             // wait for the library to finish initializing
            Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
            Assert.IsTrue(testProvider.ItemCount == 1, "Start with a new database for these tests.");

            // create a collection and make sure it is on disk
            dataReloaded = false;             // it has been loaded for the default set of parts
            string collectionName = "Collection1";

            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB
            Assert.IsTrue(dataReloaded == false);
            testProvider.AddCollectionToLibrary(collectionName);
            Assert.IsTrue(testProvider.CollectionCount == 1);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(NamedCollectionExists(collectionName));             // assert that the record does exist in the DB

            PrintItemWrapper           itemAtRoot      = testProvider.GetPrintItemWrapper(0);
            List <ProviderLocatorNode> providerLocator = itemAtRoot.PrintItem.GetLibraryProviderLocator();

            Assert.IsTrue(providerLocator.Count == 1);

            // add an item works correctly
            dataReloaded = false;
            Assert.IsTrue(!NamedItemExists(collectionName));
            Assert.IsTrue(dataReloaded == false);

            testProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
            Thread.Sleep(3000);             // wait for the add to finihs

            Assert.IsTrue(testProvider.ItemCount == 2);
            Assert.IsTrue(dataReloaded == true);
            string fileNameWithExtension = Path.GetFileNameWithoutExtension(meshPathAndFileName);

            Assert.IsTrue(NamedItemExists(fileNameWithExtension));

            // make sure the provider locator is correct

            // remove item works
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveItem(testProvider.GetPrintItemWrapper(1));
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(!NamedItemExists(fileNameWithExtension));

            // remove collection gets rid of it
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveCollection(testProvider.GetCollectionItem(0));
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(testProvider.CollectionCount == 0);
            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB
        }
Example #5
0
        public void LoadCalibrationPrints()
        {
            // Load the calibration file names
            string calibrationFiles = ActiveSliceSettings.Instance.GetValue("calibration_files");

            if (string.IsNullOrEmpty(calibrationFiles))
            {
                return;
            }

            string[] calibrationPrintFileNames = calibrationFiles.Split(';');
            if (calibrationPrintFileNames.Length < 1)
            {
                return;
            }

            var libraryProvider = new LibraryProviderSQLite(null, null, null, "Local Library");

            libraryProvider.EnsureSamplePartsExist(calibrationPrintFileNames);

            var queueItems = QueueData.Instance.GetItemNames();

            // Finally, ensure missing calibration parts are added to the queue if missing
            var filenamesWithoutExtensions = calibrationPrintFileNames.Select(f => Path.GetFileNameWithoutExtension(f));

            foreach (string nameOnly in filenamesWithoutExtensions)
            {
                if (queueItems.Contains(nameOnly))
                {
                    continue;
                }

                // Find the first library item with the given name and add it to the queue
                PrintItem libraryItem = libraryProvider.GetLibraryItems(nameOnly).FirstOrDefault();
                if (libraryItem != null)
                {
                    QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem));
                }
            }

            libraryProvider.Dispose();
        }
Example #6
0
        public async Task LoadCalibrationPrints()
        {
            if (this.ActivePrinter.Make != null && this.ActivePrinter.Model != null)
            {
                // Load the calibration file names
                List <string> calibrationPrintFileNames = LoadCalibrationPartNamesForPrinter(this.ActivePrinter.Make, this.ActivePrinter.Model);

                using (LibraryProviderSQLite instance = new LibraryProviderSQLite(null, null, null, "Local Library"))
                {
                    await instance.EnsureSamplePartsExist(calibrationPrintFileNames);
                }

                var queueItems = QueueData.Instance.GetItemNames();

                // Finally, ensure missing calibration parts are added to the queue if missing
                var filenamesWithoutExtensions = calibrationPrintFileNames.Select(f => Path.GetFileNameWithoutExtension(f));
                foreach (string nameOnly in filenamesWithoutExtensions)
                {
                    if (queueItems.Contains(nameOnly))
                    {
                        continue;
                    }

                    // If the library item does not exist in the queue, add it
                    IEnumerable <PrintItem> libraryItems = null;
                    using (LibraryProviderSQLite instance = new LibraryProviderSQLite(null, null, null, "Local Library"))
                    {
                        libraryItems = instance.GetLibraryItems(nameOnly);
                    }

                    foreach (PrintItem libraryItem in libraryItems)
                    {
                        if (libraryItem != null)
                        {
                            QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem));
                        }
                    }
                }
            }
        }