/// <summary> /// Removes given instance from history /// </summary> /// <param name="instance">Instance</param> public virtual void ForgetInstance(Instance instance) { // Reset connecting instance. if (ConnectingInstance != null && ConnectingInstance.Equals(instance)) { ConnectingInstance = ConnectingInstanceList.FirstOrDefault(); } instance.Forget(); }
/// <summary> /// Removes given instance from history /// </summary> /// <param name="instance">Instance</param> public virtual void ForgetInstance(Instance instance) { // Remove the instance from history. ConnectingInstanceList.Remove(instance); // Reset connecting instance. if (ConnectingInstance != null && ConnectingInstance.Equals(instance)) { ConnectingInstance = ConnectingInstanceList.FirstOrDefault(); } }
/// <summary> /// Select connecting instance by URI /// </summary> /// <remarks>When the instance with given URI is no longer available, this method returns the most popular instance from the <see cref="ConnectingInstanceList"/> list.</remarks> /// <param name="uri">Preferred instance URI</param> /// <returns>Connecting instance</returns> public Instance SelectConnectingInstance(Uri uri) { if (uri == null) { return(null); } // Find the connecting instance by URI. var instance = ConnectingInstanceList.FirstOrDefault(inst => inst.Base.AbsoluteUri == uri.AbsoluteUri); if (instance != null) { return(instance); } // The last connecting instance is no longer available. Select the most popular one among the remaining ones. return(ConnectingInstanceList.Count > 0 ? ConnectingInstanceList.Aggregate((most_popular_instance, inst) => (most_popular_instance == null || inst.Popularity > most_popular_instance.Popularity ? inst : most_popular_instance)) : null); }
/// <inheritdoc/> public override void FromSettings(ConnectWizard wizard, Xml.InstanceSourceSettingsBase settings) { if (settings is Xml.LocalInstanceSourceSettings h_local) { // - Restore instance list. // - Restore connecting instance (optional). foreach (var h_instance in h_local.ConnectingInstanceList) { var connecting_instance = InstanceList.FirstOrDefault(inst => inst.Base.AbsoluteUri == h_instance.Base.AbsoluteUri); if (connecting_instance == null) { // The connecting instance was not found. Could be user entered, or removed from discovery file. connecting_instance = new Instance(h_instance.Base); connecting_instance.RequestAuthorization += wizard.Instance_RequestAuthorization; connecting_instance.ForgetAuthorization += wizard.Instance_ForgetAuthorization; } connecting_instance.Popularity = h_instance.Popularity; // Restore connecting profiles (optionally). ObservableCollection <Profile> profile_list = null; try { switch (Properties.Settings.Default.ConnectingProfileSelectMode) { case 0: case 2: // This might trigger OAuth. profile_list = connecting_instance.GetProfileList(connecting_instance, Window.Abort.Token); break; } } catch (OperationCanceledException) { throw; } catch { // When profile list could not be obtained from the instance, instance settings should be forgotten to avoid issues next time. connecting_instance.Forget(); continue; } switch (Properties.Settings.Default.ConnectingProfileSelectMode) { case 0: { // Restore only profiles user connected to before. foreach (var h_profile in h_instance.ProfileList) { var profile = profile_list.FirstOrDefault(prof => prof.ID == h_profile.ID); if (profile != null) { // Synchronise profile data. h_profile.DisplayName = profile.DisplayName; profile.Popularity = h_profile.Popularity; } else { // The profile is gone missing. Create an unavailable profile placeholder. profile = new Profile { Instance = connecting_instance, ID = h_profile.ID, DisplayName = h_profile.DisplayName, Popularity = h_profile.Popularity }; profile.RequestAuthorization += (object sender_profile, RequestAuthorizationEventArgs e_profile) => connecting_instance.OnRequestAuthorization(connecting_instance, e_profile); } // Add to the list of connecting profiles. if (ConnectingProfileList.FirstOrDefault(prof => prof.Equals(profile)) == null) { ConnectingProfileList.Add(profile); } } } break; case 2: { // Add all available profiles to the connecting profile list. // Restore popularity on the fly (or leave default to promote newly discovered profiles). foreach (var profile in profile_list) { var h_profile = h_instance.ProfileList.FirstOrDefault(prof => prof.ID == profile.ID); if (h_profile != null) { profile.Popularity = h_profile.Popularity; } ConnectingProfileList.Add(profile); } } break; } var instance = ConnectingInstanceList.FirstOrDefault(inst => inst.Base.AbsoluteUri == connecting_instance.Base.AbsoluteUri); if (instance == null) { ConnectingInstanceList.Add(connecting_instance); } } ConnectingInstance = SelectConnectingInstance(h_local.ConnectingInstance); } }