예제 #1
0
        private async Task Import()
        {
            try
            {
                _loggingService.Info($"Importing channels from file");

                var chs = await _channelService.LoadChannels();

                if (!File.Exists(AndroidChannelsListPath))
                {
                    await _dialogService.Error($"File {AndroidChannelsListPath} not found");

                    return;
                }

                var jsonFromFile = File.ReadAllText(AndroidChannelsListPath);

                var importedChannels = JsonConvert.DeserializeObject <ObservableCollection <DVBTChannel> >(jsonFromFile);

                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);
            }
            catch (Exception ex)
            {
                _loggingService.Error(ex, "Import failed");
                await _dialogService.Error($"Import failed");
            }
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
        private async Task Tune(long freq, long bandWidth, int dvbtTypeIndex)
        {
            try
            {
//#if DEBUG
//                await Task.Delay(1000);

//                var channel = new DVBTChannel();
//                channel.PIDs = "0,16,17";
//                channel.ProgramMapPID = 5000;
//                channel.Name = "Channel name";
//                channel.ProviderName = "Multiplex";
//                channel.Frequency = freq;
//                channel.Bandwdith = bandWidth;
//                channel.Number = String.Empty;
//                channel.DVBTType = dvbtTypeIndex;
//                channel.Type = ServiceTypeEnum.DigitalTelevisionService;

//                TunedChannels.Add(channel);

//                Device.BeginInvokeOnMainThread(() =>
//                {
//                    SelectedChannel = channel;
//                });
//#endif


                var tuneResult = await _driver.TuneEnhanced(freq, bandWidth, dvbtTypeIndex);

                switch (tuneResult.Result)
                {
                case SearchProgramResultEnum.Error:
                    _loggingService.Debug("Search error");

                    SignalStrengthProgress = 0;
                    return;

                case SearchProgramResultEnum.NoSignal:
                    _loggingService.Debug("No signal");

                    SignalStrengthProgress = 0;
                    return;

                case SearchProgramResultEnum.OK:

                    SignalStrengthProgress = tuneResult.SignalPercentStrength / 100.0;
                    break;
                }

                var searchMapPIDsResult = await _driver.SearchProgramMapPIDs(false);

                switch (searchMapPIDsResult.Result)
                {
                case SearchProgramResultEnum.Error:
                    _loggingService.Debug("Search error");

                    return;

                case SearchProgramResultEnum.NoSignal:
                    _loggingService.Debug("No signal");

                    return;

                case SearchProgramResultEnum.NoProgramFound:
                    _loggingService.Debug("No program found");

                    return;
                }

                var mapPIDs = new List <long>();
                var mapPIDToServiceDescriptor = new Dictionary <long, ServiceDescriptor>();

                foreach (var sd in searchMapPIDsResult.ServiceDescriptors)
                {
                    mapPIDs.Add(sd.Value);
                    mapPIDToServiceDescriptor.Add(sd.Value, sd.Key);
                }
                _loggingService.Debug($"Program MAP PIDs found: {String.Join(",", mapPIDs)}");


                if (TuningAborted)
                {
                    _loggingService.Debug($"Tuning aborted");
                    return;
                }

                // searching PIDs

                var searchProgramPIDsResult = await _driver.SearchProgramPIDs(mapPIDs);

                switch (searchProgramPIDsResult.Result)
                {
                case SearchProgramResultEnum.Error:
                    _loggingService.Debug($"Error scanning Map PIDs");
                    break;

                case SearchProgramResultEnum.NoSignal:
                    _loggingService.Debug("No signal");
                    break;

                case SearchProgramResultEnum.NoProgramFound:
                    _loggingService.Debug("No program found");
                    break;

                case SearchProgramResultEnum.OK:

                    var totalChannelsAddedCount = 0;

                    foreach (var kvp in searchProgramPIDsResult.PIDs)
                    {
                        var pids        = string.Join(",", kvp.Value);
                        var sDescriptor = mapPIDToServiceDescriptor[kvp.Key];

                        var ch = new DVBTChannel();
                        ch.PIDs          = pids;
                        ch.ProgramMapPID = kvp.Key;
                        ch.Name          = sDescriptor.ServiceName;
                        ch.ProviderName  = sDescriptor.ProviderName;
                        ch.Frequency     = freq;
                        ch.Bandwdith     = bandWidth;
                        ch.Number        = String.Empty;
                        ch.DVBTType      = dvbtTypeIndex;
                        ch.Type          = (ServiceTypeEnum)sDescriptor.ServisType;

                        TunedChannels.Add(ch);

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            SelectedChannel = ch;
                        });

                        _loggingService.Debug($"Found channel \"{sDescriptor.ServiceName}\"");

                        // automatically adding new tuned channel if does not exist
                        if (!ConfigViewModel.ChannelExists(_channels, ch.Frequency, ch.ProgramMapPID))
                        {
                            ch.Number = ConfigViewModel.GetNextChannelNumber(_channels).ToString();

                            _channels.Add(ch);

                            await _channelService.SaveChannels(_channels);

                            totalChannelsAddedCount++;
                        }
                    }

                    if (totalChannelsAddedCount > 0)
                    {
                        if (totalChannelsAddedCount > 1)
                        {
                            MessagingCenter.Send($"{totalChannelsAddedCount} channels saved", BaseViewModel.MSG_ToastMessage);
                        }
                        else
                        {
                            MessagingCenter.Send($"Channel saved", BaseViewModel.MSG_ToastMessage);
                        }
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }