public List <PrintItem> NewPrintItemListForImport(List <PrintItem> printItemList) { List <PrintItem> newPrintItemList = new List <PrintItem>(); foreach (var printItem in printItemList) { string userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath; string partName = Path.GetFileName(printItem.FileLocation); string pathToRenameForImport = Path.Combine(userDataPath, "data", "QueueItems"); PrintItem newPrintItem = new PrintItem(); newPrintItem.DateAdded = printItem.DateAdded; newPrintItem.Name = printItem.Name; newPrintItem.PrintCount = printItem.PrintCount; newPrintItem.PrintItemCollectionID = printItem.PrintItemCollectionID; newPrintItem.ReadOnly = printItem.ReadOnly; newPrintItem.Protected = printItem.Protected; if (printItem.FileLocation.Contains("[QueueItems]")) { newPrintItem.FileLocation = Path.Combine(pathToRenameForImport, partName); } else { newPrintItem.FileLocation = printItem.FileLocation; } newPrintItemList.Add(newPrintItem); } return(newPrintItemList); }
private async Task <PrintItemWrapper> MakeCopyForQueue() { var printItemWrapper = await this.GetPrintItemWrapperAsync(); // Handle non-existing files if (!File.Exists(printItemWrapper.FileLocation)) { return(null); } PrintItem printItemToCopy = printItemWrapper.PrintItem; string fileName = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItemToCopy.FileLocation)); string newFileLocation = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); // Handle file read/write errors try { File.Copy(printItemToCopy.FileLocation, newFileLocation); } catch (Exception ex) { string errorMessage = string.Format("Unable to duplicate file for queue: {0}\r\n{1}", printItemToCopy.FileLocation, ex.Message); Trace.WriteLine(errorMessage); return(null); } return(new PrintItemWrapper(new PrintItem(printItemToCopy.Name, newFileLocation) { Protected = printItemToCopy.Protected })); }
void mergeAndSavePartsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string filePath = e.Result as string; if (filePath != null) { PrintItem printItem = new PrintItem(); printItem.Commit(); printItem.Name = string.Format("{0}", word); printItem.FileLocation = Path.GetFullPath(filePath); printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id; printItem.Commit(); PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); LibraryData.Instance.AddItem(printItemWrapper); // and save to the queue { QueueData.Instance.AddItem(printItemWrapper); } } //Exit after save UiThread.RunOnIdle(CloseOnIdle); }
public void PrintItemsExemptTest() { // Arrange _fileRepositoryMock .Setup(mock => mock.ReadLines(It.IsAny <string>())) .Returns( new List <string> { $"print-item1 19.99 {exemptString}", "print-item2 29.99", $"print-item3 39.99 {exemptString}" }); var jobsFileRepository = new JobsFileRepository(_fileRepositoryMock.Object); // Act var job = jobsFileRepository.ReadJobFromFile("fakeFilePath"); // Assert var expectedOuput = Job.Create( false, new List <PrintItem> { PrintItem.Create("print-item1", 19.99m, true), PrintItem.Create("print-item2", 29.99m, false), PrintItem.Create("print-item3", 39.99m, true) }); Assert.That(job, Is.EqualTo(expectedOuput).Using(new JobEqualityComparer())); }
private void PreLoadItemToQueue(PrintItem printItem) { string fileDest = printItem.FileLocation; if (!string.IsNullOrEmpty(fileDest) && File.Exists(fileDest)) { var printItemToAdd = new PrintItemWrapper(printItem); // check if there is a thumbnail image for this file and load it into the user cache if so string justThumbFile = printItem.Name + ".png"; string applicationUserDataPath = StaticData.Instance.MapPath(Path.Combine("OEMSettings", "SampleParts")); string thumbnailSourceFile = Path.Combine(applicationUserDataPath, justThumbFile); if (File.Exists(thumbnailSourceFile)) { string thumbnailDestFile = PartThumbnailWidget.GetImageFileName(printItemToAdd); Directory.CreateDirectory(Path.GetDirectoryName(thumbnailDestFile)); // copy it to the right place File.Copy(thumbnailSourceFile, thumbnailDestFile); } QueueData.Instance.AddItem(printItemToAdd); } }
private PrintItem ReadPrintItem(string line) { var printItemParts = line.Split(' '); var lineParts = printItemParts.Length; if (lineParts != 2 && lineParts != 3) { throw new InvalidOperationException($"Print item line {line} does not contain enough data"); } decimal itemCost; if (!decimal.TryParse(printItemParts[1], out itemCost)) { throw new InvalidOperationException($"Cannot parse the cost for item {line}"); } var exempt = lineParts == 3 && string.Equals( printItemParts[2], taxExemptLine, StringComparison.OrdinalIgnoreCase); //TO DO return(PrintItem.Create( printItemParts[0], itemCost, exempt)); }
public void compileString() { for (int i = 0; i < printList.items.Count; i++) { PrintItem thisItem = printList.items[i]; if (thisItem.stringExpr == null) { printNumericExpression(thisItem.numExpr); } else { printStringExpression(thisItem.stringExpr); } if (i < printList.separators.Count) { PrintList.printseparator thisSeparator = printList.separators[i]; if (thisSeparator == PrintList.printseparator.COMMA) { printLiteral(","); } if (thisSeparator == PrintList.printseparator.SEMICOLON) { printLiteral(";"); } } } printLiteral("\r\n"); }
public void SetObjectFromCombo() { if (selectingobject) { return; } if (CurrentList.Count == 0) { return; } if (ComboSelection.SelectedIndex > CurrentList.Count - 1) { return; } ReportItem ritem = CurrentList[ComboSelection.SelectedIndex]; if (!(ritem is PrintItem)) { return; } PrintItem nitem = (PrintItem)ritem; SubReportEdit.SelectPrintItem(nitem); }
private static void writeNormal(PrintItem item) { writeDefaultHeader(item); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(item.message); Console.ForegroundColor = ConsoleColor.Gray; }
private static void writeRed(PrintItem item) { writeDefaultHeader(item); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(item.message); Console.ForegroundColor = ConsoleColor.Gray; }
private async void MergeAndSavePartsToStl() { if (MeshGroups.Count > 0) { partSelectButtonWasClicked = viewControls3D.ActiveButton == ViewControls3DButtons.PartSelect; processingProgressControl.ProcessType = "Saving Parts:".Localize(); processingProgressControl.Visible = true; processingProgressControl.PercentComplete = 0; LockEditControls(); // we sent the data to the asynch lists but we will not pull it back out (only use it as a temp holder). PushMeshGroupDataToAsynchLists(true); string fileName = "TextCreator_{0}".FormatWith(Path.ChangeExtension(Path.GetRandomFileName(), ".amf")); string filePath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); processingProgressControl.RatioComplete = 0; await Task.Run(() => mergeAndSavePartsBackgroundWorker_DoWork(filePath)); PrintItem printItem = new PrintItem(); printItem.Name = string.Format("{0}", word); printItem.FileLocation = Path.GetFullPath(filePath); PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); // and save to the queue QueueData.Instance.AddItem(printItemWrapper); //Exit after save UiThread.RunOnIdle(CloseOnIdle); } }
private void ViewButton_Click(object sender, EventArgs e) { this.rightButtonOverlay.SlideOut(); PrintItem printItem = DataStorage.Datastore.Instance.dbSQLite.Table <DataStorage.PrintItem>().Where(v => v.Id == this.printTask.PrintItemId).Take(1).FirstOrDefault(); if (printItem != null) { string pathAndFile = printItem.FileLocation; if (File.Exists(pathAndFile)) { bool shiftKeyDown = Keyboard.IsKeyDown(Keys.ShiftKey); if (shiftKeyDown) { OpenPartPreviewWindow(printItem, View3DWidget.AutoRotate.Disabled); } else { OpenPartPreviewWindow(printItem, View3DWidget.AutoRotate.Enabled); } } else { PrintItemWrapper itemWrapper = new PrintItemWrapper(printItem); ShowCantFindFileMessage(itemWrapper); } } }
public void LoadCalibrationPrints() { if (this.ActivePrinter.Make != null && this.ActivePrinter.Model != null) { // Load the calibration file names List <string> calibrationPrintFileNames = LoadCalibrationPartNamesForPrinter(this.ActivePrinter.Make, this.ActivePrinter.Model); var libraryProvider = new LibraryProviderSQLite(null, null, null, "Local Library"); libraryProvider.EnsureSamplePartsExist(calibrationPrintFileNames); var queueItems = QueueData.Instance.GetItemNames(); // Finally, ensure missing calibration parts are added to the queue if missing var filenamesWithoutExtensions = calibrationPrintFileNames.Select(f => Path.GetFileNameWithoutExtension(f)); foreach (string nameOnly in filenamesWithoutExtensions) { if (queueItems.Contains(nameOnly)) { continue; } // Find the first library item with the given name and add it to the queue PrintItem libraryItem = libraryProvider.GetLibraryItems(nameOnly).FirstOrDefault(); if (libraryItem != null) { QueueData.Instance.AddItem(new PrintItemWrapper(libraryItem)); } } libraryProvider.Dispose(); } }
public List <PrintItem> NewPrintItemListToExport(List <PrintItem> printItemList) { List <PrintItem> newPrintItemList = new List <PrintItem>(); foreach (var printItem in printItemList) { string pathToRenameForExport = printItem.FileLocation; string partName = Path.GetFileName(pathToRenameForExport); string exportedFilePath = "[QueueItems]\\" + partName; PrintItem newPrintItem = new PrintItem(); newPrintItem.DateAdded = printItem.DateAdded; newPrintItem.Name = printItem.Name; newPrintItem.PrintCount = printItem.PrintCount; newPrintItem.PrintItemCollectionID = printItem.PrintItemCollectionID; newPrintItem.ReadOnly = printItem.ReadOnly; newPrintItem.Protected = printItem.Protected; if (pathToRenameForExport.Contains("C:\\")) { newPrintItem.FileLocation = exportedFilePath; } else { newPrintItem.FileLocation = printItem.FileLocation; } newPrintItemList.Add(newPrintItem); } return(newPrintItemList); }
void exchange(int i, int j) { PrintItem temp = itemList[i]; itemList[i] = itemList[j]; itemList[j] = temp; }
private void txtBarcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string[] barcode = txtBarcode.Text.Split(';'); //Label of PREMAC 6-4-9 have more 2 fields lbData = new PrintItem { Item_Number = barcode[0].Trim(), Item_Name = barcode[1].Trim(), SupplierName = barcode[2].Trim(), Invoice = barcode[3].Trim(), Delivery_Date = DateTime.Parse(barcode[4].Trim()), Delivery_Qty = int.Parse(barcode[5].Trim()), SupplierCD = string.Empty, Remark = string.Empty }; if (barcode.Length > 7) { if (!string.IsNullOrEmpty(barcode[6])) { lbData.SupplierCD = barcode[6].Trim(); } if (!string.IsNullOrEmpty(barcode[7])) { lbData.Remark = barcode[7].Trim(); } } txtInsInvoice.Text = lbData.Invoice; txtInQty.Text = lbData.Delivery_Qty.ToString(); txtLabelQty.Focus(); } }
private void SubmitForm() { string newName = textToAddWidget.ActualTextEditWidget.Text; if (newName != "") { string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".amf"); string fileNameAndPath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName); PrintItem printItem = new PrintItem(); printItem.Name = newName; printItem.FileLocation = Path.GetFullPath(fileNameAndPath); printItem.PrintItemCollectionID = LibraryData.Instance.LibraryCollection.Id; printItem.Commit(); PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem); QueueData.Instance.AddItem(printItemWrapper); if (addToLibraryOption.Checked) { LibraryData.Instance.AddItem(printItemWrapper); } functionToCallOnSaveAs(printItemWrapper); CloseOnIdle(); } }
private static void writeDefaultHeader(PrintItem item) { Console.Write("[" + item.dateTimenow + ":" + item.milliSecond + "] ["); Console.ForegroundColor = ConsoleColor.Green; Console.Write(item.className + "." + item.methodName); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("] » "); }
private PrintItem GetPrintItemFromFile(string fileName, string displayName) { PrintItem item = new PrintItem(); item.FileLocation = fileName; item.Name = displayName; return(item); }
public static void Print(int copies) { for (int i = 1; i <= copies; ++i) { Console.WriteLine("{0}:{1} from thread<{2}>", i, PrintItem.Read(), Thread.CurrentThread.ManagedThreadId); Worker.DoWork(i); } }
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; }
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); } } }
public PrintQueueItem(string displayName, string fileLocation) { PrintItem printItem = new PrintItem(); printItem.Name = displayName; printItem.FileLocation = fileLocation; this.PrintItemWrapper = new PrintItemWrapper(printItem); ConstructPrintQueueItem(); }
private static void writeSpecialLineWithHeaderHead(PrintItem item) { writeDefaultHeader(item); Console.ForegroundColor = item.colorOne; Console.Write(item.headerText); Console.ForegroundColor = item.colorTwo; Console.WriteLine(item.message); Console.ForegroundColor = ConsoleColor.Gray; }
/// <summary> /// Enqueues an item /// </summary> /// <param name="item"></param> private static void enQueueItem(PrintItem item) { if (loggin) { lock (queItem.SyncRoot) { queItem.Enqueue(item); } } }
public void MoveSelectedToBottom() { if (SelectedIndex >= 0 && SelectedIndex < Count) { int currentIndex = SelectedIndex; PrintItem replacementItem = new PrintItem(SelectedPrintItem.Name, SelectedPrintItem.FileLocation); QueueData.Instance.RemoveAt(SelectedIndex); this.SelectedIndex = currentIndex; } }
public void RemoveAllSdCardFiles() { for (int i = ItemCount - 1; i >= 0; i--) { PrintItem printItem = PrintItems[i].PrintItem; if (printItem.FileLocation == QueueData.SdCardFileName) { RemoveAt(i); } } }
private static void writeSpecialColorLine(PrintItem item) { Console.Write("[" + item.dateTimenow + ":" + item.milliSecond + "] ["); Console.ForegroundColor = item.colorOne; Console.Write(item.className + "." + item.methodName); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("] » "); Console.ForegroundColor = item.colorTwo; Console.WriteLine(item.message); Console.ForegroundColor = ConsoleColor.Gray; }
public PrintItemWrapper(PrintItem printItem, List <ProviderLocatorNode> sourceLibraryProviderLocator = null) { this.PrintItem = printItem; if (FileLocation != null) { this.fileType = Path.GetExtension(FileLocation).ToUpper(); } SourceLibraryProviderLocator = sourceLibraryProviderLocator; }
public PrintItemWrapper(PrintItem printItem, ILibraryContainer sourceLibraryProviderLocator = null) { this.printer = printer; this.PrintItem = printItem; if (FileLocation != null) { this.fileType = Path.GetExtension(FileLocation).ToUpper(); } SourceLibraryProviderLocator = sourceLibraryProviderLocator; }
public static void Main() { int T = int.Parse(Console.ReadLine()); while (T--> 0) { string[] tokens = Console.ReadLine().Split(); int n = int.Parse(tokens[0]); int m = int.Parse(tokens[1]); tokens = Console.ReadLine().Split(); Queue<PrintItem> queue = new Queue<PrintItem>(); PriorityQueue priority_queue = new PriorityQueue(); for (int i = 0; i < n; i++) { int pr = int.Parse(tokens[i]); PrintItem item = new PrintItem(i, pr); queue.Enqueue(item); priority_queue.Enqueue(item); } priority_queue.buildHeap(); int count = 0; PrintItem highPItem = priority_queue.extractMin(); ; while (queue.Count > 0) { PrintItem item = queue.Dequeue(); if (item.Priority == highPItem.Priority) { // add its print time count++; if (item.Index == m) break; highPItem = priority_queue.extractMin(); } else // we did not get high priority item push into queue { queue.Enqueue(item); } } Console.WriteLine(count); } }
private static void writePlain(PrintItem item) { Console.WriteLine(item.message); }
int heapSearch(PrintItem PrintItem) { for (int i = 0; i < heapSize; i++) { PrintItem aPrintItem = itemList[i]; if (PrintItem.Index == aPrintItem.Index) return i; } return -1; }
//Must go to the Draw Engine public static void PrintOnPosition(int row, int col, ConsoleColor color = ConsoleColor.DarkGray) { PrintItem toPrint = new PrintItem(" ", col, row, color, true); stuffToPrint.Enqueue(toPrint); }
public static void PrintStringOnPosition(int row, int col, string phrase, ConsoleColor color = ConsoleColor.White) { PrintItem toPrint = new PrintItem(phrase, col, row, color); stuffToPrint.Enqueue(toPrint); }
private static void printEmpty(PrintItem item) { Console.WriteLine(); }
private static void fileWriter(PrintItem item) { writeToFile(item.headerText, item.message); }
public int find(PrintItem PrintItem) { return heapSearch(PrintItem); }
// requires public public void Enqueue(PrintItem PrintItem) { heapSize++; itemList.Add(PrintItem); }