Beispiel #1
0
        private static void AddStlOrGcode(string loadedFileName, string extension)
        {
            PrintItem printItem = new PrintItem();

            printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
            printItem.FileLocation          = Path.GetFullPath(loadedFileName);
            printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id;
            printItem.Commit();

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

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    LibraryData.SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave, false);
                    LibraryData.Instance.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        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);
                LibraryData.Instance.AddItem(printItemWrapper);
            }
        }
        void mergeAndSavePartsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] fileList = e.Argument as string[];
            foreach (string loadedFileName in fileList)
            {
                PrintItem printItem = new PrintItem();
                printItem.Name                  = Path.GetFileNameWithoutExtension(loadedFileName);
                printItem.FileLocation          = Path.GetFullPath(loadedFileName);
                printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id;
                printItem.Commit();

                List <MeshGroup> meshToConvertAndSave = MeshFileIo.Load(loadedFileName);

                try
                {
                    PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
                    LibraryData.SaveToLibraryFolder(printItemWrapper, meshToConvertAndSave);
                    LibraryData.Instance.AddItem(printItemWrapper);
                }
                catch (System.UnauthorizedAccessException)
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        //Do something special when unauthorized?
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes, unauthorized access", "Unable to save");
                    });
                }
                catch
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save");
                    });
                }
            }
        }