private void UpdateKnownWebLibrary(WebLibraryDetail new_web_library_detail, bool suppress_flush_to_disk = true, string extra_info_message_on_skip = "") { WebLibraryDetail old; if (web_library_details.TryGetValue(new_web_library_detail.Id, out old)) { bool use_old = true; bool use_new = true; // don't work with the old find if it has been purged if (old.IsPurged) { use_old = false; } // don't work with the new find if it has been purged if (new_web_library_detail.IsPurged) { use_new = false; } // don't work with the old find if it has been deleted and the new one has not: if (old.Deleted && !new_web_library_detail.Deleted && use_new) { use_old = false; } // and vice versa: if (!old.Deleted && new_web_library_detail.Deleted && use_old) { use_new = false; } // skip when there's nothing new to pick up: if (!use_new) { return; } // only do the mix/collision resolution when both old and new are viable: if (use_old) { int state = 0x00; // bit 0: prefer to use old, bit 1: prefer to use fresh, bit 2: used old, bit 3: used fresh, 0: don't know yet. // if there's already an entry present, see if we should 'upgrade' the info or stick with what we have: DateTime?dt = MixOldAndNew(old.LastServerSyncNotificationDate, new_web_library_detail.LastServerSyncNotificationDate, new_web_library_detail.Id + "::" + nameof(old.LastServerSyncNotificationDate), ref state); old.LastServerSyncNotificationDate = dt ?? DATE_ZERO; old.LastBundleManifestDownloadTimestampUTC = MixOldAndNew(old.LastBundleManifestDownloadTimestampUTC, new_web_library_detail.LastBundleManifestDownloadTimestampUTC, new_web_library_detail.Id + "::" + nameof(old.LastBundleManifestDownloadTimestampUTC), ref state); old.LastBundleManifestIgnoreVersion = MixOldAndNew(old.LastBundleManifestIgnoreVersion, new_web_library_detail.LastBundleManifestIgnoreVersion, new_web_library_detail.Id + "::" + nameof(old.LastBundleManifestIgnoreVersion), ref state); old.LastSynced = MixOldAndNew(old.LastSynced, new_web_library_detail.LastSynced, new_web_library_detail.Id + "::" + nameof(old.LastSynced), ref state); old.IntranetPath = MixOldAndNew(old.IntranetPath, new_web_library_detail.IntranetPath, new_web_library_detail.Id + "::" + nameof(old.IntranetPath), ref state, PathsMixCollisionComparer); old.ShortWebId = MixOldAndNew(old.ShortWebId, new_web_library_detail.ShortWebId, new_web_library_detail.Id + "::" + nameof(old.ShortWebId), ref state); old.FolderToWatch = MixOldAndNew(old.FolderToWatch, new_web_library_detail.FolderToWatch, new_web_library_detail.Id + "::" + nameof(old.FolderToWatch), ref state, PathsMixCollisionComparer); old.Title = MixOldAndNew(old.Title, new_web_library_detail.Title, new_web_library_detail.Id + "::" + nameof(old.Title), ref state); old.Description = MixOldAndNew(old.Description, new_web_library_detail.Description, new_web_library_detail.Id + "::" + nameof(old.Description), ref state); old.BundleManifestJSON = MixOldAndNew(old.BundleManifestJSON, new_web_library_detail.BundleManifestJSON, new_web_library_detail.Id + "::" + nameof(old.BundleManifestJSON), ref state); /* old.DescriptiveTitle = */ //MixOldAndNew(old.DescriptiveTitle, new_web_library_detail.DescriptiveTitle, new_web_library_detail.Id + "::" + nameof(old.DescriptiveTitle), ref state); MixOldAndNew(old.LibraryType(), new_web_library_detail.LibraryType(), new_web_library_detail.Id + "::" + nameof(old.LibraryType), ref state); old.Deleted = MixOldAndNew(old.Deleted, new_web_library_detail.Deleted, new_web_library_detail.Id + "::" + nameof(old.Deleted), ref state); old.AutoSync = MixOldAndNew(old.AutoSync, new_web_library_detail.AutoSync, new_web_library_detail.Id + "::" + nameof(old.AutoSync), ref state); old.IsAdministrator = MixOldAndNew(old.IsAdministrator, new_web_library_detail.IsAdministrator, new_web_library_detail.Id + "::" + nameof(old.IsAdministrator), ref state); /* old.IsBundleLibrary = */ MixOldAndNew(old.IsBundleLibrary, new_web_library_detail.IsBundleLibrary, new_web_library_detail.Id + "::" + nameof(old.IsBundleLibrary), ref state); /* old.IsIntranetLibrary = */ MixOldAndNew(old.IsIntranetLibrary, new_web_library_detail.IsIntranetLibrary, new_web_library_detail.Id + "::" + nameof(old.IsIntranetLibrary), ref state); /* old.IsWebLibrary = */ MixOldAndNew(old.IsWebLibrary, new_web_library_detail.IsWebLibrary, new_web_library_detail.Id + "::" + nameof(old.IsWebLibrary), ref state); old.IsLocalGuestLibrary = MixOldAndNew(old.IsLocalGuestLibrary, new_web_library_detail.IsLocalGuestLibrary, new_web_library_detail.Id + "::" + nameof(old.IsLocalGuestLibrary), ref state); old.IsReadOnly = MixOldAndNew(old.IsReadOnly, new_web_library_detail.IsReadOnly, new_web_library_detail.Id + "::" + nameof(old.IsReadOnly), ref state); // fixup: if (old.LibraryType() != "UNKNOWN" && old.IsReadOnly) { // reset ReadOnly for everyone who is ex-Premium(Plus) for all their known libraries. old.IsReadOnly = false; } old.library?.Dispose(); old.library = new_web_library_detail.library; if ((state & 0x0c) == 0x0c) { Logging.Warn("library info has been mixed as part of collision resolution for library {0}.", old.Id); } else if ((state & 0x04) == 0x04) { Logging.Info("library info has been kept as-is as part of collision resolution for library {0}.", old.Id); } if ((state & 0x08) == 0x08) { Logging.Warn("library info has been picked up from the new entry as part of collision resolution for library {0}.", old.Id); } new_web_library_detail = old; } } if (null == new_web_library_detail.library) { new_web_library_detail.library = new Library(new_web_library_detail); } web_library_details[new_web_library_detail.Id] = new_web_library_detail; if (!suppress_flush_to_disk) { SaveKnownWebLibraries(); FireWebLibrariesChanged(); } }
internal void ForgetKnownWebLibraryFromIntranet(WebLibraryDetail web_library_detail) { Logging.Info("+Forgetting {1} Library from {0}", web_library_detail.Title, web_library_detail.LibraryType()); if (MessageBoxes.AskQuestion("Are you sure you want to forget the {1} Library '{0}'?", web_library_detail.Title, web_library_detail.LibraryType())) { web_library_details.Remove(web_library_detail.Id); SaveKnownWebLibraries(); FireWebLibrariesChanged(); } Logging.Info("-Forgetting {1} Library from {0}", web_library_detail.Title, web_library_detail.LibraryType()); }
private void UpdateKnownWebLibrary(WebLibraryDetail new_web_library_detail, bool suppress_flush_to_disk = true, string extra_info_message_on_skip = "") { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); WebLibraryDetail old; if (web_library_details.TryGetValue(new_web_library_detail.Id, out old)) { bool use_old = true; bool use_new = true; // don't work with the old find if it has been purged if (old.IsPurged) { use_old = false; } // don't work with the new find if it has been purged if (new_web_library_detail.IsPurged) { use_new = false; } // don't work with the old find if it has been deleted and the new one has not: if (old.Deleted && !new_web_library_detail.Deleted && use_new) { use_old = false; } // and vice versa: if (!old.Deleted && new_web_library_detail.Deleted && use_old) { use_new = false; } // skip when there's nothing new to pick up: if (!use_new) { return; } // only do the mix/collision resolution when both old and new are viable: if (use_old) { int state = 0x00; // bit 0: prefer to use old, bit 1: prefer to use fresh, bit 2: used old, bit 3: used fresh, 0: don't know yet. // if there's already an entry present, see if we should 'upgrade' the info or stick with what we have: old.LastBundleManifestDownloadTimestampUTC = MixOldAndNew(old.LastBundleManifestDownloadTimestampUTC, new_web_library_detail.LastBundleManifestDownloadTimestampUTC, new_web_library_detail.Id + "::" + nameof(old.LastBundleManifestDownloadTimestampUTC), ref state); old.LastBundleManifestIgnoreVersion = MixOldAndNew(old.LastBundleManifestIgnoreVersion, new_web_library_detail.LastBundleManifestIgnoreVersion, new_web_library_detail.Id + "::" + nameof(old.LastBundleManifestIgnoreVersion), ref state); old.LastSynced = MixOldAndNew(old.LastSynced, new_web_library_detail.LastSynced, new_web_library_detail.Id + "::" + nameof(old.LastSynced), ref state); old.IntranetPath = MixOldAndNew(old.IntranetPath, new_web_library_detail.IntranetPath, new_web_library_detail.Id + "::" + nameof(old.IntranetPath), ref state, PathsMixCollisionComparer); old.FolderToWatch = MixOldAndNew(old.FolderToWatch, new_web_library_detail.FolderToWatch, new_web_library_detail.Id + "::" + nameof(old.FolderToWatch), ref state, PathsMixCollisionComparer); old.Title = MixOldAndNew(old.Title, new_web_library_detail.Title, new_web_library_detail.Id + "::" + nameof(old.Title), ref state); old.Description = MixOldAndNew(old.Description, new_web_library_detail.Description, new_web_library_detail.Id + "::" + nameof(old.Description), ref state); old.BundleManifestJSON = MixOldAndNew(old.BundleManifestJSON, new_web_library_detail.BundleManifestJSON, new_web_library_detail.Id + "::" + nameof(old.BundleManifestJSON), ref state); /* old.DescriptiveTitle = */ //MixOldAndNew(old.DescriptiveTitle, new_web_library_detail.DescriptiveTitle, new_web_library_detail.Id + "::" + nameof(old.DescriptiveTitle), ref state); MixOldAndNew(old.LibraryType(), new_web_library_detail.LibraryType(), new_web_library_detail.Id + "::" + nameof(old.LibraryType), ref state); old.Deleted = MixOldAndNew(old.Deleted, new_web_library_detail.Deleted, new_web_library_detail.Id + "::" + nameof(old.Deleted), ref state); old.AutoSync = MixOldAndNew(old.AutoSync, new_web_library_detail.AutoSync, new_web_library_detail.Id + "::" + nameof(old.AutoSync), ref state); /* old.IsBundleLibrary = */ MixOldAndNew(old.IsBundleLibrary, new_web_library_detail.IsBundleLibrary, new_web_library_detail.Id + "::" + nameof(old.IsBundleLibrary), ref state); /* old.IsIntranetLibrary = */ MixOldAndNew(old.IsIntranetLibrary, new_web_library_detail.IsIntranetLibrary, new_web_library_detail.Id + "::" + nameof(old.IsIntranetLibrary), ref state); /* old.IsWebLibrary = */ ASSERT.Test(old.Xlibrary != null ? new_web_library_detail.Xlibrary == null : true); #if false // this code is not needed in the current use of the API as long as the ASSERTions above hold old.library?.Dispose(); if (new_web_library_detail.library != null) { old.library = new_web_library_detail.library; } // and update it's internal (cyclic) web_library_detail reference: if (old.library != null) { old.library.WebLibraryDetail = old; } #endif if ((state & 0x0c) == 0x0c) { Logging.Warn("library info has been mixed as part of collision resolution for library {0}.", old.Id); } else if ((state & 0x04) == 0x04) { Logging.Info("library info has been kept as-is as part of collision resolution for library {0}.", old.Id); } if ((state & 0x08) == 0x08) { Logging.Warn("library info has been picked up from the new entry as part of collision resolution for library {0}.", old.Id); } new_web_library_detail = old; } } //ASSERT.Test(new_web_library_detail.Xlibrary == null); web_library_details[new_web_library_detail.Id] = new_web_library_detail; if (!suppress_flush_to_disk) { SaveKnownWebLibraries(); StatusManager.Instance.ClearStatus("LibraryInitialLoad"); FireWebLibrariesChanged(); } }