示例#1
0
        private void Sync_BACKGROUND(SyncControlGridItem sync_control_grid_item)
        {
            StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(sync_control_grid_item.library_sync_detail.web_library_detail), String.Format("Starting sync of {0}", sync_control_grid_item.LibraryTitle));

            var  sd            = sync_control_grid_item.library_sync_detail;
            bool done_anything = false;

            try
            {
                IntranetLibraryDetail.EnsureIntranetLibraryExists(sync_control_grid_item.library_sync_detail.web_library_detail);

                if (sync_control_grid_item.SyncLibrary)
                {
                    if (sd.sync_decision.can_sync)
                    {
                        Logging.Info("Syncing metadata for {0}", sd.web_library_detail.Title);
                        SynchronizeMetadata_INTERNAL_BACKGROUND(sd.web_library_detail, sync_control_grid_item.IsReadOnly);
                        SynchronizeDocuments_Upload_INTERNAL_BACKGROUND(sd.web_library_detail, sd.web_library_detail.Xlibrary.PDFDocuments, sync_control_grid_item.IsReadOnly);
                        Logging.Info("Downloading documents for {0}", sd.web_library_detail.Title);
                        SynchronizeDocuments_Download_INTERNAL_BACKGROUND(sd.web_library_detail, sd.web_library_detail.Xlibrary.PDFDocuments, sync_control_grid_item.IsReadOnly);
                        done_anything = true;
                    }
                    else
                    {
                        Logging.Info("Not synchronizing metadata or documents for {0}", sd.web_library_detail.Title);
                    }
                }

                // Indicate that we have synced
                if (done_anything)
                {
                    var now = DateTime.UtcNow;

                    sd.web_library_detail.LastSynced = now;

                    string syncfilepath = HistoricalSyncFile.GetSyncDbFilename(sd.web_library_detail);
                    File.SetCreationTimeUtc(syncfilepath, now);
                    File.SetLastWriteTimeUtc(syncfilepath, now);
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem while trying to connect to this Intranet Library?  Are you sure you have permission to access this folder?  Your Network or System Administrator can grant you this permission.\n\nThe detailed error message is:\n" + ex.Message);
            }
            finally
            {
                sd.web_library_detail.Xlibrary.sync_in_progress = false;

                WebLibraryManager.Instance.NotifyOfChangeToWebLibraryDetail();
            }

            StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(sd.web_library_detail), String.Format("Finished sync of {0}", sync_control_grid_item.LibraryTitle));
        }
        public void UpdateKnownWebLibraryFromIntranet(string intranet_path)
        {
            Logging.Info("+Updating known Intranet Library from " + intranet_path);

            IntranetLibraryDetail intranet_library_detail = IntranetLibraryDetail.Read(IntranetLibraryTools.GetLibraryDetailPath(intranet_path));

            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

            new_web_library_detail.IntranetPath = intranet_path;
            new_web_library_detail.Id           = intranet_library_detail.Id;
            new_web_library_detail.Title        = intranet_library_detail.Title;
            new_web_library_detail.Description  = intranet_library_detail.Description;
            new_web_library_detail.IsReadOnly   = false;
            new_web_library_detail.Deleted      = false;

            UpdateKnownWebLibrary(new_web_library_detail);

            Logging.Info("-Updating known Intranet Library from " + intranet_path);
        }
        public void UpdateKnownWebLibraryFromIntranet(string intranet_path, bool suppress_flush_to_disk = true, string extra_info_message_on_skip = "")
        {
            Logging.Info("+Updating known Intranet Library from {0}", intranet_path);

            IntranetLibraryDetail intranet_library_detail = IntranetLibraryDetail.Read(IntranetLibraryTools.GetLibraryDetailPath(intranet_path));

            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

            new_web_library_detail.IntranetPath = intranet_path;
            //new_web_library_detail.IsIntranetLibrary = true;
            new_web_library_detail.Id          = intranet_library_detail.Id;
            new_web_library_detail.Title       = intranet_library_detail.Title;
            new_web_library_detail.Description = intranet_library_detail.Description;
            new_web_library_detail.IsReadOnly  = false;
            new_web_library_detail.Deleted     = false;

            UpdateKnownWebLibrary(new_web_library_detail, suppress_flush_to_disk, extra_info_message_on_skip);

            Logging.Info("-Updating known Intranet Library from {0}", intranet_path);
        }
        public void UpdateKnownWebLibraryFromIntranet(string intranet_path, bool suppress_flush_to_disk = true, string extra_info_message_on_skip = "")
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            Logging.Info("+Updating known Intranet Library from {0}", intranet_path);

            IntranetLibraryDetail intranet_library_detail = IntranetLibraryDetail.Read(IntranetLibraryTools.GetLibraryDetailPath(intranet_path));

            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

            new_web_library_detail.IntranetPath = intranet_path;
            new_web_library_detail.Id           = intranet_library_detail.Id;
            new_web_library_detail.Title        = intranet_library_detail.Title;
            new_web_library_detail.Description  = intranet_library_detail.Description;
            new_web_library_detail.Deleted      = false;

            UpdateKnownWebLibrary(new_web_library_detail, suppress_flush_to_disk, extra_info_message_on_skip);

            Logging.Info("-Updating known Intranet Library from {0}", intranet_path);
        }
        // *************************************************************************************************************
        // *** MIGRATION TO OPEN SOURCE CODE ***************************************************************************
        // *************************************************************************************************************
        private void AddLegacyWebLibrariesThatCanBeFoundOnDisk()
        {
            /**
             * Plan:
             * Iterate through all the folders in the Qiqqa data directory
             * If a folder contains a valid Library record and it is a WEB library, then add it to our list with the word '[LEGACY]' in front of it
             */

            string base_directory_path = UpgradePaths.V037To038.SQLiteUpgrade.BaseDirectoryForQiqqa;

            Logging.Info("Going to scan for web libraries at: {0}", base_directory_path);
            if (Directory.Exists(base_directory_path))
            {
                string[] library_directories = Directory.GetDirectories(base_directory_path);
                foreach (string library_directory in library_directories)
                {
                    Logging.Info("Inspecting directory {0} - Phase 1 : Web & Known Libraries", library_directory);

                    string databaselist_file = Path.GetFullPath(Path.Combine(library_directory, @"Qiqqa.known_web_libraries"));
                    if (File.Exists(databaselist_file))
                    {
                        LoadKnownWebLibraries(databaselist_file, true);
                    }
                }

                foreach (string library_directory in library_directories)
                {
                    Logging.Info("Inspecting directory {0} - Phase 2 : Intranet Libraries", library_directory);

                    string databaselist_file = IntranetLibraryTools.GetLibraryDetailPath(library_directory);
                    if (File.Exists(databaselist_file))
                    {
                        IntranetLibraryDetail intranet_library_detail = IntranetLibraryDetail.Read(databaselist_file);

                        UpdateKnownWebLibraryFromIntranet(library_directory, extra_info_message_on_skip: String.Format(" as obtained from file {0}", databaselist_file));
                    }
                }

                foreach (string library_directory in library_directories)
                {
                    Logging.Info("Inspecting directory {0} - Phase 3 : Bundles", library_directory);

                    // must be a qiqqa_bundle and/or qiqqa_bundle_manifest file set
                    Logging.Warn("Auto bundle import at startup is not yet suppoerted.");
                }

                foreach (string library_directory in library_directories)
                {
                    Logging.Info("Inspecting directory {0} - Phase 4 :  Local and Legacy Libraries", library_directory);

                    string database_file = Path.GetFullPath(Path.Combine(library_directory, @"Qiqqa.library"));
                    if (File.Exists(database_file))
                    {
                        var library_id = Path.GetFileName(library_directory);

                        WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

                        new_web_library_detail.Id         = library_id;
                        new_web_library_detail.Title      = "Legacy Web Library - " + new_web_library_detail.Id;
                        new_web_library_detail.IsReadOnly = false;
                        // library: UNKNOWN type

                        UpdateKnownWebLibrary(new_web_library_detail);
                    }
                }
            }
        }
示例#6
0
        // *************************************************************************************************************
        // *** MIGRATION TO OPEN SOURCE CODE ***************************************************************************
        // *************************************************************************************************************
        private void AddLegacyWebLibrariesThatCanBeFoundOnDisk()
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                ConfigurationManager.ThrowWhenActionIsNotEnabled(nameof(AddLegacyWebLibrariesThatCanBeFoundOnDisk));

                /**
                 * Plan:
                 * - Iterate through all the folders in the Qiqqa data directory.
                 * - If a folder contains a valid Library record and it is a WEB library,
                 *   then add it to our list with the word '[LEGACY]' in front of it.
                 */

                string base_directory_path = UpgradePaths.V037To038.SQLiteUpgrade.BaseDirectoryForQiqqa;
                Logging.Info("Going to scan for web libraries at: {0}", base_directory_path);
                if (Directory.Exists(base_directory_path))
                {
                    string[] library_directories = Directory.GetDirectories(base_directory_path);
                    foreach (string library_directory in library_directories)
                    {
                        Logging.Info("Inspecting directory {0} - Phase 1 : Web & Known Libraries", library_directory);

                        string databaselist_file = Path.GetFullPath(Path.Combine(library_directory, @"Qiqqa.known_web_libraries"));
                        if (File.Exists(databaselist_file))
                        {
                            LoadKnownWebLibraries(databaselist_file, only_load_those_libraries_which_are_actually_present: true);
                        }
                    }

                    foreach (string library_directory in library_directories)
                    {
                        Logging.Info("Inspecting directory {0} - Phase 2 : Intranet Libraries", library_directory);

                        string databaselist_file = IntranetLibraryTools.GetLibraryDetailPath(library_directory);
                        if (File.Exists(databaselist_file))
                        {
                            IntranetLibraryDetail intranet_library_detail = IntranetLibraryDetail.Read(databaselist_file);

                            UpdateKnownWebLibraryFromIntranet(library_directory, extra_info_message_on_skip: String.Format(" as obtained from file {0}", databaselist_file));
                        }
                    }

                    foreach (string library_directory in library_directories)
                    {
                        Logging.Info("Inspecting directory {0} - Phase 3 : Bundles", library_directory);

                        // must be a qiqqa_bundle and/or qiqqa_bundle_manifest file set
                        Logging.Warn("Auto bundle import at startup is not yet supported.");
                    }

                    foreach (string library_directory in library_directories)
                    {
                        Logging.Info("Inspecting directory {0} - Phase 4 : Local and Legacy Libraries", library_directory);

                        string database_file   = LibraryDB.GetLibraryDBPath(library_directory);
                        string db_syncref_path = IntranetLibraryTools.GetLibraryMetadataPath(library_directory);

                        // add/update only if this is not a Internet sync directory/DB!
                        if (File.Exists(db_syncref_path))
                        {
                            Logging.Info("Skip the Qiqqa Internet/Intranet Sync directory and the sync DB contained therein: '{0}'", db_syncref_path);

                            // https://github.com/jimmejardine/qiqqa-open-source/issues/145 :: delete lib file when it is very small and was illegally
                            // constructed by a previous v82beta Qiqqa release:
                            if (File.Exists(database_file))
                            {
                                long s3length = File.GetSize(database_file);
                                if (6 * 1024 > s3length)
                                {
                                    Logging.Warn("DELETE the wrongfully created DB file '{0}' in the Qiqqa Internet/Intranet Sync directory and the sync DB contained therein: '{1}', which has precedence!", database_file, db_syncref_path);

                                    FileTools.DeleteToRecycleBin(database_file);
                                }
                                else
                                {
                                    Logging.Error("Inspect the Library DB file '{0}' in the Qiqqa Internet/Intranet Sync directory and the sync DB contained therein: '{1}', which MAY have precedence. Delete one of these manually to clean up your system as Qiqqa heuristics cannot tell which is the prevalent metadata database here!", database_file, db_syncref_path);
                                }
                            }

                            continue;
                        }
                        if (File.Exists(database_file))
                        {
                            var library_id = Path.GetFileName(library_directory);

                            WebLibraryDetail new_web_library_detail = new WebLibraryDetail();

                            new_web_library_detail.Id         = library_id;
                            new_web_library_detail.Title      = "Legacy Web Library - " + new_web_library_detail.Id;
                            new_web_library_detail.IsReadOnly = false;
                            // library: UNKNOWN type

                            UpdateKnownWebLibrary(new_web_library_detail);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem while scanning for (legacy) libraries.");
            }
        }