示例#1
0
        internal static void DaemonPut(Library library, string fingerprint)
        {
            string filename_full  = PDFDocumentFileLocations.DocumentPath(library, fingerprint, "pdf");
            string filename_short = Path.GetFileName(filename_full);
            string pdf_path       = IntranetLibraryTools.GetLibraryPDFPath(library.WebLibraryDetail.IntranetPath, filename_short);

            DirectoryTools.CreateDirectory(Path.GetDirectoryName(pdf_path));

            Logging.Info("+Copying up {0}", fingerprint);
            File.Copy(filename_full, pdf_path);
            Logging.Info("-Copying up {0}", fingerprint);
        }
示例#2
0
        internal static void DaemonGet(Library library, string fingerprint)
        {
            string filename_full  = PDFDocumentFileLocations.DocumentPath(library, fingerprint, "pdf");
            string filename_short = Path.GetFileName(filename_full);
            string pdf_path       = IntranetLibraryTools.GetLibraryPDFPath(library.WebLibraryDetail.IntranetPath, filename_short);

            DirectoryTools.CreateDirectory(Path.GetDirectoryName(filename_full));

            Logging.Info("+Copying down {0}", fingerprint);
            File.Copy(pdf_path, filename_full);
            Logging.Info("-Copying down {0}", fingerprint);

            // Write the audit
            if (true)
            {
                string audit_filename  = IntranetLibraryTools.GetLibraryAuditFilename(library.WebLibraryDetail.IntranetPath);
                string audit_directory = Path.GetDirectoryName(audit_filename);

                if (Directory.Exists(audit_directory))
                {
                    string audit_data = String.Format(
                        "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\r\n"
                        , DateTime.UtcNow.ToString("yyyyMMdd.hhmmss")
                        , ConfigurationManager.Instance.ConfigurationRecord.Account_Username
                        , ConfigurationManager.Instance.ConfigurationRecord.Account_Nickname
                        , Environment.UserName
                        , filename_short
                        , pdf_path
                        );

                    try
                    {
                        File.AppendAllText(audit_filename, audit_data);
                    }
                    catch (Exception ex)
                    {
                        Logging.Warn(ex, "Unable to write intranet sync audit data.");
                    }
                }
            }
        }
        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;
            }
        }
示例#4
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);
            }
        }
示例#5
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);
            }
        }