private async Task ImportList(object json) { if (!(await _dialogService.Confirm("Are you sure to import channels list?"))) { return; } try { _loggingService.Info($"Importing channels"); var chs = await _channelService.LoadChannels(); var importedChannels = JsonConvert.DeserializeObject <ObservableCollection <DVBTChannel> >(json as string); var count = 0; foreach (var ch in importedChannels) { if (!ConfigViewModel.ChannelExists(chs, ch.Frequency, ch.ProgramMapPID)) { count++; ch.Number = ConfigViewModel.GetNextChannelNumber(chs).ToString(); chs.Add(ch); } } await _channelService.SaveChannels(chs); MessagingCenter.Send($"Imported channels count: {count}", BaseViewModel.MSG_ToastMessage); await Refresh(); } catch (Exception ex) { _loggingService.Error(ex, "Import failed"); await _dialogService.Error($"Import failed"); } }
private async Task ShareLog() { try { _loggingService.Info("Sharing channels list"); var chs = await _channelService.LoadChannels(); if (chs.Count == 0) { await _dialogService.Information("Channel list is empty"); return; } var shareDir = Path.Combine(BaseViewModel.AndroidAppDirectory, "shared"); if (!Directory.Exists(shareDir)) { Directory.CreateDirectory(shareDir); } var listPath = Path.Combine(shareDir, "DVBTTelevizor.channels.json"); if (File.Exists(listPath)) { File.Delete(listPath); } File.WriteAllText(listPath, JsonConvert.SerializeObject(chs)); MessagingCenter.Send(listPath, BaseViewModel.MSG_ShareFile); } catch (Exception ex) { _loggingService.Error(ex); MessagingCenter.Send($"File sharing failed", BaseViewModel.MSG_ToastMessage); } }
private async Task Tune() { _loggingService.Info($"Tuning"); State = TuneState.TuningInProgress; TunedChannels.Clear(); _channels = await _channelService.LoadChannels(); if (_channels == null) { _channels = new ObservableCollection <DVBTChannel>(); } OnPropertyChanged(nameof(TuningLabel)); OnPropertyChanged(nameof(AutomaticTuningProgress)); TuningAborted = false; try { if (ManualTuning) { long freq = Convert.ToInt64(TuneFrequency) * 1000000; long bandWidth = TuneBandwidth * 1000000; var ch = Convert.ToInt32((Convert.ToInt64(TuneFrequency) - 474 + 8 * 21) / 8); _actualTunningChannel = ch; _actualTuningDVBTType = 0; OnPropertyChanged(nameof(TuningLabel)); if (DVBTTuning) { await Tune(freq, bandWidth, 0); } _actualTuningDVBTType = 1; OnPropertyChanged(nameof(TuningLabel)); if (DVBT2Tuning) { await Tune(freq, bandWidth, 1); } } else { await AutomaticTune(); } State = TuneState.TuneFinishedOK; } catch (Exception ex) { State = TuneState.TuneFailed; } finally { OnPropertyChanged(nameof(TuningFinished)); OnPropertyChanged(nameof(TunedChannels)); OnPropertyChanged(nameof(AddChannelsVisible)); OnPropertyChanged(nameof(TuningLabel)); OnPropertyChanged(nameof(AutomaticTuningProgress)); } }