public override void Initialize(IAppContext context) { _context = context; _menuGenerator = context.Container.GetInstance <MenuGenerator>(); _menuListener = context.Container.GetInstance <MenuListener>(); _mapListener = context.Container.GetInstance <MapListener>(); _dockPanelService = context.Container.GetInstance <DockPanelService>(); }
public static EntryListenerAdapter <TKey, TValue> CreateAdapter(MapListener mapListener, ISerializationService serializationService) { var adapter = new EntryListenerAdapter <TKey, TValue> { SerializationService = serializationService }; if (mapListener is EntryAddedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Added; adapter.Added = ((EntryAddedListener <TKey, TValue>)mapListener).EntryAdded; } if (mapListener is EntryRemovedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Removed; adapter.Removed = ((EntryRemovedListener <TKey, TValue>)mapListener).EntryRemoved; } if (mapListener is EntryUpdatedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Updated; adapter.Updated = ((EntryUpdatedListener <TKey, TValue>)mapListener).EntryUpdated; } if (mapListener is EntryEvictedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Evicted; adapter.Evicted = ((EntryEvictedListener <TKey, TValue>)mapListener).EntryEvicted; } if (mapListener is EntryLoadedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Loaded; adapter.Loaded = ((EntryLoadedListener <TKey, TValue>)mapListener).EntryLoaded; } if (mapListener is MapEvictedListener) { adapter.ListenerFlags |= EntryEventType.EvictAll; adapter.EvictAll = ((MapEvictedListener)mapListener).MapEvicted; } if (mapListener is MapClearedListener) { adapter.ListenerFlags |= EntryEventType.ClearAll; adapter.ClearAll = ((MapClearedListener)mapListener).MapCleared; } if (mapListener is EntryMergedListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Merged; adapter.Merged = ((EntryMergedListener <TKey, TValue>)mapListener).EntryMerged; } if (mapListener is EntryExpiredListener <TKey, TValue> ) { adapter.ListenerFlags |= EntryEventType.Expired; adapter.Expired = ((EntryExpiredListener <TKey, TValue>)mapListener).EntryExpired; } return(adapter); }
public override void Initialize(IAppContext context) { if (context == null) { throw new ArgumentNullException("context"); } _context = context; _menuGenerator = context.Container.GetInstance <MenuGenerator>(); _menuListener = context.Container.GetInstance <MenuListener>(); _mapListener = context.Container.GetInstance <MapListener>(); _menuUpdater = context.Container.GetInstance <MenuUpdater>(); }
public void Command_Received_Non_Match_Or_Empty_Ignored() { var listener = new MapListener(_mockChatClient.Object, _mockMapsClient.Object); var cmd = new CommandEventArgs(null, null, "doughnut"); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); cmd = new CommandEventArgs(null, null, "map of"); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); _mockChatClient.Verify(m => m.SendMessage(It.IsAny<string>(), It.IsAny<string[]>()), Times.Never); }
public void Command_Received_Match_Trims_Tag() { _mockMapsClient .Setup(m => m.GetStaticUrlAsync(It.IsAny<string>())) .ReturnsAsync(StaticUrl); var listener = new MapListener(_mockChatClient.Object, _mockMapsClient.Object); var cmd = new CommandEventArgs(null, null, ValidCmd + " "); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); _mockMapsClient.Verify(m => m.GetStaticUrlAsync("bristol")); }
public void Command_Received_Match_Http_Exception_Caught() { _mockMapsClient .Setup(m => m.GetStaticUrlAsync(It.IsAny<string>())) .Throws(new HttpClientException(null, null)); var listener = new MapListener(_mockChatClient.Object, _mockMapsClient.Object); var cmd = new CommandEventArgs("#chan1", "JIM", ValidCmd); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); _mockChatClient.Verify(m => m.SendMessage("JIM: Whoops, something went wrong", "#chan1")); }
public Guid AddEntryListener(MapListener listener, bool includeValue) { var listenerAdapter = EntryListenerAdapter <TKey, TValue> .CreateAdapter(listener, Client.SerializationService); var listenerFlags = (int)listenerAdapter.ListenerFlags; var request = MapAddEntryListenerCodec.EncodeRequest(Name, includeValue, listenerFlags, IsSmart()); DistributedEventHandler handler = eventData => MapAddEntryListenerCodec.EventHandler.HandleEvent(eventData, (key, value, oldValue, mergingValue, type, uuid, entries) => { OnEntryEvent(key, value, oldValue, mergingValue, type, uuid, entries, listenerAdapter); }); return(RegisterListener(request, message => MapAddEntryListenerCodec.DecodeResponse(message).Response, id => MapRemoveEntryListenerCodec.EncodeRequest(Name, id), handler)); }
public void Command_Received_Match_Replies() { _mockMapsClient .Setup(m => m.GetStaticUrlAsync(It.IsAny<string>())) .ReturnsAsync(StaticUrl); var listener = new MapListener(_mockChatClient.Object, _mockMapsClient.Object); var cmd = new CommandEventArgs("#chan1", "JIM", ValidCmd); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); cmd = new CommandEventArgs("#chan1", "JIM", "map edinburgh"); _mockChatClient.Raise(m => m.CommandReceived += null, cmd); _mockChatClient.Verify(m => m.SendMessage($"JIM: {StaticUrl}", "#chan1"), Times.Exactly(2)); }
public string AddEntryListener(MapListener listener, TKey key, bool includeValue) { var keyData = ToData(key); var listenerAdapter = EntryListenerAdapter <TKey, TValue> .CreateAdapter(listener, GetContext().GetSerializationService()); var listenerFlags = (int)listenerAdapter.ListenerFlags; var request = MapAddEntryListenerToKeyCodec.EncodeRequest(GetName(), keyData, includeValue, listenerFlags, IsSmart()); DistributedEventHandler handler = eventData => MapAddEntryListenerToKeyCodec.EventHandler.HandleEvent(eventData, (key_, value, oldValue, mergingValue, type, uuid, entries) => { OnEntryEvent(key_, value, oldValue, mergingValue, type, uuid, entries, listenerAdapter); }); return(RegisterListener(request, message => MapAddEntryListenerToKeyCodec.DecodeResponse(message).response, id => MapRemoveEntryListenerCodec.EncodeRequest(GetName(), id), handler)); }
/*private readonly LegendListener _legendListener; * private readonly MainPluginListener _mainPluginListener; * * * private readonly MenuListener _menuListener; */ // // public MainPresenter( IAppContext context, IMainView view, IConfigService configService, MapLegendPresenter mapLegendPresenter, OverviewPresenter overviewPresenter, IProjectService projectService) : base(view) { Logger.Current.Trace("Start MainPresenter"); if (view == null) { throw new ArgumentNullException("view"); } if (projectService == null) { throw new ArgumentNullException("projectService"); } if (configService == null) { throw new ArgumentNullException("configService"); } _context = context; _configService = configService; _projectService = projectService; // view.Map.Lock(); try { var appContext = context as AppContext; if (appContext == null) { throw new InvalidCastException("Invalid type of IAppContext instance"); } appContext.Init(view, projectService, configService, mapLegendPresenter, overviewPresenter); //projectService, configService); //最后去整理,当前的工作环境需要的配置参数有哪些 /* view.Map.Initialize(); * view.Map.ApplyConfig(configService);*/ view.ViewClosing += OnViewClosing; view.ViewUpdating += OnViewUpdating; view.BeforeShow += OnBeforeShow; var container = context.Container; _statusBarListener = container.GetSingleton <StatusBarListener>(); _menuGenerator = container.GetSingleton <MenuGenerator>(); _menuUpdater = new MenuUpdater(_context, PluginIdentity.Default, _menuGenerator.GetMenuKeys()); _mapListener = container.GetSingleton <MapListener>(); /*_menuListener = container.GetSingleton<MenuListener>(); * * _mainPluginListener = container.GetSingleton<MainPluginListener>(); * _legendListener = container.GetSingleton<LegendListener>(); * */ SplashView.Instance.ShowStatus("开始引导插件..."); appContext.InitPlugins(configService); // must be called after docking is initialized _context.RibbonMenu.ReorderTabs(); // this will display progress updates and debug window // file based-logger is already working Logger.Current.Init(appContext); } finally { /*view.Map.Unlock(); * context.Legend.Unlock();*/ } View.AsForm.Shown += ViewShown; Logger.Current.Trace("End MainPresenter"); }
public MainPresenter( IAppContext context, IMainView view, IProjectService projectService, IConfigService configService, LegendPresenter legendPresenter, ToolboxPresenter toolboxPresenter, IRepository repository) : base(view) { Logger.Current.Trace("Start MainPresenter"); if (view == null) { throw new ArgumentNullException("view"); } if (projectService == null) { throw new ArgumentNullException("projectService"); } if (configService == null) { throw new ArgumentNullException("configService"); } if (repository == null) { throw new ArgumentNullException("repository"); } // PM 2016-03-02 Added: if (legendPresenter == null) { throw new ArgumentNullException("legendPresenter"); } if (toolboxPresenter == null) { throw new ArgumentNullException("toolboxPresenter"); } _context = context; _projectService = projectService; _configService = configService; GlobalListeners.Attach(Logger.Current); view.Map.Lock(); try { var appContext = context as AppContext; if (appContext == null) { throw new InvalidCastException("Invalid type of IAppContext instance"); } appContext.Init(view, projectService, configService, legendPresenter, toolboxPresenter, repository); view.Map.Initialize(); view.Map.ApplyConfig(configService); view.ViewClosing += OnViewClosing; view.ViewUpdating += OnViewUpdating; view.BeforeShow += OnBeforeShow; var container = context.Container; _statusBarListener = container.GetSingleton <StatusBarListener>(); _menuGenerator = container.GetSingleton <MenuGenerator>(); _menuListener = container.GetSingleton <MenuListener>(); _mapListener = container.GetSingleton <MapListener>(); _mainPluginListener = container.GetSingleton <MainPluginListener>(); _legendListener = container.GetSingleton <LegendListener>(); _menuUpdater = new MenuUpdater(_context, PluginIdentity.Default); SplashView.Instance.ShowStatus("Loading plugins"); // must be called after docking is initialized: appContext.InitPlugins(configService, p => SplashView.Instance.ShowStatus($"Loading plugins: {p.Name}")); // this will display progress updates and debug window // file based-logger is already working Logger.Current.Init(appContext); } finally { view.Map.Unlock(); context.Legend.Unlock(); } View.AsForm.Shown += ViewShown; Logger.Current.Trace("End MainPresenter"); }