Exemplo n.º 1
0
        private void OnTelegramServiceNewMessage(object sender, EventArgs.NewMessageEventArgs e)
        {
            _dispatcherService.InvokeIfRequired(async() =>
            {
                try
                {
                    var chat     = Chats.FirstOrDefault(x => x.Chat.Id == e.Message.Chat.Id);
                    bool newChat = chat == null;

                    if (newChat)
                    {
                        chat = ChatViewModel.Create(e.Message.Chat);
                        Chats.Add(chat);
                    }

                    chat.AddMessage(e.Message);
                    Chats.MoveItemToTop(chat);

                    if (newChat)
                    {
                        await chat.LoadImageAsync();
                    }
                }
                catch (Exception ex)
                {
                    ProcessException(ex);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Meant to be used by an inheriting controller to inject a view from the SwitchViewEvent, handled by OnSwitchViewEvent
        /// </summary>
        /// <typeparam name="TView"></typeparam>
        /// <param name="region"></param>
        /// <returns></returns>
        protected TView RegisterAndActivateView <TView>(string region = RegionNames.MainRegion) where TView : class
        {
            if (string.IsNullOrWhiteSpace(region))
            {
                region = RegionNames.MainRegion;
            }

            TView view = null;

            _dispatcherService.InvokeIfRequired(() =>
            {
                lock (_locker)
                {
                    try
                    {
                        view = _container.GetInstance <TView>();

                        try
                        {
                            _regionManager.Regions[region].ActiveViews.ToList().ForEach(v => _regionManager.Regions[region].Remove(v));
                            // Add it, then activate
                            _regionManager.AddToRegion(region, view);
                            _regionManager.Regions[region].Activate(view);
                        }
                        catch (Exception ex)
                        {
                            Logger.Default.Error("Unable to activate view.", ex);
                            view = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Default.Error("unable to switch view", ex);
                    }
                }
            });

            return(view);
        }