/// <summary> /// Initialize our ViewModel /// </summary> /// <returns> /// The <see cref="IDisposable" />. /// </returns> private IDisposable InitViewModel() { // init command objects this.InitCommands(); // init collection that contains our own shareable windows; content is created by refresh Task afterwards this.ShareableWindows = new SourceCache<ShareableWindow, IntPtr>(w => w.Handle); // get favorites and init list of RemoteHosts var favService = new FavoritesService(); var favs = favService.GetFavorites(); this.RemoteHosts = new ReactiveList<RemoteHost>(favs.Select(x => this.CreateRemoteHost(x.Name, x.Ip))); // start refresh timer for collecting shareable windows var timer = DispatcherScheduler.Current.SchedulePeriodic(TimeSpan.FromSeconds(1), this.RefreshShareableWindows); return new CompositeDisposable(timer, this.ShareableWindows); }
/// <summary> /// persist favorites when application is shutdown /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Current_Exit(object sender, ExitEventArgs e) { var favService = new FavoritesService(); if (this.RemoteHosts != null) favService.UpdateFavorites(this.RemoteHosts.Select(x => new Favorite() { Ip = x.IpAddress, Name = x.Name })); }