本文整理汇总了C#中EventAggregator类的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator类的具体用法?C# EventAggregator怎么用?C# EventAggregator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventAggregator类属于命名空间,在下文中一共展示了EventAggregator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServiceFactoryBase
static ServiceFactoryBase()
{
Events = new EventAggregator();
ResourceService = new ResourceService();
DialogService = new RealDialogService();
MessageBoxService = new RealMessageBoxService();
}
示例2: App
public App()
{
try
{
IUnityContainer unityContainer = new UnityContainer();
var connectionString = System.Configuration.ConfigurationSettings.AppSettings.Get("webService");
IWebservice webService = new Webservice(connectionString);
EventAggregator eventAggregator = new EventAggregator();
unityContainer.RegisterInstance<IEventAggregator>(eventAggregator);
unityContainer.RegisterInstance<IWebservice>(webService);
IMessaging emailMessenger = new EmailMessaging();
unityContainer.RegisterInstance<IMessaging>(emailMessenger);
var regionManager = new RegionManager();
regionManager.Regions.Add(new Region() { Name = "MainContentRegion" });
unityContainer.RegisterInstance<IRegionManager>(regionManager);
ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(unityContainer));
}
catch (Exception ex)
{
logger.Error("Error in app constructor", ex);
}
}
示例3: a_published_message_is_received_by_multiple_subscribers
public void a_published_message_is_received_by_multiple_subscribers()
{
// When the bus publishes a message, it is sent through the socket
var consumer = new ZeroConsumer<Message>("tcp://localhost:5562");
var bus = new BusAdapter();
bus.AttachConsumer(consumer);
// Meanwhile, the aggregator waits for messages from the same socket
var producer = new ZeroProducer<Message>("tcp://*:5562");
var aggregator = new EventAggregator<Message>();
aggregator.AttachTo(producer);
// While two test consumers are subscribed to the aggregator
// (the syntax looks like it's the other way around)
var confirmById = new FakeEventConsumer();
var confirmAsReceived = new TestConsumer();
aggregator.SubscribeTo(confirmById);
aggregator.SubscribeTo(confirmAsReceived);
// When we drop a message on the bus, the test consumer should get it
var @event = new FakeEvent();
bus.Publish(@event);
// Pause the thread so the producer (via aggregator) can send to the test consumer
var timeout = TimeSpan.FromSeconds(1).TotalMilliseconds;
Thread.Sleep((int)timeout);
Assert.IsTrue(confirmAsReceived.Received);
Assert.AreEqual(@event.Id, confirmById.Id);
producer.Dispose();
consumer.Dispose();
}
示例4: Given
protected override void Given()
{
eventAggregator = new EventAggregator();
view = new Mock<ITerritoryStatsView>();
territoryStats = new TerritoryStatsPresentationModel(
view.Object, eventAggregator);
}
示例5: ActivityFinderPopupViewModel
public ActivityFinderPopupViewModel(BcontrolDataHandler datahandler,C1DataGrid searchGrid)
{
eventaggregator = EventAggregator.Instance;
IsVisible = false;
_datahandler = datahandler;
_datahandler.SearchInitialDataRetrieved += new EventHandler<GetSearchInitialDataCompletedEventArgs>(bcontrolDataHandler_SearchInitialDataRetrieved);
_datahandler.SearchByMapListRetrieved +=new EventHandler<GetSearchMapListCompletedEventArgs>(bcontrolDatahandler_SearchByMapListRetrieved);
_datahandler.SearchByGlobalHeadListRetrieved += new EventHandler<GetSearchGlobalHeadListCompletedEventArgs>(bcontrolDatahandler_SearchByGlobalHeadListRetrieved);
_datahandler.SearchByGlobalFunctionListRetrieved += new EventHandler<GetSearchGlobalFunctionListCompletedEventArgs>(bcontrolDatahandler_SearchByGlobalFunctionListRetrieved);
_datahandler.SearchByBusinessAreaListRetrieved += new EventHandler<GetSearchBusinessAreaListCompletedEventArgs>(bcontrolDatahandler_SearchByBusinessAreaListRetrieved);
_datahandler.SearchByBusinessFunctionListRetrieved += new EventHandler<GetSearchBusinessFunctionListCompletedEventArgs>(bcontrolDatahandler_SearchByBusinessFunctionListRetrieved);
_datahandler.SearchBySubFunctionListRetrieved += new EventHandler<GetSearchSubFunctionListCompletedEventArgs>(bcontrolDatahandler_SearchByBusinessSubFunctionListRetrieved);
_datahandler.SearchByLevelDataRetrieved += new EventHandler<GetSearchResultsBylevelCompletedEventArgs>(bcontrolDataHandler_SearchByLevelDataRetrieved);
_datahandler.SearchByHierarchyDataRetrieved += new EventHandler<GetSearchResultsByHierarchyCompletedEventArgs>(bcontrolDataHandler_SearchByHierarchyDataRetrieved);
_datahandler.DiagramTemplateLinkRetrieved += new EventHandler<GetDiagramTemplateLinkCompletedEventArgs>(bcontrolDataHandler_DiagramTemplateLinkRetrieved);
_datahandler.ExisitingActivitiesRetrieved +=new EventHandler<GetExisitingActivitiesCompletedEventArgs>(bcontrolDatahandler_ExisitingActivitiesRetrieved);
_isModifiedLinks = false;
_searchResultsList = new ObservableCollection<ActivitySet>();
_datahandler.GetDiagramTemplateLink();
ErrorMessage = "";
_searchGrid = searchGrid;
}
示例6: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
RegisterServices();
EventAggregator = new EventAggregator();
}
示例7: UploadReportHierarchyViewModel
public UploadReportHierarchyViewModel(StringBuilder log, C1DataGrid grid, BcontrolDataHandler bcontrolDataHandler)
{
eventaggregator = EventAggregator.Instance;
_log = log;
_grid = grid;
PreviewCommand = new RelayCommand(PreviewAction);
PreviewCommand.IsEnabled = false;
UploadCommand = new RelayCommand(UploadAction);
UploadCommand.IsEnabled = false;
CloseCommand = new RelayCommand(CloseAction);
CloseCommand.IsEnabled = true;
_datahandler = bcontrolDataHandler;
_datahandler.ClearBcontrolHierarchyDataRetrieved += new EventHandler<ClearBcontrolHierarchyDataCompletedEventArgs>(_datahandler_ClearBcontrolHierarchyDataRetrieved);
_datahandler.AddBcontrolHierarchyDataRetrieved += new EventHandler<AddBcontrolHierarchyDataCompletedEventArgs>(_datahandler_AddBcontrolHierarchyDataRetrieved);
_datahandler.CompleteAddBcontrolHierarchyDataRetrieved += new EventHandler<CompleteAddBcontrolHierarchyDataCompletedEventArgs>(_datahandler_CompleteAddBcontrolHierarchyDataRetrieved);
_columns = new Dictionary<string, ReportField>();
_columns.Add("Map Name", new ReportField(100, true));
_columns.Add("Level", new ReportField(500, true));
_columns.Add("FunctionalHead", new ReportField(50, false));
_columns.Add("AdditionalData", new ReportField(100, false));
_columns.Add("TOM", new ReportField(100, false));
_columns.Add("REN", new ReportField(100, false));
_columns.Add("Bcontrol Function Structure", new ReportField(100, false));
_columns.Add("Taxonomy Level 3", new ReportField(100, false));
_columns.Add("BusinessHierarchy1", new ReportField(100, false));
_columns.Add("BusinessHierarchy2", new ReportField(100, false));
_columns.Add("BusinessHierarchy3", new ReportField(100, false));
}
示例8: ShouldPassOnTheHintFromTheFirstHelpfulRule
public void ShouldPassOnTheHintFromTheFirstHelpfulRule()
{
// Given an event aggregator to which we're subscribed
var events = new EventAggregator();
Hint hint = null;
events.GetEvent<HintProvidedEvent>().Subscribe(h => hint = h);
// And one rule which fails then one which passes first time
var unhelpfulRule = new Mock<IMightBeAbleToHelp>();
unhelpfulRule.Setup(r => r.HelpWith(It.IsAny<NineCells>())).Returns(Hint.None);
var expectedHint = new Hint("I can help!", new List<Cell>());
var helpfulRule = new Mock<IMightBeAbleToHelp>();
helpfulRule.Setup(r => r.HelpWith(It.IsAny<NineCells>())).Returns(expectedHint);
// And a repository with some cells in it
var repository = new Mock<ILookAfterCells>();
repository.Setup(r => r.FetchCellsByRowColumnOrNiner()).Returns(
new List<NineCells> {new NineCells(new Cell[0])});
// When we publish a request for a hint
new Solver(events, repository.Object, new[] {unhelpfulRule.Object, helpfulRule.Object});
events.GetEvent<HintRequestEvent>().Publish(null);
// Then the solver should publish the first helpful hint
Assert.AreEqual(expectedHint, hint);
}
示例9: TryGetEventHandler_should_return_false_when_no_subscribers_exist
public void TryGetEventHandler_should_return_false_when_no_subscribers_exist()
{
var subject = new EventAggregator();
Action<int> handler;
subject.TryGetEventHandler(out handler).Should().BeFalse();
}
示例10: ObserverShouldOnlyReceiveSubscribedNotifications
public void ObserverShouldOnlyReceiveSubscribedNotifications()
{
// Arrange
var eventAggregator = new EventAggregator();
var observer1 = new Mock<IObserve<TestEvent>>();
var observer2 = new Mock<IObserve<OtherEvent>>();
eventAggregator.Subscribe(observer1.Object);
eventAggregator.Subscribe(observer2.Object);
var testEvent = new TestEvent();
var otherEvent = new OtherEvent();
// Act
eventAggregator.Publish(testEvent);
eventAggregator.Publish(otherEvent);
// Assert
observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Once);
observer1.Verify(x => x.OnNext(testEvent), Times.Once);
observer2.Verify(x => x.OnNext(otherEvent), Times.Once);
}
示例11: Navigate_To_Subsequent_Page_Back_Button_Visible
public async Task Navigate_To_Subsequent_Page_Back_Button_Visible()
{
await DispatcherHelper.ExecuteOnUIThread(() =>
{
var eventAggregator = new EventAggregator();
var frame = new FrameFacadeAdapter(new Frame(), eventAggregator);
var sessionStateService = new MockSessionStateService();
sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>();
var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);
var deviceGestureService = new DeviceGestureService(eventAggregator);
deviceGestureService.UseTitleBarBackButton = true;
var navigationManager = SystemNavigationManager.GetForCurrentView();
// Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);
navigationService.Navigate("Mock", 1);
Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);
navigationService.Navigate("Mock", 2);
Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility);
});
}
示例12: Navigate_Raises_NavigationStateChangedEvent
public async Task Navigate_Raises_NavigationStateChangedEvent()
{
var tcs = new TaskCompletionSource<bool>();
var eventAggregator = new EventAggregator();
eventAggregator.GetEvent<NavigationStateChangedEvent>().Subscribe((args) => tcs.SetResult(args.StateChange == StateChangeType.Forward));
await DispatcherHelper.ExecuteOnUIThread(() =>
{
var frame = new FrameFacadeAdapter(new Frame(), eventAggregator);
var sessionStateService = new MockSessionStateService();
sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>();
var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);
navigationService.Navigate("Mock", 1);
});
await Task.WhenAny(tcs.Task, Task.Delay(200));
if (tcs.Task.IsCompleted)
{
Assert.IsTrue(tcs.Task.Result);
}
else
{
Assert.Fail("NavigationStateChangedEvent event wasn't raised within 200 ms.");
}
}
示例13: A_valid_message_invokes_HandlerResultProcessing_when_expected_to
public void A_valid_message_invokes_HandlerResultProcessing_when_expected_to() {
var eventAggregator = new EventAggregator();
var coroutineHandlerMock = new Mock<IHandleWithCoroutine<object>>();
var taskHandlerMock = new Mock<IHandleWithTask<object>>();
var coroutineHandlerProcessed = false;
var taskHandlerProcessed = false;
coroutineHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
.Returns(() => new List<IResult>());
taskHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
.Returns(() => new Task(() => { }));
EventAggregator.HandlerResultProcessing = (target, result) => {
if (target is IHandleWithCoroutine<object>) {
coroutineHandlerProcessed = true;
}
else if (target is IHandleWithTask<object>) {
taskHandlerProcessed = true;
}
};
eventAggregator.Subscribe(coroutineHandlerMock.Object);
eventAggregator.Subscribe(taskHandlerMock.Object);
eventAggregator.Publish(new object());
Assert.True(coroutineHandlerProcessed);
Assert.True(taskHandlerProcessed);
}
示例14: ShouldAskEachRuleInTurnWithNinersRowsAndColumnsUntilOnePasses
public void ShouldAskEachRuleInTurnWithNinersRowsAndColumnsUntilOnePasses()
{
// Given a repository with different rows, columns and niners
var niners = new List<NineCells> { new NineCells( new[] {new Cell(new CellId(-1, -1)) } )};
var rows = new List<NineCells> { new NineCells( new[] {new Cell(new CellId(-1, -1)) } )};
var columns = new List<NineCells>
{
new NineCells(new[] {new Cell(new CellId(-1, -1))} ),
new NineCells(new[] {new Cell(new CellId(-1, -1))} ),
new NineCells(new[] {new Cell(new CellId(-1, -1))} ),
};
var repository = new Mock<ILookAfterCells>();
var allSequences = new[] {niners, rows, columns}.SelectMany(list => list).ToArray();
repository.Setup(r => r.FetchCellsByRowColumnOrNiner()).Returns(allSequences);
// And one rule which fails then one which passes first time
var unhelpfulRule = new Mock<IMightBeAbleToHelp>();
unhelpfulRule.Setup(r => r.HelpWith(It.IsAny<NineCells>())).Returns(Hint.None);
var expectedHint = new Hint("I can help!", new List<Cell>());
var helpfulRule = new Mock<IMightBeAbleToHelp>();
helpfulRule.Setup(r => r.HelpWith(It.IsAny<NineCells>())).Returns(expectedHint);
// When we ask the solver for a hint
var events = new EventAggregator();
new Solver(events, repository.Object, new[] {unhelpfulRule.Object, helpfulRule.Object});
events.GetEvent<HintRequestEvent>().Publish(null);
// Then the first rule should be called with each niner, row and column
Array.ForEach(allSequences, s => unhelpfulRule.Verify(r => r.HelpWith(s)));
// And the second should only be called once
helpfulRule.Verify(r => r.HelpWith(It.IsAny<NineCells>()), Times.Once());
}
示例15: MainViewModel
public MainViewModel()
{
var events = new EventAggregator();
var config = new Configuration(events: events).WithCss().WithDefaultLoader(m =>
{
m.IsNavigationEnabled = true;
m.IsResourceLoadingEnabled = true;
});
context = BrowsingContext.New(config);
profiler = new ProfilerViewModel(events);
errors = new ErrorsViewModel(events);
dom = new DOMViewModel();
query = new QueryViewModel();
repl = new ReplViewModel();
settings = new SettingsViewModel();
statistics = new StatisticsViewModel();
tree = new TreeViewModel();
sheets = new SheetViewModel();
cts = new CancellationTokenSource();
views = new ITabViewModel[]
{
dom,
query,
repl,
statistics,
tree,
sheets
};
logs = new IEventViewModel[]
{
profiler,
errors
};
}