public async Task OpenFilePickerSrcAsync() { 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; 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); } } nPause = PauseDuration.GetSliderTicks(256 * mem[48] + mem[49]); SetControlsVisibility(mem[41]); DataBag.SetData(mem); MessagingCenter.Send(this, "DataChanged", DataBag.GetData()); } catch (Exception ex) { Console.WriteLine("Exception choosing file: " + ex.ToString()); }; return; }
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; }