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);
		}
Ejemplo n.º 2
0
        static PrintItemCollection GetRootLibraryCollection2(LibraryProviderSQLite rootLibrary)
        {
            // Attempt to initialize the library from the Datastore if null
            PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table <PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

            // If the _library collection is still missing, create and populate it with default content
            if (rootLibraryCollection == null)
            {
                rootLibraryCollection      = new PrintItemCollection();
                rootLibraryCollection.Name = "_library";
                rootLibraryCollection.Commit();

                // Preload library with Oem supplied list of default parts
                string[] itemsToAdd = SyncCalibrationFilesToDisk(OemSettings.Instance.PreloadedLibraryFiles);
                if (itemsToAdd.Length > 0)
                {
                    // Import any files sync'd to disk into the library, then add them to the queue
                    rootLibrary.AddFilesToLibrary(itemsToAdd);
                }
            }

            return(rootLibraryCollection);
        }
		static PrintItemCollection GetRootLibraryCollection2(LibraryProviderSQLite rootLibrary)
		{
			// Attempt to initialize the library from the Datastore if null
			PrintItemCollection rootLibraryCollection = Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

			// If the _library collection is still missing, create and populate it with default content
			if (rootLibraryCollection == null)
			{
				rootLibraryCollection = new PrintItemCollection();
				rootLibraryCollection.Name = "_library";
				rootLibraryCollection.Commit();

				// Preload library with Oem supplied list of default parts
				string[] itemsToAdd = SyncCalibrationFilesToDisk(OemSettings.Instance.PreloadedLibraryFiles);
				if (itemsToAdd.Length > 0)
				{
					// Import any files sync'd to disk into the library, then add them to the queue
					rootLibrary.AddFilesToLibrary(itemsToAdd);
				}
			}

			return rootLibraryCollection;
		}
		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
		}