本文整理汇总了C#中EventAggregator.GetEvent方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.GetEvent方法的具体用法?C# EventAggregator.GetEvent怎么用?C# EventAggregator.GetEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventAggregator
的用法示例。
在下文中一共展示了EventAggregator.GetEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: GetReturnsSingleInstancesOfSameEventType
public void GetReturnsSingleInstancesOfSameEventType()
{
var eventAggregator = new EventAggregator();
var instance1 = eventAggregator.GetEvent<MockEventBase>();
var instance2 = eventAggregator.GetEvent<MockEventBase>();
Assert.AreSame(instance2, instance1);
}
示例3: Create
public static CodeFlowService Create(ConfigurationService configurationService, EventAggregator eventAggregator)
{
var authorWatch = configurationService["AuthorWatch"];
var secondAuthorWatch = configurationService["SecondAuthorWatch"];
var refreshInterval = int.Parse(configurationService["RefreshInterval"]);
var announceInterval = int.Parse(configurationService["AnnounceInterval"]);
var publishEventMessenger = eventAggregator.GetEvent<RawPublishEvent>();
var traceEventMessenger = eventAggregator.GetEvent<TraceEvent>();
return new CodeFlowService(authorWatch, secondAuthorWatch, refreshInterval, announceInterval, publishEventMessenger, traceEventMessenger);
}
示例4: Create
public static TfsClientService Create(ConfigurationService configurationService, EventAggregator eventAggregator)
{
var projectCollectionUrl = configurationService["ProjectCollectionUrl"];
var projectName = configurationService["ProjectName"];
var serverCountQueries = configurationService.Where(p => p.Key.StartsWith("query", StringComparison.OrdinalIgnoreCase)).Select(p => p.Value);
var refreshInterval = int.Parse(configurationService["RefreshInterval"]);
var nextInterval = int.Parse(configurationService["NextInterval"]);
var publishEventMessenger = eventAggregator.GetEvent<RawPublishEvent>();
var traceEventMessenger = eventAggregator.GetEvent<TraceEvent>();
return new TfsClientService(projectCollectionUrl, projectName, serverCountQueries, refreshInterval, nextInterval, publishEventMessenger, traceEventMessenger);
}
示例5: 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.");
}
}
示例6: 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());
}
示例7: Position
public Position()
{
RemoveFromCollectionCommand = new DelegateCommand(RemoveFromCollection);
GoToPositionCommand = new DelegateCommand(GoToPosition);
ea = ServiceLocator.Current.GetInstance<EventAggregator>();
ea.GetEvent<NewMicrostepResolutionEvent>()
.Subscribe(onMicrostepResolutionChanged, ThreadOption.BackgroundThread);
}
示例8: OrderAndPositionViewModel
public OrderAndPositionViewModel()
{
_eventaggregator = ServiceLocator.Current.GetInstance<EventAggregator>();
_logger = ServiceLocator.Current.GetInstance<ILoggerFacade>();
_configmanager = ServiceLocator.Current.GetInstance<IConfigManager>() as ConfigManager;
_ordertracker = new OrderTracker(_configmanager.DailyOrderCapacity);
_ordertracker.SendDebugEvent += OnDebug;
_positiontracker = new PositionTracker(_configmanager.DailyOrderCapacity);
_eventaggregator.GetEvent<InitialPositionEvent>().Subscribe(ClientGotInitialPosition);
//_eventaggregator.GetEvent<SendOrderEvent>().Subscribe(ClientGotOrder);
_eventaggregator.GetEvent<OrderConfirmationEvent>().Subscribe(ClientGotOrder);
_eventaggregator.GetEvent<OrderCancelConfirmationEvent>().Subscribe(ClientGotOrderCancelConfirmation);
_eventaggregator.GetEvent<OrderFillEvent>().Subscribe(ClientGotOrderFilled);
_eventaggregator.GetEvent<GenerateReportEvent>().Subscribe(GeneratePerformanceReport);
_resultstable.Columns.Add("Statistics");
_resultstable.Columns.Add("Result");
}
示例9: Subscribe_WhenGivenEvent_ShouldRaiseEvent
public void Subscribe_WhenGivenEvent_ShouldRaiseEvent()
{
var eventWasRaised = false;
var eventBus = new EventAggregator();
eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));
eventBus.Publish(new TestEvent());
Assert.IsTrue(eventWasRaised);
}
示例10: InputService
public InputService(EventAggregator eventAggregator, StandingsService standingsService)
{
_eventAggregator = eventAggregator;
_standingsService = standingsService;
_showEvent = _eventAggregator.GetEvent<ShowEvent>();
_activePlayerChangedEvent = _eventAggregator.GetEvent<ActivePlayerChangedEvent>();
_eventAggregator.GetEvent<ActivateEvent>().Subscribe(Activate);
_eventAggregator.GetEvent<CloseEvent>().Subscribe(Reset);
_buzz = new BuzzIOWrite.BuzzIOWrite();
_buzz.FindTheHid();
_players = new[] { false, false, false, false, false };
_pressed = new[] { false, false, false, false, false };
_used = new[] { false, false, false, false, false };
_timeleft = TimeAvailable;
_timer = new Timer(1000) { AutoReset = false };
_timer.Elapsed += new ElapsedEventHandler(OnTimerEnd);
}
示例11: Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent
public void Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent()
{
var eventWasRaised = false;
var eventBus = new EventAggregator();
var subscription = eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));
subscription.Dispose();
eventBus.Publish(new TestEvent());
Assert.IsFalse(eventWasRaised);
}
示例12: testing_subscribe
public void testing_subscribe()
{
// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();
// act
eventPublisher.GetEvent<SampleEvent>()
.Subscribe(se => eventWasRaised = true);
eventPublisher.Publish(new SampleEvent());
// assert
eventWasRaised.ShouldBe(true);
}
示例13: Main
public static void Main(string[] args)
{
// Instantiate the Prism event aggregator and subscribe to events of type ISignalREvent. (Yes, their syntax is awful).
var prismEventAggregator = new EventAggregator();
prismEventAggregator.GetEvent<PubSubEvent<SimpleEvent>>().Subscribe(SimpleEventSubscriber);
prismEventAggregator.GetEvent<PubSubEvent<ComplexEvent>>().Subscribe(ComplexEventSubscriber);
// Prepare the connection.
var hubConnection = new HubConnection("http://localhost:8700/");
hubConnection.Error += ex =>
{
Console.WriteLine("SignalR error: {0}", ex.Message);
};
// Create and initialise our shim. Must be done before hubConnection.Start().
var clientShim = new PrismEventAggregatorShim(prismEventAggregator);
PubSubSignalRClient.Initialise(hubConnection, clientShim);
// Connect.
hubConnection.Start().Wait();
Console.WriteLine("Client started! Press any key to stop...");
Console.ReadKey();
}
示例14: testing_selective_subscribe_ignored
public void testing_selective_subscribe_ignored()
{
// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();
// act
eventPublisher.GetEvent<SampleEvent>()
.Where(se => se.Status != 1)
.Subscribe(se => eventWasRaised = true);
eventPublisher.Publish(new SampleEvent { Status = 1 });
// assert
eventWasRaised.ShouldBe(false);
}
示例15: Progress_event
public void Progress_event()
{
IEventAggregator aggregator = new EventAggregator();
IFileDownloader downloader = new FileDownloader(aggregator);
downloader.Initialize();
var progressEvent = aggregator.GetEvent<UpdateProgressEvent>();
int progressEventTimes = 0;
progressEvent.Subscribe(state => progressEventTimes++);
using (var file = downloader.Download(new Uri("http://www.google.co.nz/")))
{
Assert.IsNotNull(file);
file.File.Refresh();
Assert.IsTrue(file.File.Length > 0);
}
Assert.IsTrue(progressEventTimes > 0);
}