Base class for all messages broadcasted by the Messenger. You can create your own message types by extending this class.
Exemplo n.º 1
0
        private void ShowResults(MessageBase message)
        {
            questionTableView.Visibility = Visibility.Collapsed;
            questionProcessView.Visibility = Visibility.Collapsed;
            resultsWindowView.Visibility = Visibility.Collapsed;

            resultsView.Visibility = Visibility.Visible;
        }
 private void ChangeMasterDetailState(MessageBase message)
 {
     if (QuestionTableView.Visibility != QuestionProcessView.Visibility)
     {
         QuestionTableView.Visibility = QuestionProcessView.Visibility;
         QuestionProcessView.Visibility = RevertVisibility(QuestionProcessView.Visibility);
     }
 }
Exemplo n.º 3
0
        public void ReceiveMessage(MessageBase message)
        {
            var casted = message as OldTestMessage;

            if (casted != null)
            {
                ReceivedContent = casted.Content;
            }
        }
        private ChildWindowViewModelBase CreateViewModel(MessageBase message)
        {
            if (MessageIsForError(message))
            {
                return CreateViewModelForError(message);
            }

            throw new ArgumentException("Unhandled message", "message");
        }
        private void SelectCultureAction(CultureInfo culture)
        {
            CurrentCulture = culture;

            var message = new MessageBase();
            Messenger.Default.Send(message, ViewModelMessagingToken.ClearPageCache);

            //ServiceLocator.NavigationService.NavigateTo(GetType());
            //ServiceLocator.NavigationService.RemoveBackEntry();
        }
        private ChildWindowViewModelBase CreateViewModelForError(MessageBase message)
        {
            var errorVm = _viewModelFactory.CreateErrorOccuredViewModel();
            if (message is DisplayErrorSavingDataMessage)
            {
                errorVm.Description = "There was an error saving the data.";
            }
            else if (message is DisplayErrorRetrievingDataMessage)
            {
                errorVm.Description = "There was an error retrieving the data. Please try again.";
            }

            return errorVm;
        }
Exemplo n.º 7
0
        public void ReceiveMessage(MessageBase message)
        {
            Sender = message.Sender;
            Message = message;

            var castedMessage = message as GenericMessage<string>;
            if (castedMessage != null)
            {
                Content = castedMessage.Content;
            }

            var propertyMessage = message as PropertyChangedMessage<DateTime>;
            if (propertyMessage != null
                && propertyMessage.PropertyName == OldTestViewModel.LastChanged2PropertyName)
            {
                ReceivedMessagesCount++;
            }
        }
Exemplo n.º 8
0
        internal void Broadcast(MessageBase message)
        {
            var messageType = message.GetType();

            if (_recipientsOfSubclasses != null)
            {
                foreach (var type in _recipientsOfSubclasses.Keys)
                {
                    List<WeakReference> list = null;

                    if (messageType == type
                        || messageType.IsSubclassOf(type))
                    {
                        list = _recipientsOfSubclasses[type];
                    }
                    else
                    {
                        if (type.IsGenericType
                            && messageType.IsGenericType)
                        {
                            if (type.GetGenericArguments()[0].FullName == null
                                && type.GetGenericTypeDefinition() == messageType.GetGenericTypeDefinition())
                            {
                                list = _recipientsOfSubclasses[type];
                            }
                        }
                    }

                    SendToList(message, list);
                }
            }

            if (_recipientsStrict != null)
            {
                if (_recipientsStrict.ContainsKey(messageType))
                {
                    var list = _recipientsStrict[messageType];
                    SendToList(message, list);
                }
            }

            Cleanup();
        }
Exemplo n.º 9
0
        public void ReceiveMessage(MessageBase message)
        {
            Sender = message.Sender;

            if (message is OldTestMessage)
            {
                ReceiveTestMessage(message as OldTestMessage);
                return;
            }

            if (message is GenericMessage<InvalidOperationException>)
            {
                ReceiveGenericMessage(message as GenericMessage<InvalidOperationException>);
                return;
            }

            if (message is GenericMessage<MissingMethodException>)
            {
                ReceiveGenericMessage(message as GenericMessage<MissingMethodException>);
                return;
            }

            if (message is PropertyChangedMessage<DateTime>)
            {
                ReceivePropertyChangedMessage(message as PropertyChangedMessage<DateTime>);
                return;
            }

            if (message is CommandMessage<DateTime>)
            {
                ReceiveCommandMessage(message as CommandMessage<DateTime>);
                return;
            }

            if (message is GenericMessage<string>)
            {
                ReceiveGenericStringMessage(message as GenericMessage<string>);
                return;
            }

            ReceiveMessageBase(message);
        }
 protected override void ReceiveString(MessageBase m)
 {
     var message = m as GenericMessage<string>;
     if (message != null)
     {
         _innerRecipient = new TestRecipient4();
     }
 }
 protected void ReceiveStringNested(MessageBase m)
 {
     var message = m as GenericMessage<string>;
     if (message != null)
     {
         ReceivedStringMessages++;
         LastReceivedString = message.Content;
     }
 }
 protected virtual void ReceiveString(MessageBase m)
 {
     var message = m as GenericMessage<string>;
     if (message != null)
     {
         Messenger.Default.Register<MessageBase>(this, true, ReceiveStringNested);
     }
 }
        public async Task TryImportWithStatusNotifications()
        {
            _cancellationTokenSource = new CancellationTokenSource();
            Debug.WriteLine("Starting with ExtractProgram");
            ExtractProgramResult extractionResult = await ServiceLocator.ProgramImportService.ExtractProgram(_cancellationTokenSource.Token);

            if (_cancellationTokenSource.Token.IsCancellationRequested == true)
            {
                await CleanUpImport();
                return;
            }
            if (extractionResult.Status == ExtractProgramStatus.Error)
            {
                ServiceLocator.NotifictionService.ShowToastNotification(
                        AppResourcesHelper.Get("Import_ProgramDamaged"),
                        AppResourcesHelper.Get("Import_CatrobatDamagedText"),
                        ToastDisplayDuration.Long);
                return;
            }
            
            Debug.WriteLine("Starting with CheckProgram");
            var validateResult = await ServiceLocator.ProgramValidationService.CheckProgram(StorageConstants.TempProgramImportPath);

            if (_cancellationTokenSource.Token.IsCancellationRequested == true)
            {
                await CleanUpImport();
                return;
            }

            switch (validateResult.State)
            {
                case ProgramState.Valid:
                    _programName = validateResult.ProgramHeader.ProjectName;
                    break;
                case ProgramState.Damaged:
                    ServiceLocator.NotifictionService.ShowToastNotification("",
                        AppResourcesHelper.Get("Import_ProgramDamaged"),
                        ToastDisplayDuration.Long);
                    break;
                case ProgramState.VersionTooOld:
                    ServiceLocator.NotifictionService.ShowToastNotification("",
                        AppResourcesHelper.Get("Import_ProgramOutdated"),
                        ToastDisplayDuration.Long);
                    break;
                case ProgramState.VersionTooNew:
                    ServiceLocator.NotifictionService.ShowToastNotification("",
                        AppResourcesHelper.Get("Import_AppTooOld"),
                        ToastDisplayDuration.Long);
                    break;
                case ProgramState.ErrorInThisApp:
                    ServiceLocator.NotifictionService.ShowToastNotification("",
                        AppResourcesHelper.Get("Import_GeneralError"),
                        ToastDisplayDuration.Long);
                    break;
                case ProgramState.Unknown:
                    ServiceLocator.NotifictionService.ShowToastNotification("",
                        AppResourcesHelper.Get("Import_GeneralError"),
                        ToastDisplayDuration.Long);
                    break;
                case ProgramState.FilesMissing:
                    ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Import_Canceled"),
                    AppResourcesHelper.Get("Import_FilesMissing"), MissingFilesCallback, MessageBoxOptions.Ok);
                    return;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            Debug.WriteLine("Starting with AcceptTempProgram");
            await ServiceLocator.ProgramImportService.AcceptTempProgram();
            var localProgramsChangedMessage = new MessageBase();
            Messenger.Default.Send(localProgramsChangedMessage,
                ViewModelMessagingToken.LocalProgramsChangedListener);

            ServiceLocator.NotifictionService.ShowToastNotification("",
                AppResourcesHelper.Get("Import_ProgramAdded"),
                ToastDisplayDuration.Long,
                ToastTag.ImportFin);

            Debug.WriteLine("Finished");
        }
Exemplo n.º 14
0
        public void TestRegisterForSubclasses3()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses = new OldTestRecipient();
            Messenger.Default.Register(recipientForSubclasses, typeof(MessageBase), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(MessageBase), true);

            var message = new MessageBase(this);
            Messenger.Default.Broadcast(message);

            Assert.AreEqual(this, recipientForSubclasses.Sender);
            Assert.AreEqual(message, recipientForSubclasses.Message);
            Assert.AreEqual(this, recipientNoSubclasses.Sender);
            Assert.AreEqual(message, recipientNoSubclasses.Message);
        }
Exemplo n.º 15
0
        private static void SendToList(MessageBase message, IEnumerable<WeakReference> list)
        {
            if (list != null)
            {
                var listClone = list.Take(list.Count()).ToList();

                foreach (var recipient in listClone)
                {
                    if (recipient.IsAlive
                        && recipient.Target != null
                        && (message.Target == null
                            || (recipient.Target.GetType() == message.Target
                            || recipient.Target == message.Target)))
                    {
                        ((IMessageRecipient)recipient.Target).ReceiveMessage(message);
                    }
                }
            }
        }
Exemplo n.º 16
0
        private static async Task LoadContext()
        {
            await ServiceLocator.TraceService.LoadLocal();

            _context = new CatrobatContext();

            var localSettings = await ServiceLocator.ContextService.RestoreLocalSettings();
            _context.LocalSettings = localSettings;

            if (localSettings == null)
            {
                _context.LocalSettings = new LocalSettings();

                var defaultProject = await ServiceLocator.ContextService.
                    RestoreDefaultProgram(AppResources.Main_DefaultProgramName);

                ProgramChecker.CheckProgram(defaultProject);

                _context.LocalSettings.CurrentProgramName = defaultProject.Name;
                await defaultProject.Save();
            }

            if (_context.LocalSettings.CurrentLanguageString == null)
                _context.LocalSettings.CurrentLanguageString =
                    ServiceLocator.CultureService.GetCulture().TwoLetterISOLanguageName;

            var themeChooser = ServiceLocator.ThemeChooser;
            if (_context.LocalSettings.CurrentThemeIndex != -1)
                themeChooser.SelectedThemeIndex = _context.LocalSettings.CurrentThemeIndex;

            if (_context.LocalSettings.CurrentLanguageString != null)
                ServiceLocator.GetInstance<SettingsViewModel>().CurrentCulture =
                    new CultureInfo(_context.LocalSettings.CurrentLanguageString);

            var themeChooserChangedMessage = new GenericMessage<ThemeChooser>(themeChooser);
            Messenger.Default.Send(themeChooserChangedMessage, ViewModelMessagingToken.ThemeChooserListener);

            var contextChangedMessage = new GenericMessage<CatrobatContextBase>(_context);
            Messenger.Default.Send(contextChangedMessage, ViewModelMessagingToken.ContextListener);

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

            //var message = new GenericMessage<Project>(currentProject);
            //Messenger.Default.Send(message, ViewModelMessagingToken.CurrentProgramChangedListener);

            // allow viewmodels to load from settings
            Messenger.Default.Send(new GenericMessage<LocalSettings>(_context.LocalSettings), ViewModelMessagingToken.LoadSettings);
        }
            public void ReceiveMessage(MessageBase message)
            {
                var casted = message as GenericMessage<string>;
                if (casted != null)
                {
                    if (casted.Content == TestContentString)
                    {
                        ReceiveString(casted);
                        return;
                    }

                    if (casted.Content == TestContentStringNested)
                    {
                        ReceiveStringNested(casted);
                    }
                }
            }
Exemplo n.º 18
0
 protected void CrearPageCacheMessageAction(MessageBase message)
 {
     this.NavigationCacheMode = NavigationCacheMode.Disabled;
 }
Exemplo n.º 19
0
 private void ReceiveMessageBase(MessageBase message)
 {
     Message = message;
 }
        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.Name = ProgramName;
                    CurrentProgram.Description = ProgramDescription;
                    
                    var programChangedMessage1 = new GenericMessage<Program>(CurrentProgram);
                        Messenger.Default.Send(programChangedMessage1, 
                            ViewModelMessagingToken.CurrentProgramChangedListener);

                    using (var storage = StorageSystem.GetStorage())
                    {
                        await storage.RenameDirectoryAsync(oldProgramPath, ProgramName);
                    }
                    
                    var programChangedMessage2 = new GenericMessage<Program>(CurrentProgram);
                    Messenger.Default.Send(programChangedMessage2,
                        ViewModelMessagingToken.CurrentProgramChangedListener);

                    await App.SaveContext(CurrentProgram);

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

                    base.GoBackAction();
                }
            }

        }
Exemplo n.º 21
0
 private async void LocalProgramsChangedMessageAction(MessageBase message)
 {
     ServiceLocator.DispatcherService.RunOnMainThread(async () =>
     {
         await UpdateLocalPrograms();
     });
 }
        private async void SaveAction()
        {
            GoBackAction();

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

            if (CreateEmptyProgram)
            {
                CurrentProgram = await ServiceLocator.ContextService.CreateEmptyProgram(uniqueName);
                string backgroundName = "Background";
                var sprite = new Sprite { Name = backgroundName };
                CurrentProgram.Sprites.Add(sprite);
            }
            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);
        }
        private void HandleMessage(MessageBase message)
        {
            var vm = CreateViewModel(message);
            Title = vm.Title;
            CurrentContent = vm;

            Messenger.Default.Send(new ShowChildWindowMessage());
        }
        public void ReceiveMessageBase(MessageBase testMessage)
        {
            Assert.IsNotNull(testMessage);

            var castedMessage = testMessage as ITestMessage;

            if (castedMessage != null)
            {
                Assert.AreEqual(TestContent, castedMessage.Content);
                _messageWasReceived = true;
                _messageWasReceivedInMessageBase = true;
            }
        }
 private bool MessageIsForError(MessageBase message)
 {
     return message is DisplayErrorSavingDataMessage
            || message is DisplayErrorRetrievingDataMessage;
 }