Beispiel #1
0
        // The meat, entry point from interop
        public ResultFileStorageData GetStorage(RequestFileStorageData fileStorageData)
        {
            string srcPath = fileStorageData.FilePath;
            string srcHash = CalculateFileMD5(srcPath);

            // Do we even exist in db?
            Storage storage = m_StorageRepo.GetStorageByHash(srcHash);

            if (storage == null)
            {
                storage = CreateNewStorageForFile(fileStorageData, srcHash);
            }

            // Save for posterity.
            var history = new History
            {
                Hash      = srcHash,
                OpenDate  = DateTime.Now,
                VolumeId  = storage.VolumeId,
                StorageId = storage.Id,
            };

            m_DBService.InsertOrUpdate(history);

            var res = new ResultFileStorageData
            {
                StorageFilePath = Path.Combine(UserSettingsService.StorageFolder, storage.StorageName),
                Cancel          = false,
            };

            return(res);
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            RequestFileStorageData data = new RequestFileStorageData
            {
                FilePath = @"s:\Users\stimo\Desktop\1662753704.pdf",
            };

            BelManagedClass bel = new BelManagedClass();

            ResultFileStorageData res = bel.RequestFileStoragePath(data);

            MessageBox.Show(res.StorageFilePath);
        }
Beispiel #3
0
        // The meat, entry point from interop
        // Called when Sumatra opens a file
        public ResultFileStorageData GetStorage(RequestFileStorageData fileStorageData)
        {
            string srcPath = fileStorageData.FilePath;

            if (!File.Exists(srcPath))
            {
                return new ResultFileStorageData
                       {
                           Cancel          = true,
                           StorageFilePath = "",
                       }
            }
            ;

            string srcHash = StorageHelperService.CalculateFileMD5(srcPath);

            // Do we even exist in db?
            Storage storage = m_StorageRepo.GetStorageByHash(srcHash);

            if (storage == null)
            {
                storage = CreateNewStorageForFile(fileStorageData, srcHash);
            }
            // Has source file been moved / renamed?
            else if (storage.FilePath != srcPath || storage.FileName != Path.GetFileName(srcPath))
            {
                StorageHelperService.DeleteOldStorageFiles(Path.Combine(UserSettingsService.StorageFolder, storage.StorageName));
                storage.FilePath    = srcPath;
                storage.FileName    = Path.GetFileName(srcPath);
                storage.StorageName = StorageHelperService.GetUniqueStoName(fileStorageData.FilePath);
                m_DBService.InsertOrUpdate(storage);
            }

            VM.CurrentStorage = storage;

            string storagePath = Path.Combine(UserSettingsService.StorageFolder, storage.StorageName);

            // Hmm storage file has been removed (this is not bad) - just recreate it.
            if (!File.Exists(storagePath))
            {
                m_VolumeService.LoadVolume(storage.VolumeId);
                m_VolumeService.LoadCitations();
                if (m_VolumeService.Citations.Any())
                {
                    PdfService.RecreateTheWholeThing(VM, m_VolumeService);
                }
                else
                {
                    CopyFileToStorage(storage.FilePath, storage.StorageName);
                }
            }

            // Save for posterity.
            var history = new History
            {
                Hash      = srcHash,
                OpenDate  = DateTime.Now,
                VolumeId  = storage.VolumeId,
                StorageId = storage.Id,
            };

            m_DBService.InsertOrUpdate(history);

            var res = new ResultFileStorageData
            {
                StorageFilePath = storagePath,
                Cancel          = false,
            };

            return(res);
        }