Esempio n. 1
0
        private void ValidateFolder()
        {
            string base_path = "???";

            try
            {
                ButtonJoinCreate.Caption = "Create";

                base_path = TxtPath.Text;
                if (Directory.Exists(base_path))
                {
                    string library_detail_path = IntranetLibraryTools.GetLibraryDetailPath(base_path);
                    if (File.Exists(library_detail_path))
                    {
                        IntranetLibraryDetail library_detail = IntranetLibraryDetail.Read(library_detail_path);
                        TxtTitle.Text            = library_detail.Title;
                        TxtDescription.Text      = library_detail.Description;
                        ButtonJoinCreate.Caption = "Join";
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "There was an exception while validating the selected Intranet Library path {0}.", base_path);
            }
        }
        public IntranetLibraryDB(string base_path)
        {
            this.base_path = base_path;
            library_path   = IntranetLibraryTools.GetLibraryMetadataPath(base_path);

            // Copy a library into place...
            if (!File.Exists(library_path))
            {
                Logging.Warn("Intranet Library metadata db does not exist so copying the template to {0}", library_path);
                string library_metadata_template_path = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.StartupDirectoryForQiqqa, @"DocumentLibrary/IntranetLibraryStuff/IntranetLibrary.Metadata.Template.s3db"));
                if (!File.Exists(library_metadata_template_path))
                {
                    throw new Exception($"Sync template file '{library_metadata_template_path}' does not exist!");
                }
                string basedir = Path.GetDirectoryName(library_path);
                if (!Directory.Exists(basedir))
                {
                    throw new Exception($"Sync target directory '{basedir}' for Qiqqa database '{library_path}' does not exist!");
                }
                try
                {
                    File.Copy(library_metadata_template_path, library_path);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error 0x{2:08X}: Failed to write the sync template '{0}' to sync target directory '{1}'", library_metadata_template_path, basedir, ex.HResult);
                    throw;
                }
            }
        }
Esempio n. 3
0
        public IntranetLibraryDB(string base_path)
        {
            this.base_path    = base_path;
            this.library_path = IntranetLibraryTools.GetLibraryMetadataPath(base_path);

            // Copy a library into place...
            if (!File.Exists(library_path))
            {
                Logging.Warn("Intranet Library metadata db does not exist so copying the template to {0}", library_path);
                string library_metadata_template_path = ConfigurationManager.Instance.StartupDirectoryForQiqqa + @"DocumentLibrary\IntranetLibraryStuff\IntranetLibrary.Metadata.Template.s3db";
                File.Copy(library_metadata_template_path, library_path);
            }
        }
        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;
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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);
            }
        }