Пример #1
0
        private bool EnsureIntranetLibraryExists(string db_base_path, string db_title, string db_description)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                string base_path = db_base_path;

                if (!Directory.Exists(base_path))
                {
                    DirectoryTools.CreateDirectory(base_path);
                }

                EnsureWarningFilesArePresent(base_path);

                // If the file exists, check that we don't need to update its details
                string library_detail_path = IntranetLibraryTools.GetLibraryDetailPath(base_path);
                if (File.Exists(library_detail_path))
                {
                    try
                    {
                        IntranetLibraryDetail library_detail = IntranetLibraryDetail.Read(library_detail_path);
                        if (library_detail.Title != db_title || library_detail.Description != db_description)
                        {
                            library_detail.Title       = db_title;
                            library_detail.Description = db_description;
                            IntranetLibraryDetail.Write(library_detail_path, library_detail);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Error(ex, "There was an error while updating an Intranet Library path, so will try to delete and recreate... (path: {0})", base_path);
                        FileTools.Delete(library_detail_path);
                    }
                }

                // If the file does not exist, create it from scratch
                if (!File.Exists(library_detail_path))
                {
                    IntranetLibraryDetail library_detail = new IntranetLibraryDetail();
                    library_detail.Id          = IntranetLibraryDetail.GetRandomId();
                    library_detail.Title       = db_title;
                    library_detail.Description = db_description;
                    IntranetLibraryDetail.Write(library_detail_path, library_detail);
                }

                // If the sync database does not exist, put one in place.
                IntranetLibraryDB db = new IntranetLibraryDB(base_path);

                // Notify the WebLibraryManager
                WebLibraryManager.Instance.UpdateKnownWebLibraryFromIntranet(base_path, suppress_flush_to_disk: false, extra_info_message_on_skip: String.Format("as specified in file {0}", library_detail_path));

                // make sure the PDF/documents database is loaded into memory:
                WebLibraryManager.Instance.InitAllLoadedLibraries();

                return(true);
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Problem accessing Intranet Library for the first time.");

                MessageBoxes.Error("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);

                return(false);
            }
        }
        public static void EnsureIntranetLibraryExists(string db_base_path, string db_title, string db_description, string id = null)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                string base_path = db_base_path;

                if (!Directory.Exists(base_path))
                {
                    DirectoryTools.CreateDirectory(base_path);
                }

                EnsureWarningFilesArePresent(base_path);

                // If the file exists, check that we don't need to update its details
                string library_detail_path = IntranetLibraryTools.GetLibraryDetailPath(base_path);
                if (File.Exists(library_detail_path))
                {
                    try
                    {
                        IntranetLibraryDetail library_detail = IntranetLibraryDetail.Read(library_detail_path);
                        if (library_detail.Title != db_title || library_detail.Description != db_description)
                        {
                            library_detail.Title       = db_title;
                            library_detail.Description = db_description;
                            IntranetLibraryDetail.Write(library_detail_path, library_detail);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Error(ex, "There was an error while updating an Intranet Library path, so will try to delete and recreate... (path: {0})", base_path);
                        FileTools.Delete(library_detail_path);
                    }
                }

                // If the file does not exist, create it from scratch
                if (!File.Exists(library_detail_path))
                {
                    IntranetLibraryDetail library_detail = new IntranetLibraryDetail();
                    library_detail.Id          = String.IsNullOrEmpty(id) ? IntranetLibraryDetail.GetRandomId() : id;
                    library_detail.Title       = db_title;
                    library_detail.Description = db_description;
                    IntranetLibraryDetail.Write(library_detail_path, library_detail);
                }

                // If the sync database does not exist, put one in place.
                IntranetLibraryDB db = new IntranetLibraryDB(base_path);

                // Notify the WebLibraryManager
                WebLibraryManager.Instance.UpdateKnownWebLibraryFromIntranet(base_path, suppress_flush_to_disk: false, extra_info_message_on_skip: String.Format("as specified in file {0}", library_detail_path));

                // make sure the PDF/documents database is loaded into memory:
                WebLibraryManager.Instance.InitAllLoadedLibraries();
            }
            catch (Exception ex)
            {
                Logging.Error(ex, $"Problem accessing Intranet Library for the first time. (Id: {id}, path: '{db_base_path}', DB title: '{db_title}', Description: '{db_description}'");

                throw;
            }
        }
Пример #3
0
        private bool EnsureIntranetLibraryExists()
        {
            try
            {
                string base_path = TxtPath.Text;
                if (!Directory.Exists(base_path))
                {
                    DirectoryTools.CreateDirectory(base_path);
                }

                EnsureWarningFilesArePresent(base_path);

                // If the file exists, check that we don't need to update it's details
                string library_detail_path = IntranetLibraryTools.GetLibraryDetailPath(base_path);
                if (File.Exists(library_detail_path))
                {
                    try
                    {
                        IntranetLibraryDetail library_detail = IntranetLibraryDetail.Read(library_detail_path);
                        if (library_detail.Title != TxtTitle.Text || library_detail.Description != TxtDescription.Text)
                        {
                            library_detail.Title       = TxtTitle.Text;
                            library_detail.Description = TxtDescription.Text;
                            IntranetLibraryDetail.Write(library_detail_path, library_detail);
                        }
                    }

                    catch (Exception ex)
                    {
                        Logging.Error(ex, "There was an error while updating an Intranet Library path, so will try to delete and recreate...");
                        FileTools.Delete(library_detail_path);
                    }
                }

                // If the file does not exists, create it from scratch
                if (!File.Exists(library_detail_path))
                {
                    IntranetLibraryDetail library_detail = new IntranetLibraryDetail();
                    library_detail.Id          = IntranetLibraryDetail.GetRandomId();
                    library_detail.Title       = TxtTitle.Text;
                    library_detail.Description = TxtDescription.Text;
                    IntranetLibraryDetail.Write(library_detail_path, library_detail);
                }

                // If the sync database does not exist, put one in place.
                IntranetLibraryDB db = new IntranetLibraryDB(base_path);

                // Notify the WebLibrearyManager
                WebLibraryManager.Instance.UpdateKnownWebLibraryFromIntranet(base_path);

                return(true);
            }

            catch (Exception ex)
            {
                Logging.Error(ex, "Problem accessing Intranet Library for the first time.");
                MessageBoxes.Error("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);

                return(false);
            }
        }