コード例 #1
0
        private void AddMessenger(IMessengerConfiguration configuration)
        {
            IMessenger newMessenger = null;

            try
            {
                var messengerType = Type.GetType(configuration.MessengerTypeName);

                if (messengerType != null)
                {
                    newMessenger = (IMessenger)Activator.CreateInstance(messengerType);
                }
            }
            catch (Exception)
            {
            }

            //next step: initialize it
            if (newMessenger != null)
            {
                try
                {
                    newMessenger.Initialize(this, configuration);

                    //now add it to our collection
                    lock (m_ConfigLock)
                    {
                        m_Messengers.Add(newMessenger);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #2
0
        public RoomsViewModel(Page page)
        {
            this.page  = page;
            _messenger = DependencyService.Get <IMessenger>();

            ConnectCommand = new Command(async() =>
            {
                var success    = false;
                string message = string.Empty;
                try
                {
                    IsBusy  = true;
                    success = await _messenger.Initialize();
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
                finally
                {
                    IsBusy = false;
                }

                if (success)
                {
                    await page.DisplayAlert("Success", "Now joining #general.", "OK");
                    await page.Navigation.PushAsync(new MainChatPage());
                }
                else
                {
                    await page.DisplayAlert("Sad Monkeys", $"Unable to join #general: {message}", "OK");
                }
            });
        }