public void RoastProfileSelChanged() { // if changed manually in picker (this function is also called, if we programmatically change RoastProfileSel)m // we want to remove formerly selected special (id >= 100) entry, so it connot be choosen manually in the picker again if (RoastProfileSel.isManualChoiceAllowed || // manually template choosen or (RoastProfileSel.Id != lastSelectedRoastProfile.Id)) // programmatically other special entry choosen { if ((lastSelectedRoastProfile?.Id > 100) || (lastSelectedRoastProfile?.Id == 0)) { RoastProfiles.Remove(lastSelectedRoastProfile); OnPropertyChanged(nameof(RoastProfiles)); } } if (!string.IsNullOrEmpty(RoastProfileSel.Data)) { // if (manually) template choosen -> load template byte[] mem = new byte[80]; int index = 16; string line = RoastProfileSel.Data; if (string.IsNullOrEmpty(line)) { return; } try { int j = 0; while ((j < line.Length) && (index < 80)) { if ((line[j] == ' ') || (line[j] == '\t')) { j++; continue; } mem[index++] = byte.Parse(line.Substring(j, 2), NumberStyles.HexNumber); j += 2; } } catch { Console.WriteLine("Error: unknown line format: {0}", line); } nPause = PauseDuration.GetSliderTicks(256 * mem[48] + mem[49]); SetControlsVisibility(mem[41], false); DataBag.SetData(mem); MessagingCenter.Send(this, "DataChanged", DataBag.GetData()); } lastSelectedRoastProfile = RoastProfileSel; }
public async Task OpenFilePickerDestAsync() { try { FileData fileData = await CrossFilePicker.Current.PickFile(); if (fileData == null) { return; // user canceled file picking } MemoryStream ms = new MemoryStream(fileData.DataArray); StreamReader reader = new StreamReader(ms, System.Text.Encoding.ASCII); string line; byte[] mem = new byte[80]; int index = 0; int i = 0; while (true) { line = reader.ReadLine(); if (line == null) { break; } try { int j = 0; while ((2 * j < line.Length) && (line[2 * j] != ' ') && (line[2 * j] != '\t') && (index < 80)) { mem[index++] = byte.Parse(line.Substring(2 * j++, 2), NumberStyles.HexNumber); } } catch { Console.WriteLine("Error: unknown line format: {0}", line); } } byte[] mem1stCard = MergeTagData(DataBag.GetData(), mem); StreamWriter ofile = new StreamWriter(Path.Combine(_downloadFolder, fileData.FileName + "-new.txt")) { NewLine = "\n" }; index = 0; for (i = 0; i < 20; i++) { line = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}", mem1stCard[index], mem1stCard[index + 1], mem1stCard[index + 2], mem1stCard[index + 3]); index += 4; ofile.WriteLine(line); } ofile.Close(); } catch (Exception ex) { System.Console.WriteLine("Exception choosing file: " + ex.ToString()); }; return; }