本文整理汇总了C#中IMessageBus.Listen方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageBus.Listen方法的具体用法?C# IMessageBus.Listen怎么用?C# IMessageBus.Listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessageBus
的用法示例。
在下文中一共展示了IMessageBus.Listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PasteViewModel
public PasteViewModel(ClipboardItem clipboardItem, IRoom room, IMessageBus bus)
{
if (clipboardItem.IsImage)
{
_imageSource = clipboardItem.LocalPath;
}
else
{
_imageSource = DependencyProperty.UnsetValue;
}
Caption = "Upload this " + (clipboardItem.IsImage ? "image" : "file") + "?";
LocalPath = clipboardItem.LocalPath;
ShowLocalPath = !clipboardItem.IsImage;
ContentType = clipboardItem.ContentType;
Size = clipboardItem.Size;
PasteCommand = new ReactiveCommand();
Subscribe(bus.Listen<FileUploadedMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
.SubscribeUI(_ => IsFinished = true));
Subscribe(bus.Listen<FileUploadProgressChangedMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
.SubscribeUI(
msg =>
{
ProgressCurrent = msg.Progress.Current;
ProgressTotal = msg.Progress.Total;
Debug.WriteLine("Current, total" + ProgressCurrent + ", " + ProgressTotal);
}));
Subscribe(bus.Listen<CorrelatedExceptionMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
.SubscribeUI(msg =>
{
IsErrored = true;
IsUploading = false;
LastException = msg.Exception;
}));
ProgressCurrent = 0;
ProgressTotal = 100;
Subscribe(bus.RegisterMessageSource(
PasteCommand.Do(_ =>
{
IsUploading = true;
IsErrored = false;
})
.Select(_ => new RequestUploadFileMessage(room.Id, clipboardItem.LocalPath, clipboardItem.ContentType))
.Do(msg => _currentCorrelation = msg.CorrelationId)));
CancelCommand = new ReactiveCommand();
Subscribe(CancelCommand.Subscribe(_ => IsFinished = true));
}
示例2: Register
public void Register(IMessageBus bus)
{
// Listen for the message which attaches a frame.
bus.Listen<ApplicationInitializedMessage>()
.ObserveOn(RxApp.DeferredScheduler)
.Subscribe(s => Frame = s.RootFrame);
// Listen for the message which attaches a popup host.
bus.Listen<PopupHostReadyMessage>()
.ObserveOn(RxApp.DeferredScheduler)
.Subscribe(m => PopupHost = m.PopupHost);
}
示例3: ShellView
public ShellView(IShellViewModel vm, IMessageBus bus, IModuleResolver resolver, ISettings settings)
: this()
{
_bus = bus;
_resolver = resolver;
_settings = settings;
DataContext = vm;
_bus.Listen<ActivateMainModuleMessage>().Subscribe(msg => ActivateMainModule(msg.ModuleName));
_bus.Listen<NavigateMainModuleMessage>().Subscribe(msg => NavigateMainModule(msg.ModuleName));
_bus.Listen<NavigateBackMainModuleMessage>().Where(_ => _navigationStack.Count > 0).Subscribe(
_ => NavigateBack());
_bus.Listen<SettingsChangedMessage>().Subscribe(OnSettingsChanged);
}
示例4: Register
public void Register(IMessageBus bus)
{
// Listen for the message which has us navigate.
bus.Listen<NavigateMessage>()
.ObserveOn(RxApp.DeferredScheduler)
.Subscribe(OnNavigateMessage);
}
示例5: ModuleLoader
public ModuleLoader(IMessageBus bus, IWindsorContainer windsorContainer)
{
_bus = bus;
_windsorContainer = windsorContainer;
_bus.Listen<ApplicationLoadedMessage>().ObserveOn(Scheduler.ThreadPool).Subscribe(OnApplicationLoaded);
}
示例6: LoanViewModel
public LoanViewModel(IMessageBus messenger, Loan loan)
{
myLoan = loan;
_OweTo = myLoan.Lender.Name;
_APR = myLoan.APR;
_OutstandingBalance = myLoan.OutstandingBalance(DateTime.Now);
_MakePaymentCommand = new DelegateCommand(MakePaymentExecute, MakePaymentCanExecute);
myMessenger = messenger;
myMessenger
.Listen<Loan>("PaymentMade")
.ObserveOnDispatcher()
.Subscribe(
l =>
{
if (l == myLoan)
{
myMessenger.SendMessage<Person>(loan.Lender, "BalanceChanged");
myMessenger.SendMessage<Person>(loan.Borrower, "BalanceChanged");
this.PaymentMaker = null;
this.OutstandingBalance = myLoan.OutstandingBalance(DateTime.Now);
}
});
}
示例7: NewImageVM
public NewImageVM(IMessageBus Messenger,
IStoreImages ImageStore) {
Messenger.Listen<IElementVM<MultimediaObject>>(MessageContracts.EDIT)
.Where(vm => vm.Model.MediaType == MediaType.Image && vm.Model.IsNew())
.SelectMany(mmo => {
var capture = new CameraCaptureTask();
var results =
Observable.FromEventPattern<PhotoResult>(h => capture.Completed += h, h => capture.Completed -= h)
.Select(ev => ev.EventArgs)
.Catch(Observable.Empty<PhotoResult>())
.Select(res => new { VM = mmo, Result = res })
.Take(1)
.Replay(1);
results.Connect();
try {
capture.Show();
}
catch (InvalidOperationException) {
}
return results;
})
.Where(tuple => tuple.VM != null
&& tuple.Result != null
&& tuple.Result.TaskResult == TaskResult.OK)
.Do(tuple => {
tuple.VM.Model.Uri = ImageStore.StoreImage(tuple.VM.Model.NewFileName(), tuple.Result);
})
.Select(t => t.VM as IElementVM<MultimediaObject>)
.ToMessage(Messenger, MessageContracts.SAVE);
}
示例8: SubscribeToMessageBus
public void SubscribeToMessageBus(IMessageBus messageBus)
{
if (this.subscription == null)
{
this.subscription = messageBus.Listen<object>().Subscribe(this.SubscriptionHandler);
}
}
示例9: NavigationContentViewModel
public NavigationContentViewModel(ISettingsViewModel settingsViewModel, IMessageBus bus)
{
_settingsViewModel = settingsViewModel;
bus.Listen<AppUpdateAvailableMessage>().SubscribeOnceUI(_ =>
{
ShowUpdate = true;
});
bus.Listen<AppUpdateProgressMessage>().SubscribeUI(msg =>
{
ShowProgress = true;
ShowUpdate = false;
ProgressValue = msg.ProgressPercentage;
});
StartUpdateCommand = new ReactiveCommand();
bus.RegisterMessageSource(StartUpdateCommand.Select(c => new RequestAppUpdateMessage()));
}
示例10: ModuleViewModel
public ModuleViewModel(IModule module, IMessageBus bus)
{
_module = module;
_bus = bus;
_bus.Listen<RoomActivityMessage>().Delay(TimeSpan.FromMilliseconds(100))
.SubscribeUI(msg => this.RaisePropertyChanged(vm => vm.Notifications));
}
示例11: ShellViewModel
public ShellViewModel(IMainScreen mainScreen, IMessageBus bus)
{
_navigationStack.Push(mainScreen);
bus.Listen<NavigateMainModuleMessage>().SubscribeUI(msg => NavigateTo(msg.Module.MainViewModel));
NavigateBackCommand = new ReactiveCommand();
NavigateBackCommand.SubscribeUI(NavigateBack);
}
示例12: ShellViewModel
public ShellViewModel(IMessageBus bus)
{
Title = DefaultTitle;
var activated = bus.Listen<ApplicationActivatedMessage>();
var deactivated = bus.Listen<ApplicationDeactivatedMessage>();
bus.Listen<RoomActivityMessage>()
.SkipUntil(deactivated)
.TakeUntil(activated.Do(_ => UnreadCount = 0))
.Repeat()
.Subscribe(_ => UnreadCount++);
bus.Listen<RequestApplicationRestartMessage>().ObserveOnDispatcher().Subscribe(_ =>
{
System.Windows.Forms.Application.Restart();
Environment.Exit(1);
});
}
示例13: ToastWindowViewModel
public ToastWindowViewModel(Func<IChatDocument> chatDocumentCreator, IMessageBus bus, IApplicationActivator activator)
{
_chatDocumentCreator = chatDocumentCreator;
_bus = bus;
_activator = activator;
Toasts = new ReactiveCollection<ToastViewModel>();
Subscribe(() => bus.Listen<ShowToastMessage>().SubscribeUI(OnShowToast));
}
示例14: RoomListViewModel
public RoomListViewModel(Room room, IMessageBus bus)
{
_room = room;
_bus = bus;
bus.Listen<RoomPresenceMessage>().SubscribeUI(msg => IsActive = msg.IsPresentIn(_room.Id));
_bus.Listen<RoomActivatedMessage>().Where(msg => msg.RoomId == _room.Id)
.Do(_ => IsJoiningRoom = false)
.SubscribeUI(_ => IsCurrentRoom = true);
_bus.Listen<RoomDeactivatedMessage>().Where(msg => msg.RoomId == _room.Id)
.SubscribeUI(_ => IsCurrentRoom = false);
_bus.Listen<RoomActivityMessage>().Where(msg => msg.RoomId == _room.Id)
.SubscribeUI(msg => RoomActivityCount += msg.Count);
JoinCommand = new ReactiveCommand();
JoinCommand.Do(_ => IsJoiningRoom = true).SubscribeUI(HandleJoinCommand);
}
示例15: MainCampfireView
public MainCampfireView(IMainCampfireViewModel model, IMessageBus bus, INavigationContent content)
: this()
{
_bus = bus;
_content = content;
_model = model;
DataContext = model;
bus.Listen<ActivateModuleMessage>()
.Where(msg => msg.ParentModule == ModuleNames.MainCampfireView)
.Where(msg => msg.Module != _moduleContainer.Content)
.SubscribeUI(ActivateModule);
}