private void DoneLoadingGCodeToPrint()
		{
			switch (communicationState)
			{
				case CommunicationStates.Connected:
					// This can happen if the printer is reset during the slicing of the part.
					break;

				case CommunicationStates.PreparingToPrint:
					if (ActivePrintItem.PrintItem.Id == 0)
					{
						ActivePrintItem.PrintItem.Commit();
					}

					if (activePrintTask == null)
					{
						// TODO: Fix printerItemID int requirement
						activePrintTask = new PrintTask();
						activePrintTask.PrintStart = DateTime.Now;
						activePrintTask.PrinterId = this.ActivePrinter.ID.GetHashCode();
						activePrintTask.PrintName = ActivePrintItem.PrintItem.Name;
						activePrintTask.PrintItemId = ActivePrintItem.PrintItem.Id;
						activePrintTask.PrintingGCodeFileName = ActivePrintItem.GetGCodePathAndFileName();
						activePrintTask.PrintComplete = false;

						activePrintTask.Commit();
					}

					CommunicationState = CommunicationStates.Printing;
					break;

				default:
#if DEBUG
					throw new Exception("We are not preparing to print so we should not be starting to print");
					//#else
					CommunicationState = CommunicationStates.Connected;
#endif
					break;
			}
		}
		private void loadGCodeWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			switch (communicationState)
			{
				case CommunicationStates.Connected:
					// This can happen if the printer is reset during the slicing of the part.
					break;

				case CommunicationStates.PreparingToPrint:
					if (ActivePrintItem.PrintItem.Id == 0)
					{
						ActivePrintItem.PrintItem.Commit();
					}

					activePrintTask = new PrintTask();
					activePrintTask.PrintStart = DateTime.Now;
					activePrintTask.PrinterId = ActivePrinterProfile.Instance.ActivePrinter.Id;
					activePrintTask.PrintName = ActivePrintItem.PrintItem.Name;
					activePrintTask.PrintItemId = ActivePrintItem.PrintItem.Id;
					activePrintTask.PrintComplete = false;
					activePrintTask.Commit();

					CommunicationState = CommunicationStates.Printing;
					break;

				default:
#if DEBUG
					throw new Exception("We are not preparing to print so we should not be starting to print");
					//#else
					CommunicationState = CommunicationStates.Connected;
#endif
					break;
			}
		}
        public bool StartPrint(string gcodeFileContents)
        {
            if (!PrinterIsConnected || PrinterIsPrinting)
            {
                return false;
            }

            gcodeFileContents = gcodeFileContents.Replace("\r\n", "\n");
            gcodeFileContents = gcodeFileContents.Replace('\r', '\n');
            string[] gcodeLines = gcodeFileContents.Split('\n');
            List<string> printableGCode = new List<string>(gcodeLines.Length);
            foreach (string line in gcodeLines)
            {
                printableGCode.Add(line);
            }

            ExtrusionRatio = 1;
            FeedRateRatio = 1;

            switch(communicationState)
            {
                case CommunicationStates.PreparingToPrintToSd:
                    activePrintTask = null;
                    CommunicationState = CommunicationStates.PrintingToSd;
                    break;

                case CommunicationStates.PreparingToPrint:
                    if (ActivePrintItem.PrintItem.Id == 0)
                    {
                        ActivePrintItem.PrintItem.Commit();
                    }

                    activePrintTask = new PrintTask();
                    activePrintTask.PrintStart = DateTime.Now;
                    activePrintTask.PrinterId = ActivePrinterProfile.Instance.ActivePrinter.Id;
                    activePrintTask.PrintName = ActivePrintItem.PrintItem.Name;
                    activePrintTask.PrintItemId = ActivePrintItem.PrintItem.Id;
                    activePrintTask.PrintComplete = false;
                    activePrintTask.Commit();

                    CommunicationState = CommunicationStates.Printing;
                    break;

                default:
                    throw new NotFiniteNumberException();
            }

            ClearQueuedGCode();
            loadedGCode = GCodeFile.ParseGCodeString(string.Join("\n", printableGCode.ToArray()));

            if (printableGCode.Count == 0)
            {
                return true;
            }

            sendGCodeToPrinterThread = new Thread(SendCurrentGCodeFileToPrinter);
            sendGCodeToPrinterThread.Name = "sendGCodeToPrinterThread - StartPrint";
            sendGCodeToPrinterThread.IsBackground = true;
            sendGCodeToPrinterThread.Start();

            return true;
        }