private void copyMsgBox_Result(object sender, DialogEventArgs e) { //If a File is selected select the folder its in if (!_selectedItem.Is_Dir) { _selectedItem = _selectedItem.Parent; } Host.Cursor = Cursors.WaitCursor; if (e.Result == DialogResult.OK) { //copy if (!Form1.Instance.DropBox.CopyFile(_clipboard, _selectedItem)) { Host.Cursor = Cursors.Default; MessageDialog.Show("Failed to Copy!", null, "OK"); } } else if (e.Result == DialogResult.Cancel) { //move if (!Form1.Instance.DropBox.MoveFile(_clipboard, _selectedItem)) { Host.Cursor = Cursors.Default; MessageDialog.Show("Failed to Move!", null, "OK"); } } lsbDropbox.Items = ListHelpers.MakeDirList(Form1.Instance.DropBox.GetItems(_selectedItem)); Host.Cursor = Cursors.Default; _clipboard = null; }
/// <summary> /// Initializes a new instance of the <see cref="BasicNode"/> class. /// </summary> /// <param name="context">The node context.</param> public InputSelector(INodeContext context) : base(context, INPUT_PREFIX) { context.ThrowIfNull("context"); mTypeService = context.GetService <ITypeService>(); // Initialize the input count, allowing range 2..99. mInputCount = mTypeService.CreateInt(PortTypes.Integer, "InputCount", 2); mInputCount.MinValue = 2; mInputCount.MaxValue = 50; // Initialize inputs using a helper function that grows/shrinks the list of inputs // whenever the input count is changed mInputs = new List <AnyValueObject>(); ListHelpers.ConnectListToCounter(mInputs, mInputCount, mTypeService.GetValueObjectCreator(PortTypes.Any, INPUT_PREFIX), updateOutputValues); // Initialize the input for the index of the input to select. mSelectIndexInput = mTypeService.CreateInt(PortTypes.Integer, "InputSelectIndex"); mSelectIndexInput.MinValue = 0; mSelectIndexInput.MaxValue = mInputCount.MaxValue - 1; mSelectIndexInput.ValueSet += updateOutputValues; // Initialize the selector for "send-on-select". mSelectAction = mTypeService.CreateEnum("ESelectAction2", "SelectAction2", mSelectActionValues, "ResendCurrent"); // Initialize the output mOutput = mTypeService.CreateAny(PortTypes.Any, "Output"); }
private void newFolder_submit(object sender, DialogEventArgs e) { if (e.Result != DialogResult.OK) { return; } //If a File is selected select the folder its in if (!_selectedItem.Is_Dir) { _selectedItem = _selectedItem.Parent; } var folderName = textInputPanel.Data; Host.Cursor = Cursors.WaitCursor; var newSelected = Form1.Instance.DropBox.CreateFolder(_selectedItem, folderName); if (newSelected != null) { newSelected.Parent = _selectedItem; _selectedItem.Contents.Add(newSelected); _selectedItem = newSelected; lsbDropbox.Items = ListHelpers.MakeDirList(_selectedItem); lsbDropbox.SelectedItemIndex = -1; header.Title = _selectedItem.Name; Host.Cursor = Cursors.Default; } else { //show error...? Host.Cursor = Cursors.Default; MessageDialog.Show("Create Folder Failed!", null, "OK"); } }
public void Question_2_1_BasicCases() { // No duplicates var l1 = ListHelpers.CreateLinkedList(1, 2, 3); var expected = ListHelpers.CloneList(l1); this.ValidateResult(expected, l1); // Several (3x) duplicates var l2 = ListHelpers.CreateLinkedList(1, 1, 1); expected = ListHelpers.CreateLinkedList(1); this.ValidateResult(expected, l2); // two sets of duplicates, one next to each other one separated var l3 = ListHelpers.CreateLinkedList(1, 2, 2, 1); expected = ListHelpers.CreateLinkedList(1, 2); this.ValidateResult(expected, l3); // 3x duplicate case split up var l4 = ListHelpers.CreateLinkedList(1, 2, 2, 3, 2); expected = ListHelpers.CreateLinkedList(1, 2, 3); this.ValidateResult(expected, l4); // Several duplicates in the list var l5 = ListHelpers.CreateLinkedList(1, 2, 2, 1, 3, 4, 7, 5, 6, 2, 3, 4, 5, 6); expected = ListHelpers.CreateLinkedList(1, 2, 3, 4, 7, 5, 6); this.ValidateResult(expected, l5); }
/// <summary> /// Creates a clone of this instance /// </summary> /// <returns>Clone of this instance</returns> public object Clone() { MachineModel clone = new MachineModel { Channels = (Channels)Channels.Clone(), Electronics = (Electronics)Electronics.Clone(), Heat = (Heat)Heat.Clone(), Job = (Job)Job.Clone(), MessageBox = (MessageBox)MessageBox.Clone(), Move = (Move)Move.Clone(), Network = (Network)Network.Clone(), Scanner = (Scanner)Scanner.Clone(), Sensors = (Sensors)Sensors.Clone(), State = (State)State.Clone() }; ListHelpers.CloneItems(clone.Fans, Fans); ListHelpers.CloneItems(clone.Messages, Messages); ListHelpers.CloneItems(clone.Spindles, Spindles); ListHelpers.CloneItems(clone.Storages, Storages); ListHelpers.CloneItems(clone.Tools, Tools); ListHelpers.CloneItems(clone.UserVariables, UserVariables); return(clone); }
public void Question_2_7_BasicCases() { var l1 = ListHelpers.CreateLinkedList(1, 2); var l2 = ListHelpers.CreateLinkedList(3, 4); var intersection = ListHelpers.CreateLinkedList(5, 6); AddIntersection(l1, l2, intersection); Validate(intersection, l1, l2); l1 = ListHelpers.CreateLinkedList(1); l2 = ListHelpers.CreateLinkedList(2); intersection = ListHelpers.CreateLinkedList(3); AddIntersection(l1, l2, intersection); Validate(intersection, l1, l2); l1 = ListHelpers.CreateLinkedList(1, 2, 3, 4); l2 = ListHelpers.CreateLinkedList(2); intersection = ListHelpers.CreateLinkedList(5); AddIntersection(l1, l2, intersection); Validate(intersection, l1, l2); l1 = ListHelpers.CreateLinkedList(1, 2, 3, 4); l2 = ListHelpers.CreateLinkedList(2, 2, 2, 2); intersection = ListHelpers.CreateLinkedList(5, 4, 3, 2, 3); AddIntersection(l1, l2, intersection); Validate(intersection, l1, l2); intersection = ListHelpers.CreateLinkedList(4); Validate(intersection, intersection, intersection); }
public static void Execute(Vegas vegas) { var videoTracks = VegasHelper.GetTracks <VideoTrack>(vegas, 1); var selectedTrackEvents = VegasHelper.GetTrackEvents(videoTracks); var currentPosition = selectedTrackEvents[0].Start; //order the list ListHelpers.Shuffle(selectedTrackEvents, new Random()); using (var undo = new UndoBlock("Randomize Events")) { //update order of the events foreach (var selectedTrackEvent in selectedTrackEvents) { if (selectedTrackEvent.IsGrouped) { foreach (var groupedTrackEvents in selectedTrackEvent.Group) { groupedTrackEvents.Start = currentPosition; } } else { selectedTrackEvent.Start = currentPosition; } currentPosition += selectedTrackEvent.Length; } } }
public void Question_2_2_EdgeCases() { // 1 => 1 - Only one element. var l1 = ListHelpers.CreateLinkedList(1); Assert.AreEqual(1, Question_2_2.ReturnKthToLast(l1, 0)); }
/// <summary> /// Assigns every property from another instance /// </summary> /// <param name="from">Object to assign from</param> /// <exception cref="ArgumentNullException">other is null</exception> /// <exception cref="ArgumentException">Types do not match</exception> public void Assign(object from) { if (from == null) { throw new ArgumentNullException(); } if (!(from is MachineModel other)) { throw new ArgumentException("Invalid type"); } Channels.Assign(other.Channels); Electronics.Assign(other.Electronics); ListHelpers.AssignList(Fans, other.Fans); Heat.Assign(other.Heat); Job.Assign(other.Job); MessageBox.Assign(other.MessageBox); ListHelpers.AssignList(Messages, other.Messages); Move.Assign(other.Move); Network.Assign(other.Network); Scanner.Assign(other.Scanner); Sensors.Assign(other.Sensors); ListHelpers.AssignList(Spindles, other.Spindles); State.Assign(other.State); ListHelpers.AssignList(Storages, other.Storages); ListHelpers.AssignList(Tools, other.Tools); ListHelpers.AssignList(UserVariables, other.UserVariables); }
private static Node <T> AddLoop <T>(Node <T> head, params T[] loop) where T : IEquatable <T> { while (head?.Next != null) { head = head.Next; } var loopStart = ListHelpers.CreateLinkedList(loop); var loopEnd = loopStart; while (loopEnd.Next != null) { loopEnd = loopEnd.Next; } if (head != null) { head.Next = loopStart; } loopEnd.Next = loopStart; return(loopStart); }
private void deleteFolderMsgBox_Result(object sender, DialogEventArgs e) { if (e.Result != DialogResult.OK) { return; } //Delete Selected folder... Host.Cursor = Cursors.WaitCursor; //Delete Folder if (Form1.Instance.DropBox.Delete(_selectedItem)) { //Now load the parent Directory _selectedItem = _selectedItem.Parent; lsbDropbox.Items = ListHelpers.MakeDirList(Form1.Instance.DropBox.GetItems(_selectedItem)); lsbDropbox.SelectedItemIndex = -1; header.Title = _selectedItem.Name; Host.Cursor = Cursors.Default; } else { Host.Cursor = Cursors.Default; MessageDialog.Show("Failed to Delete!", null, "OK"); } }
private void FillSubtractionModeNumbers() { System.Random rnd = new System.Random(); int correctNumberOne; int correctNumberTwo; // Dicculty Setting if (_instance.CurrentDiffulty == GameDifficulty.Easy) { _GUIManager._instance.NumberToFind.text = Random.Range(1, EASY_NUMBERS_RANGE).ToString(); // Get the two correct numbers correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), EASY_NUMBERS_MAX); //int correctNumberOne = rnd.Next(maxReference); correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text); } else if (_instance.CurrentDiffulty == GameDifficulty.Normal) { _GUIManager._instance.NumberToFind.text = Random.Range(1, NORMAL_NUMBERS_RANGE).ToString(); // Get the two correct numbers correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), NORMAL_NUMBERS_MAX); //int correctNumberOne = rnd.Next(maxReference); correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text); } else { _GUIManager._instance.NumberToFind.text = Random.Range(1, HARD_NUMBERS_RANGE).ToString(); // Get the two correct numbers correctNumberOne = Random.Range(int.Parse(_GUIManager._instance.NumberToFind.text), HARD_NUMBERS_MAX); //int correctNumberOne = rnd.Next(maxReference); correctNumberTwo = correctNumberOne - int.Parse(_GUIManager._instance.NumberToFind.text); } // Add random number to all buttons foreach (var button in _GUIManager._instance.NumericAnswers) { // Get children(text) Text buttonText = button.GetComponentInChildren <Text>(); button.interactable = true; buttonText.text = Random.Range(1, int.Parse(_GUIManager._instance.NumberToFind.text)).ToString(); } // Insert the two correct answers into the list Text buttonOneText = _GUIManager._instance.NumericAnswers[0].GetComponentInChildren <Text>(); buttonOneText.text = correctNumberOne.ToString(); Text buttonTwoText = _GUIManager._instance.NumericAnswers[1].GetComponentInChildren <Text>(); buttonTwoText.text = correctNumberTwo.ToString(); // Randomize the list ListHelpers.RandomizeList(_GUIManager._instance.NumericAnswers); }
/// <summary> /// Process a print status response (type 3) /// </summary> /// <param name="json">JSON response in UTF-8 format</param> /// <returns>Asynchronous task</returns> private static async Task ProcessPrintResponse(ReadOnlyMemory <byte> json) { PrintStatusResponse printResponse = (PrintStatusResponse)JsonSerializer.Deserialize(json.Span, typeof(PrintStatusResponse), JsonHelper.DefaultJsonOptions); using (await Provider.AccessReadWriteAsync()) { // Check if the last layer is complete if (printResponse.currentLayer > Provider.Get.Job.Layers.Count + 1) { float lastHeight = 0F, lastDuration = 0F, lastProgress = 0F; float[] lastFilamentUsage = new float[printResponse.extrRaw.Count]; foreach (Layer l in Provider.Get.Job.Layers) { lastHeight += l.Height; lastDuration += l.Duration; lastProgress += l.FractionPrinted; for (int i = 0; i < Math.Min(lastFilamentUsage.Length, l.Filament.Count); i++) { lastFilamentUsage[i] += l.Filament[i]; } } float[] filamentUsage = new float[printResponse.extrRaw.Count]; for (int i = 0; i < filamentUsage.Length; i++) { filamentUsage[i] = printResponse.extrRaw[i] - lastFilamentUsage[i]; } float printDuration = printResponse.printDuration - printResponse.warmUpDuration; Layer layer = new Layer { Duration = printDuration - lastDuration, Filament = new List <float>(filamentUsage), FractionPrinted = (printResponse.fractionPrinted / 100F) - lastProgress, Height = (printResponse.currentLayer > 2) ? _currentHeight - lastHeight : printResponse.firstLayerHeight }; Provider.Get.Job.Layers.Add(layer); // FIXME: In case Z isn't mapped to the 3rd axis... _currentHeight = printResponse.coords.xyz[2]; } else if (printResponse.currentLayer < Provider.Get.Job.Layers.Count && GetStatus(printResponse.status) == MachineStatus.Processing) { // Starting a new print job Provider.Get.Job.Layers.Clear(); _currentHeight = 0F; } Provider.Get.Job.Layer = printResponse.currentLayer; Provider.Get.Job.LayerTime = (printResponse.currentLayer == 1) ? printResponse.firstLayerDuration : printResponse.currentLayerTime; Provider.Get.Job.FilePosition = printResponse.filePosition; ListHelpers.SetList(Provider.Get.Job.ExtrudedRaw, printResponse.extrRaw); Provider.Get.Job.Duration = printResponse.printDuration; Provider.Get.Job.WarmUpDuration = printResponse.warmUpDuration; Provider.Get.Job.TimesLeft.File = (printResponse.timesLeft.file > 0F) ? (float?)printResponse.timesLeft.file : null; Provider.Get.Job.TimesLeft.Filament = (printResponse.timesLeft.filament > 0F) ? (float?)printResponse.timesLeft.filament : null; Provider.Get.Job.TimesLeft.Layer = (printResponse.timesLeft.layer > 0F) ? (float?)printResponse.timesLeft.layer : null; } }
private void movePublishHostDownButton_Click(object sender, EventArgs e) { int index = publishHostsListBox.SelectedIndex; EditedItem.Details.SitesToPublishTo.Move(index, index + 1); UpdatePublishHostsBindings(true); publishHostsListBox.SelectedIndex = ListHelpers.MoveSelectedIndex(publishHostsListBox.Items.Count, index, index + 1); }
private void moveDownloadHostDownButton_Click(object sender, EventArgs e) { int index = downloadHostListBox.SelectedIndex; EditedItem.Details.DownloadHosts.Move(index, index + 1); UpdateDownloadHostsBindings(true); downloadHostListBox.SelectedIndex = ListHelpers.MoveSelectedIndex(downloadHostListBox.Items.Count, index, index + 1); }
private void moveSocialPostDownButton_Click(object sender, EventArgs e) { int index = SocialPost_listBox.SelectedIndex; EditedItem.Details.PlacesToPost.Move(index, index + 1); UpdateSocialPostBindings(true); SocialPost_listBox.SelectedIndex = ListHelpers.MoveSelectedIndex(SocialPost_listBox.Items.Count, index, index + 1); }
private void moveDownVerMetaButton_Click(object sender, EventArgs e) { int index = versionListBox.SelectedIndex; EditedItem.Details.VersionMetadata.Move(index, index + 1); UpdateVerMetaBindings(true); versionListBox.SelectedIndex = ListHelpers.MoveSelectedIndex(versionListBox.Items.Count, index, index + 1); }
private void ValidateResult <T>(Node <T> expected, Node <T> input, int k) where T : IEquatable <T> { var inputCopy = ListHelpers.CloneList(input); var inputCopy2 = ListHelpers.CloneList(input); Assert.AreEqual(expected, Question_2_2.ReturnKthToLast(inputCopy, k)); }
/// <summary> /// Creates a clone of this instance /// </summary> /// <returns>A clone of this instance</returns> public object Clone() { Sensors clone = new Sensors(); ListHelpers.CloneItems(clone.Endstops, Endstops); ListHelpers.CloneItems(clone.Probes, Probes); return(clone); }
private void form_main_Shown(object sender, EventArgs e) { // Set the loading text. list_selection.Items.Add(ListHelpers.LoadingItem()); // Create the DataRetriever, and provide it with a delegate to DisplayList for returning data _dataRetriever = new DataRetriever(DisplayList); // Start retrieving data on a separate thread... _dataRetriever.GetData(); }
public void Question_2_6_EdgeCases() { var l1 = ListHelpers.CreateLinkedList(1); var l2 = ListHelpers.CreateLinkedList(2, 2); var l3 = ListHelpers.CreateLinkedList(1, 2); Validate(true, l1); Validate(true, l2); Validate(false, l3); }
/// <summary> /// Example where there are zero issues with reading in a delimited file /// into a strong typed list then finally into a DataTable. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PerfectWorldExampleDataTableButton_Click(object sender, EventArgs e) { var fileOperations = new FileOperations(); var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Import1.txt"); _bindingSource.DataSource = ListHelpers.ConvertToDataTable( fileOperations.ReadCustomersPerfectWorld(fileName)); dataGridView1.DataSource = _bindingSource; }
public void ViewInventory() { // This is almost an exact copy of the Shop.cs do while possibly rework later do { // See shop.cs for explination of this Interface.BasicInterfaceDelegateParams(this, LineHelpers.PrintLine, "Your Inventory:", "1. Weapons", "2. Armor", "3. Consumables.", "4. Exit"); int type = LineHelpers.ReadInputNumber(new int[] { 1, 2, 3, 4 }); Interface.BasicInterface(this); Thing choice; switch (type) { case 1: Interface.BasicInterfaceDelegate(this, LineHelpers.PrintLine, "Weapons: "); choice = ListHelpers.PrintListGetItem(this.Weapons, PrintTypes.Weapon) as Weapon; break; case 2: Interface.BasicInterfaceDelegate(this, LineHelpers.PrintLine, "Armor: "); choice = ListHelpers.PrintListGetItem(this.Armor, PrintTypes.Armor) as Armor; break; case 3: Interface.BasicInterfaceDelegate(this, LineHelpers.PrintLine, "Consumables: "); choice = ListHelpers.PrintListGetItem(this.Consumables, PrintTypes.Consumable) as Consumable; break; default: return; } if (choice != null) { try { if (type == 1) { EquipWeapon(choice as Weapon); } else { EquipArmor(choice as Armor); } } // this should never be nessicary catch (Exception ex) { LineHelpers.PrintLine("Unable to equip Item."); } } } while (true); }
public MainViewModel() { var randomService = new RandomService(); var listHelper = new ListHelpers(randomService); this.algorithms = new List <IAIAlgorithm> { //new AgresiveRandomAI(), new DfsAI(5, listHelper), new MctsAI(listHelper, randomService) }; }
private void ValidateResult <T>(Node <T> expected, Node <T> input) where T : IEquatable <T> { var inputCopy = ListHelpers.CloneList(input); var inputCopy2 = ListHelpers.CloneList(input); Question_2_1.RemoveDuplicates(inputCopy); ListHelpers.ValidateLinkedListContent(expected, inputCopy); Question_2_1.RemoveDuplicatesNoSpace(input); ListHelpers.ValidateLinkedListContent(expected, input); Question_2_1.RemoveDuplicatesNoSpace2(inputCopy2); ListHelpers.ValidateLinkedListContent(expected, input); }
public void Question_2_3_InvalidCases() { // Remove end of list var l3 = ListHelpers.CreateLinkedList(1, 2); var expected = ListHelpers.CreateLinkedList(1); TestHelpers.AssertExceptionThrown(() => Question_2_3.RemoveMiddleNode(l3.Next), typeof(ArgumentException)); // Pass null node. Node <int> head = null; TestHelpers.AssertExceptionThrown(() => Question_2_3.RemoveMiddleNode(head), typeof(ArgumentNullException)); }
public static void SaveList(GroceryList newList) { if (AppData.auth.CurrentUser == null) { return; } var toWriteDict = ListHelpers.ListToDict(newList); AppData.DataNode.GetChild(AppData.currentUser.Uid) .GetChild(newList.ListName) .SetValue(toWriteDict); }
public void Question_2_4_EdgeCases() { // One node list, no change var l1 = ListHelpers.CreateLinkedList(1); ValidateResult(l1, 0, 1); ValidateResult(l1, 1, 1); ValidateResult(l1, 2, 1); // List with all the same values var l2 = ListHelpers.CreateLinkedList(2, 2, 2, 2, 2, 2); ValidateResult(l2, 2, 2, 2, 2, 2, 2, 2); }
// TODO add Sensors here holding info about thermistors /// <summary> /// Assigns every property of another instance of this one /// </summary> /// <param name="from">Object to assign from</param> /// <exception cref="ArgumentNullException">other is null</exception> /// <exception cref="ArgumentException">Types do not match</exception> public void Assign(object from) { if (from == null) { throw new ArgumentNullException(); } if (!(from is Sensors other)) { throw new ArgumentException("Invalid type"); } ListHelpers.AssignList(Endstops, other.Endstops); ListHelpers.AssignList(Probes, other.Probes); }
public void Question_2_6_BasicCases() { var l1 = ListHelpers.CreateLinkedList(1, 2, 1); var l2 = ListHelpers.CreateLinkedList(1, 2, 2, 2, 2, 2); var l3 = ListHelpers.CreateLinkedList(1, 1, 1, 1, 1); var l4 = ListHelpers.CreateLinkedList(1, 2, 3, 4, 5); var l5 = ListHelpers.CreateLinkedList(1, 2, 2, 2, 2, 2, 1); Validate(true, l1); Validate(false, l2); Validate(true, l3); Validate(false, l4); Validate(true, l5); }