public FavoritesShowManager(IFavoritesService favoritesService, IAnalyticsService analyticsService) { _favoritesService = favoritesService; _analyticsService = analyticsService; _favorites = _favoritesService.LoadFavorites(); _favoritesService.FavoritesUpdated += (s, e) => { _favorites = _favoritesService.LoadFavorites(); if (FavoritesUpdated != null) { FavoritesUpdated(this, EventArgs.Empty); } }; }
private void LoadFavoritesDocument(NSMetadataQuery query) { if (query.ResultCount == 1) { var item = (NSMetadataItem)query.ResultAtIndex(0); var url = (NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey); _document = new FavoritesDocument(url); _document.Open(success => { if (success && _document.Data != null) { var favorites = _favoritesService.LoadFavorites(); if (favorites.LastUpdated < _document.Data.LastUpdated) { _favoritesService.SaveFavorites(_document.Data); } } }); } else if (query.ResultCount == 0) { SaveFavoritesDocument(); } }
protected override void AddServices() { base.AddServices(); RootWorkItem.Services.Add <IUserSessionService>(_userSessionService); if (_userSessionService.ActivationUri != null) { ShellHyperlink hyperlink = HyperlinkService.ConvertToShellHyperlink(_userSessionService.ActivationUri); if (hyperlink.Data.ContainsKey("ModuleId")) { //Add shellhyperlink to workitem to prevent dialogs being lodad before the module is fully loaded. See NavigationBarView.xaml.cs function NavigationBarSelectionChangedEventHandler //Hyperlink is removed from workitem in HyperlinkService.cs function ExecuteHyperlink(ShellHyperlink hyperlink) RootWorkItem.Items.Add(hyperlink); } } if (string.IsNullOrEmpty(_userSessionService.DomainUser)) { _userSessionService.UserId = string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName); } else { _userSessionService.Password = _password; } RootWorkItem.Items.Add(_tokenCache); IChannelFactoryService factoryService = ServiceActivator.CreateInstance <IChannelFactoryService>(_userSessionService, _tokenCache); RootWorkItem.Services.Add <IChannelFactoryService>(factoryService); IAuthorizationService authorizationService = ServiceActivator.CreateInstance <IAuthorizationService>(); RootWorkItem.Services.Add <IAuthorizationService>(authorizationService); IFavoritesService favoritesService = RootWorkItem.Services.AddNew <FavoritesService, IFavoritesService>(); RootWorkItem.Services.AddNew <ShellModuleService, IShellModuleService>(); RootWorkItem.Services.AddNew <FileService, IFileService>(); _settingsService = ServiceActivator.CreateInstance <IUXSettingsService>(ContainerName); RootWorkItem.Services.Add <IUXSettingsService>(_settingsService); RootWorkItem.Services.AddNew <HyperlinkService, IHyperlinkService>(); ThreadPool.QueueUserWorkItem((e) => { try { _settingsService.LoadSettings(); favoritesService.LoadFavorites(); } catch (Exception) { } _settingsLoadedEvent.Set(); }); }