Catrobat.IDE.Core.ViewModels.Main.ProgramDetailViewModel.NavigateTo C# (CSharp) Method

NavigateTo() public method

public NavigateTo ( ) : void
return void
        public async override void NavigateTo()
        {
            if (CurrentProgram == null ||
                CurrentProgram.Name != CurrentProgramHeader.ProjectName)
            {
                lock (_loadingLock)
                {
                    if (IsActivatingLocalProgram)
                        return;

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

                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();
        }
    }