2014-04-15 18:13:27 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Kevin Pope
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-04-15 18:13:27 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-04-15 18:13:27 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-04-15 18:13:27 -07:00
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-04-15 18:13:27 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Diagnostics;
|
2017-09-17 12:01:18 -07:00
|
|
|
|
using System.Globalization;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using System.IO;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2018-03-12 17:02:18 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using MatterHackers.MatterControl.Library;
|
2014-02-15 18:06:03 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrintQueue
|
|
|
|
|
|
{
|
2017-09-17 12:01:18 -07:00
|
|
|
|
public static class PrintItemWrapperExtensionMethods
|
|
|
|
|
|
{
|
|
|
|
|
|
private static TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetFriendlyName(this PrintItemWrapper printItemWrapper)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printItemWrapper?.Name == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return textInfo?.ToTitleCase(printItemWrapper.Name.Replace('_', ' '));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetFriendlyName(string fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (fileName == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return textInfo?.ToTitleCase(fileName.Replace('_', ' '));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class PrintItemWrapper
|
|
|
|
|
|
{
|
2017-09-22 17:36:13 -07:00
|
|
|
|
private string fileType;
|
2018-11-14 14:28:29 -08:00
|
|
|
|
PrinterConfig printer;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
public PrintItemWrapper(PrintItem printItem, ILibraryContainer sourceLibraryProviderLocator = null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-11-14 14:28:29 -08:00
|
|
|
|
this.printer = printer;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.PrintItem = printItem;
|
2015-09-04 09:55:40 -07:00
|
|
|
|
|
2015-09-11 16:57:13 -07:00
|
|
|
|
if (FileLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.fileType = Path.GetExtension(FileLocation).ToUpper();
|
|
|
|
|
|
}
|
2015-07-20 16:09:52 -07:00
|
|
|
|
|
2015-09-11 14:36:57 -07:00
|
|
|
|
SourceLibraryProviderLocator = sourceLibraryProviderLocator;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PrintItemWrapper(int printItemId)
|
|
|
|
|
|
{
|
2018-11-14 14:28:29 -08:00
|
|
|
|
this.printer = printer;
|
2016-02-24 10:52:28 -08:00
|
|
|
|
this.PrintItem = Datastore.Instance.dbSQLite.Table<PrintItem>().Where(v => v.Id == printItemId).Take(1).FirstOrDefault();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2015-09-04 09:55:40 -07:00
|
|
|
|
this.fileType = Path.GetExtension(this.FileLocation).ToUpper();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2015-09-11 10:48:24 -07:00
|
|
|
|
catch(Exception e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-09-11 10:48:24 -07:00
|
|
|
|
Debug.Print(e.Message);
|
2015-09-17 13:45:26 -07:00
|
|
|
|
GuiWidget.BreakInDebugger();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
//file not found
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
public string FileHashCode
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2017-11-21 11:11:07 -08:00
|
|
|
|
if (File.Exists(this.FileLocation))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-11-24 14:51:09 -08:00
|
|
|
|
return HashGenerator.ComputeFileSHA1(this.FileLocation);
|
2015-06-08 17:52:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-21 11:11:07 -08:00
|
|
|
|
return "file-missing";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-17 09:27:08 -07:00
|
|
|
|
public string FileLocation
|
|
|
|
|
|
{
|
2017-09-22 17:36:13 -07:00
|
|
|
|
get => this.PrintItem.FileLocation;
|
|
|
|
|
|
set => this.PrintItem.FileLocation = value;
|
2016-01-11 14:06:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-17 09:27:08 -07:00
|
|
|
|
public string Name
|
|
|
|
|
|
{
|
2017-09-22 17:36:13 -07:00
|
|
|
|
get => this.PrintItem.Name;
|
|
|
|
|
|
set => this.PrintItem.Name = value;
|
2015-06-17 09:27:08 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-22 17:36:13 -07:00
|
|
|
|
public PrintItem PrintItem { get; set; }
|
2015-06-17 09:27:08 -07:00
|
|
|
|
|
2017-09-22 17:36:13 -07:00
|
|
|
|
public bool SlicingHadError { get; private set; } = false;
|
2015-06-17 09:27:08 -07:00
|
|
|
|
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
public ILibraryContainer SourceLibraryProviderLocator { get; private set; }
|
2017-09-22 17:36:13 -07:00
|
|
|
|
|
2016-01-11 14:06:47 -08:00
|
|
|
|
public bool UseIncrementedNameDuringTypeChange { get; internal set; }
|
2015-07-21 08:10:05 -07:00
|
|
|
|
|
2015-06-17 09:27:08 -07:00
|
|
|
|
public void Delete()
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintItem.Delete();
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the Id field after calling delete to clear the association and ensure that future db operations
|
|
|
|
|
|
// result in inserts rather than update statements on a missing row
|
|
|
|
|
|
this.PrintItem.Id = 0;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|