Ejemplo n.º 1
0
        private static void AddStlOrGcode(LibraryProviderSQLite libraryToAddTo, string loadedFileName, string extension)
        {
            PrintItem printItem = new PrintItem();

            printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
            printItem.FileLocation          = Path.GetFullPath(loadedFileName);
            printItem.PrintItemCollectionID = libraryToAddTo.baseLibraryCollection.Id;
            printItem.Commit();

            if (MeshFileIo.ValidFileExtensions().Contains(extension))
            {
                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
                    libraryToAddTo.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle(() =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
            else             // it is not a mesh so just add it
            {
                PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                if (false)
                {
                    libraryToAddTo.AddItem(printItemWrapper);
                }
                else                 // save a copy to the library and update this to point at it
                {
                    string sourceFileName = printItem.FileLocation;
                    string newFileName    = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
                    string destFileName   = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);

                    File.Copy(sourceFileName, destFileName, true);

                    printItemWrapper.FileLocation = destFileName;
                    printItemWrapper.PrintItem.Commit();

                    // let the queue know that the item has changed so it load the correct part
                    libraryToAddTo.AddItem(printItemWrapper);
                }
            }
        }
		private static void AddStlOrGcode(LibraryProviderSQLite libraryToAddTo, string loadedFileName, string extension)
		{
			PrintItem printItem = new PrintItem();
			printItem.Name = Path.GetFileNameWithoutExtension(loadedFileName);
			printItem.FileLocation = Path.GetFullPath(loadedFileName);
			printItem.PrintItemCollectionID = libraryToAddTo.baseLibraryCollection.Id;
			printItem.Commit();

			if (MeshFileIo.ValidFileExtensions().Contains(extension))
			{
				List<MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

				try
				{
					PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
					SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
					libraryToAddTo.AddItem(printItemWrapper);
				}
				catch (System.UnauthorizedAccessException)
				{
					UiThread.RunOnIdle(() =>
					{
						//Do something special when unauthorized?
						StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
					});
				}
				catch
				{
					UiThread.RunOnIdle(() =>
					{
						StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
					});
				}
			}
			else // it is not a mesh so just add it
			{
				PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
				if (false)
				{
					libraryToAddTo.AddItem(printItemWrapper);
				}
				else // save a copy to the library and update this to point at it
				{
					string sourceFileName = printItem.FileLocation;
					string newFileName = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
					string destFileName = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);

					File.Copy(sourceFileName, destFileName, true);

					printItemWrapper.FileLocation = destFileName;
					printItemWrapper.PrintItem.Commit();

					// let the queue know that the item has changed so it load the correct part
					libraryToAddTo.AddItem(printItemWrapper);
				}
			}
		}