protected async override void Update()
        {
            // Don't update the current channel and program information if we are in zap osd.
            if (_tvHandler == null || (_zapTimer != null && _zapTimer.IsEventPending))
            {
                return;
            }

            // Update current programs for all channels of current group (visible inside MiniGuide).
            await UpdateAllCurrentPrograms();

            _zapChannelIndex = ChannelContext.Instance.Channels.CurrentIndex;

            if (_tvHandler.NumberOfActiveSlots < 1)
            {
                PiPAvailable = false;
                PiPEnabled   = false;
                return;
            }

            PiPAvailable = true;

            // get the current channel and program out of the LiveTvMediaItems' TimeshiftContexes
            IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
            IPlayerContext        playerContext        = playerContextManager.GetPlayerContext(PlayerChoice.PrimaryPlayer);

            if (playerContext != null)
            {
                ILivePlayer player = playerContext.CurrentPlayer as ILivePlayer;
                if (player != null)
                {
                    LiveTvMediaItem   item           = player.CurrentItem;
                    ITimeshiftContext context        = item == null ? null : item.TimeshiftContexes.LastOrDefault();
                    IProgram          currentProgram = null;
                    IProgram          nextProgram    = null;
                    IChannel          channel        = null;
                    if (context != null && context.Channel != null)
                    {
                        channel         = context.Channel;
                        ChannelName     = channel.Name;
                        ChannelLogoType = channel.GetFanArtMediaType();
                        if (_tvHandler.ProgramInfo != null)
                        {
                            var result = await _tvHandler.ProgramInfo.GetNowNextProgramAsync(channel);

                            if (result.Success)
                            {
                                currentProgram = result.Result[0];
                                nextProgram    = result.Result[1];
                                double progress = currentProgram == null ? 100d : (DateTime.Now - currentProgram.StartTime).TotalSeconds /
                                                  (currentProgram.EndTime - currentProgram.StartTime).TotalSeconds * 100;
                                _programProgressProperty.SetValue(progress);
                            }
                        }
                    }
                    CurrentProgram.SetProgram(currentProgram, channel);
                    NextProgram.SetProgram(nextProgram, channel);
                }
            }
        }
        protected void UpdateForChannel(IChannel channel)
        {
            ChannelName = channel.Name;
            IProgram currentProgram;

            if (_tvHandler.ProgramInfo.GetCurrentProgram(channel, out currentProgram))
            {
                CurrentProgram.SetProgram(currentProgram);
                double progress = (DateTime.Now - currentProgram.StartTime).TotalSeconds /
                                  (currentProgram.EndTime - currentProgram.StartTime).TotalSeconds * 100;
                _programProgressProperty.SetValue(progress);
            }
            else
            {
                CurrentProgram.SetProgram(null);
                _programProgressProperty.SetValue(100d);
            }

            IProgram nextProgram;

            if (_tvHandler.ProgramInfo.GetNextProgram(channel, out nextProgram))
            {
                NextProgram.SetProgram(nextProgram);
            }
        }
        private async void CopyProgramMessageCallback(MessageboxResult result)
        {
            DateTime copyStartTime;

            lock (_copyLock)
            {
                if (_isCopying)
                {
                    return;
                }

                _isCopying    = true;
                copyStartTime = DateTime.UtcNow;
            }

            _dialogResult = result;

            if (_dialogResult == MessageboxResult.Ok)
            {
                ServiceLocator.TraceService.Add(TraceType.Info, "About to copy local program",
                                                "Program name: " + _copyProgramName);

                if (CurrentProgram != null && _copyProgramName == CurrentProgram.Name)
                {
                    await CurrentProgram.Save();
                }

                var sourceProgramName      = _copyProgramName;
                var destinationProgramName = await ServiceLocator.ContextService.
                                             CopyProgramPart1(_copyProgramName);

                await UpdateLocalPrograms();

                _copyProgramName = null;

                await ServiceLocator.ContextService.CopyProgramPart2(
                    sourceProgramName, destinationProgramName);

                var minDeleteTime     = new TimeSpan(0, 0, 2);
                var remainingCopyTime = minDeleteTime.Subtract(
                    DateTime.UtcNow.Subtract(copyStartTime));

                if (remainingCopyTime > new TimeSpan(0))
                {
                    await Task.Delay(remainingCopyTime);
                }

                await UpdateLocalPrograms();

                //var program = await ServiceLocator.ContextService.CopyProgramPart2(
                //    _copyProgramName, updatedProgramName);

                //await UpdateLocalPrograms();
            }

            lock (_copyLock)
            {
                _isCopying = false;
            }
        }
        private async void ShareLocalProgramAction()
        {
            await CurrentProgram.Save();

            //var message = new GenericMessage<LocalProgramHeader>(CurrentProgram.LocalProgramHeader);
            //Messenger.Default.Send(message, ViewModelMessagingToken.ShareProgramHeaderListener);

            ServiceLocator.NavigationService.NavigateTo <ProgramExportViewModel>();
            _performedExport = true;
        }
        protected override void Update()
        {
            // Don't update the current channel and program information if we are in zap osd.
            if (_tvHandler == null || !_active || _zapTimer != null)
            {
                return;
            }

            if (_tvHandler.NumberOfActiveSlots < 1)
            {
                PiPAvailable = false;
                PiPEnabled   = false;
                return;
            }

            PiPAvailable = true;

            // get the current channel and program out of the LiveTvMediaItems' TimeshiftContexes
            IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
            IPlayerContext        playerContext        = playerContextManager.GetPlayerContext(PlayerChoice.PrimaryPlayer);

            if (playerContext != null)
            {
                LiveTvMediaItem liveTvMediaItem = playerContext.CurrentMediaItem as LiveTvMediaItem;
                LiveTvPlayer    player          = playerContext.CurrentPlayer as LiveTvPlayer;
                if (liveTvMediaItem != null && player != null)
                {
                    ITimeshiftContext context        = player.CurrentTimeshiftContext;
                    IProgram          currentProgram = null;
                    IProgram          nextProgram    = null;
                    if (context != null)
                    {
                        ChannelName    = context.Channel.Name;
                        currentProgram = context.Program;
                        if (currentProgram != null)
                        {
                            currentProgram = context.Program;
                            double progress = (DateTime.Now - currentProgram.StartTime).TotalSeconds /
                                              (currentProgram.EndTime - currentProgram.StartTime).TotalSeconds * 100;
                            _programProgressProperty.SetValue(progress);

                            IList <IProgram> nextPrograms;
                            DateTime         nextTime = currentProgram.EndTime.Add(TimeSpan.FromSeconds(10));
                            if (_tvHandler.ProgramInfo.GetPrograms(context.Channel, nextTime, nextTime, out nextPrograms))
                            {
                                nextProgram = nextPrograms[0];
                            }
                        }
                    }
                    CurrentProgram.SetProgram(currentProgram);
                    NextProgram.SetProgram(nextProgram);
                }
            }
        }
        protected override void Update()
        {
            // Don't update the current channel and program information if we are in zap osd.
            if (_tvHandler == null || (_zapTimer != null && _zapTimer.IsEventPending))
            {
                return;
            }

            // Update current programs for all channels of current group (visible inside MiniGuide).
            UpdateAllCurrentPrograms();

            _zapChannelIndex = ChannelContext.Instance.Channels.CurrentIndex;

            if (_tvHandler.NumberOfActiveSlots < 1)
            {
                PiPAvailable = false;
                PiPEnabled   = false;
                return;
            }

            PiPAvailable = true;

            // get the current channel and program out of the LiveTvMediaItems' TimeshiftContexes
            IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
            IPlayerContext        playerContext        = playerContextManager.GetPlayerContext(PlayerChoice.PrimaryPlayer);

            if (playerContext != null)
            {
                LiveTvPlayer player = playerContext.CurrentPlayer as LiveTvPlayer;
                if (player != null)
                {
                    ITimeshiftContext context        = player.TimeshiftContexes.LastOrDefault();
                    IProgram          currentProgram = null;
                    IProgram          nextProgram    = null;
                    if (context != null && context.Channel != null)
                    {
                        ChannelName = context.Channel.Name;
                        if (_tvHandler.ProgramInfo != null && _tvHandler.ProgramInfo.GetNowNextProgram(context.Channel, out currentProgram, out nextProgram) && currentProgram != null)
                        {
                            double progress = (DateTime.Now - currentProgram.StartTime).TotalSeconds /
                                              (currentProgram.EndTime - currentProgram.StartTime).TotalSeconds * 100;
                            _programProgressProperty.SetValue(progress);
                        }
                    }
                    CurrentProgram.SetProgram(currentProgram);
                    NextProgram.SetProgram(nextProgram);
                }
            }
        }
        private async void SaveAction()
        {
            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(ProgramName);

            if (CurrentProgram.Name != ProgramName)
            {
                ProgramName = await ServiceLocator.ContextService.FindUniqueProgramName(validName);

                if (CurrentProgram.LocalProgramHeader == CurrentProgramHeader)
                {
                    CurrentProgram.LocalProgramHeader.ProjectName = ProgramName;
                    await CurrentProgram.SetProgramNameAndRenameDirectory(ProgramName);

                    CurrentProgram.Description = ProgramDescription;
                }
                else
                {
                    var oldProgramPath = CurrentProgram.BasePath;
                    CurrentProgramHeader.ProjectName = ProgramName;
                    CurrentProgram.Description       = ProgramDescription;
                    await CurrentProgram.Save();

                    var programChangedMessage1 = new GenericMessage <Program>(null);
                    Messenger.Default.Send(programChangedMessage1,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    using (var storage = StorageSystem.GetStorage())
                    {
                        await storage.RenameDirectoryAsync(oldProgramPath, ProgramName);
                    }

                    var programChangedMessage2 = new GenericMessage <Program>(null);
                    Messenger.Default.Send(programChangedMessage2,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    await App.SaveContext(CurrentProgram);

                    var localProgramsChangedMessage = new MessageBase();
                    Messenger.Default.Send(localProgramsChangedMessage,
                                           ViewModelMessagingToken.LocalProgramsChangedListener);

                    base.GoBackAction();
                }
            }
        }
        public void UpdateSchedule(object sender, SelectionChangedEventArgs e)
        {
            var selectedItem = e.FirstAddedItem as ListItem;

            if (selectedItem == null)
            {
                return;
            }
            ISchedule schedule = (ISchedule)selectedItem.AdditionalProperties["SCHEDULE"];

            UpdateScheduleDetails(schedule).Wait();
            if (selectedItem.AdditionalProperties.ContainsKey("PROGRAM"))
            {
                IProgram program = (IProgram)selectedItem.AdditionalProperties["PROGRAM"];
                CurrentProgram.SetProgram(program);
            }
            else
            {
                CurrentProgram.SetProgram(null);
            }
        }
        /// <summary>
        /// Method to run the program.
        /// </summary>
        public void Run()
        {
            S.Console.OutputEncoding = Encoding.UTF8;
            S.Console.WriteLine(CurrentProgram.GetLocalizedString("Loading_LoadingCardDatabase"));

            Logger.Debug("Application Running - {0}", ApplicationName);

            AssemblyName assemblyName         = Assembly.GetExecutingAssembly().GetName();
            string       assemblyVersion      = assemblyName.Version.ToString();
            string       assemblyArchitecture = assemblyName.ProcessorArchitecture.ToString();

            S.Console.WriteLine($"Assembly Version: {assemblyVersion}, Assembly Architecture: {assemblyArchitecture})");

            this.InitializeState();

            Logger.Debug("Initializing Card Database");
            CardDatabase.Initialize(false);

            S.Console.WriteLine(Localization.Message_PressToExit);
            S.Console.ReadKey();
        }
Beispiel #10
0
        private async void SaveAction()
        {
            GoBackAction();

            if (CurrentProgram != null)
            {
                await CurrentProgram.Save();
            }

            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(ProgramName);

            string uniqueName = await ServiceLocator.ContextService.FindUniqueProgramName(validName);

            if (CreateEmptyProgram)
            {
                CurrentProgram = await ServiceLocator.ContextService.CreateEmptyProgram(uniqueName);
            }
            else if (CreateTemplateProgram)
            {
                CurrentProgram = await SelectedTemplateOption.ProjectGenerator.GenerateProgram(uniqueName, true);
            }

            if (CurrentProgram != null)
            {
                await CurrentProgram.Save();

                //await ServiceLocator.ContextService.
                //    CreateThumbnailsForNewProgram(CurrentProgram.Name);

                var programChangedMessage = new GenericMessage <Program>(CurrentProgram);
                Messenger.Default.Send(programChangedMessage, ViewModelMessagingToken.CurrentProgramChangedListener);
            }

            var localProgramsChangedMessage = new MessageBase();

            Messenger.Default.Send(localProgramsChangedMessage,
                                   ViewModelMessagingToken.LocalProgramsChangedListener);
        }
 protected virtual void UpdateProgramStatus(IProgram program)
 {
     CurrentProgram.SetProgram(program);
 }
        public async override void NavigateTo()
        {
            if (CurrentProgram == null ||
                CurrentProgram.Name != CurrentProgramHeader.ProjectName)
            {
                lock (_loadingLock)
                {
                    if (IsActivatingLocalProgram)
                    {
                        return;
                    }

                    IsActivatingLocalProgram           = true;
                    CurrentProgramHeader.ValidityState = ProgramState.Unknown;
                    RaisePropertiesChanges();
                }

                if (CurrentProgram != null)
                {
                    await CurrentProgram.Save();
                }

                var result = await ServiceLocator.ProgramValidationService.CheckProgram(
                    Path.Combine(StorageConstants.ProgramsPath, CurrentProgramHeader.ProjectName));

                var newProgram = result.Program;

                CurrentProgramHeader.ValidityState = result.State;


                IsActivatingLocalProgram = false;

                if (newProgram != null)
                {
                    ServiceLocator.DispatcherService.RunOnMainThread(() =>
                    {
                        CurrentProgramHeader.ValidityState = ProgramState.Valid;
                    });

                    CurrentProgram = newProgram;

                    var projectChangedMessage = new GenericMessage <Program>(newProgram);
                    Messenger.Default.Send(projectChangedMessage,
                                           ViewModelMessagingToken.CurrentProgramChangedListener);

                    IsActivatingLocalProgram = false;
                }
                else
                {
                    ServiceLocator.DispatcherService.RunOnMainThread(() =>
                    {
                        CurrentProgram = null;
                    });
                }
            }
            if (_performedExport)
            {
                await ServiceLocator.ProgramExportService.CleanUpExport();

                _performedExport = false;
            }
            IsActivatingLocalProgram = false;
            RaisePropertiesChanges();

            base.NavigateTo();
        }
Beispiel #13
0
 private void UpdateSingleProgramInfo(IProgram program)
 {
     CurrentProgram.SetProgram(program);
 }