Example #1
0
        private TemporaryDirectory ShareSkydFile(ZipFileShare zip, TemporaryDirectory tempDir)
        {
            string pathCache = ChromatogramCache.FinalPathForName(DocumentPath, null);

            if (!File.Exists(pathCache))
            {
                return(tempDir);
            }
            if (ShareType.SkylineVersion != null && Document.Settings.HasResults)
            {
                var measuredResults = Document.Settings.MeasuredResults;
                if (measuredResults.CacheVersion.HasValue &&
                    !measuredResults.CacheVersion.Equals(ShareType.SkylineVersion.CacheFormatVersion))
                {
                    String cacheFileName = Path.GetFileName(pathCache);
                    if (cacheFileName != null)
                    {
                        if (tempDir == null)
                        {
                            tempDir = new TemporaryDirectory();
                        }
                        String newCachePath = Path.Combine(tempDir.DirPath, cacheFileName);
                        MinimizeToFile(newCachePath, CacheFormat.FromVersion(ShareType.SkylineVersion.CacheFormatVersion));
                        zip.AddFile(newCachePath);
                        return(tempDir);
                    }
                }
            }
            zip.AddFile(pathCache);
            return(tempDir);
        }
Example #2
0
        private void ShareComplete(ZipFileShare zip)
        {
            TemporaryDirectory tempDir = null;

            try
            {
                // If complete sharing, just zip up existing files
                var pepSettings        = Document.Settings.PeptideSettings;
                var transitionSettings = Document.Settings.TransitionSettings;
                if (Document.Settings.HasBackgroundProteome)
                {
                    zip.AddFile(pepSettings.BackgroundProteome.BackgroundProteomeSpec.DatabasePath);
                }
                if (Document.Settings.HasRTCalcPersisted)
                {
                    zip.AddFile(pepSettings.Prediction.RetentionTime.Calculator.PersistencePath);
                }
                if (Document.Settings.HasOptimizationLibraryPersisted)
                {
                    zip.AddFile(transitionSettings.Prediction.OptimizedLibrary.PersistencePath);
                }
                if (Document.Settings.HasIonMobilityLibraryPersisted)
                {
                    zip.AddFile(pepSettings.Prediction.IonMobilityPredictor.IonMobilityLibrary.PersistencePath);
                }
                var libfiles = new HashSet <string>();
                foreach (var librarySpec in pepSettings.Libraries.LibrarySpecs)
                {
                    if (libfiles.Add(librarySpec.FilePath))
                    // Sometimes the same .blib file is referred to by different library specs
                    {
                        zip.AddFile(librarySpec.FilePath);

                        if (Document.Settings.TransitionSettings.FullScan.IsEnabledMs)
                        {
                            // If there is a .redundant.blib file that corresponds
                            // to a .blib file, add that as well
                            IncludeRedundantBlib(librarySpec, zip, librarySpec.FilePath);
                        }
                    }
                }

                // ReSharper disable ExpressionIsAlwaysNull
                tempDir = ShareDataAndView(zip, tempDir);
                // ReSharper restore ExpressionIsAlwaysNull
                if (null == ShareType.SkylineVersion)
                {
                    zip.AddFile(DocumentPath); // CONSIDER(bpratt) there's no check to see if this is a current representation of the document - a dirty check would be good
                }
                else
                {
                    tempDir = ShareDocument(zip, tempDir);
                }
                Save(zip);
            }
            finally
            {
                DeleteTempDir(tempDir);
            }
        }
Example #3
0
        private void Save(ZipFileShare zip)
        {
            CountEntries = zip.CountEntries;

            using (var saver = new FileSaver(SharedPath))
            {
                zip.Save(saver.SafeName, SrmDocumentSharing_SaveProgress);
                ProgressMonitor.UpdateProgress(_progressStatus.Complete());
                saver.Commit();
            }
        }
Example #4
0
        private TemporaryDirectory ShareDataAndView(ZipFileShare zip, TemporaryDirectory tempDir)
        {
            tempDir = ShareSkydFile(zip, tempDir);
            string viewPath = SkylineWindow.GetViewFile(DocumentPath);

            if (File.Exists(viewPath))
            {
                zip.AddFile(viewPath);
            }
            return(tempDir);
        }
Example #5
0
 private void IncludeRedundantBlib(LibrarySpec librarySpec, ZipFileShare zip, string blibPath)
 {
     if (librarySpec is BiblioSpecLiteSpec)
     {
         var redundantBlibPath = BiblioSpecLiteSpec.GetRedundantName(blibPath);
         if (File.Exists(redundantBlibPath))
         {
             zip.AddFile(redundantBlibPath);
         }
     }
 }
Example #6
0
 private void SafeAuditLog(ZipFileShare zip, string docPath)
 {
     if (ShouldShareAuditLog(Document, ShareType))
     {
         var path = SrmDocument.GetAuditLogPath(docPath);
         if (File.Exists(path))
         {
             zip.AddFile(path);
         }
     }
 }
Example #7
0
        private TemporaryDirectory ShareDocument(ZipFileShare zip, TemporaryDirectory tempDir, out string tempDocPath)
        {
            if (tempDir == null)
            {
                tempDir = new TemporaryDirectory();
            }
            string fileName = Path.GetFileName(DocumentPath) ?? string.Empty;

            tempDocPath = Path.Combine(tempDir.DirPath, fileName);
            Document.SerializeToFile(tempDocPath, tempDocPath,
                                     ShareType.SkylineVersion ?? SkylineVersion.CURRENT, ProgressMonitor);
            zip.AddFile(tempDocPath);
            return(tempDir);
        }
Example #8
0
        public void Share(IProgressMonitor progressMonitor)
        {
            ProgressMonitor = progressMonitor;
            ProgressMonitor.UpdateProgress(_progressStatus = new ProgressStatus(DefaultMessage));

            using (var zip = new ZipFileShare())
            {
                if (ShareType.Complete)
                {
                    ShareComplete(zip);
                }
                else
                {
                    ShareMinimal(zip);
                }
            }
        }
Example #9
0
        private void ShareMinimal(ZipFileShare zip)
        {
            TemporaryDirectory tempDir = null;

            try
            {
                var docOriginal = Document;
                if (Document.Settings.HasBackgroundProteome)
                {
                    // Remove any background proteome reference
                    Document = Document.ChangeSettings(Document.Settings.ChangePeptideSettings(
                                                           set => set.ChangeBackgroundProteome(BackgroundProteome.NONE)));
                }
                if (Document.Settings.HasRTCalcPersisted)
                {
                    // Minimize any persistable retention time calculator
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.RetentionTime
                                        .Calculator.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath);
                    }
                }
                if (Document.Settings.HasOptimizationLibraryPersisted)
                {
                    if (tempDir == null)
                    {
                        tempDir = new TemporaryDirectory();
                    }
                    string tempDbPath = Document.Settings.TransitionSettings.Prediction.OptimizedLibrary.PersistMinimized(
                        tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath);
                    }
                }
                if (Document.Settings.HasIonMobilityLibraryPersisted)
                {
                    // Minimize any persistable ion mobility predictor
                    if (tempDir == null)
                    {
                        tempDir = new TemporaryDirectory();
                    }
                    string tempDbPath = Document.Settings.TransitionSettings.IonMobilityFiltering.IonMobilityLibrary
                                        .PersistMinimized(tempDir.DirPath, Document, null, out _);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath);
                    }
                }
                if (Document.Settings.HasLibraries)
                {
                    // Minimize all libraries in a temporary directory, and add them
                    if (tempDir == null)
                    {
                        tempDir = new TemporaryDirectory();
                    }
                    Document = BlibDb.MinimizeLibraries(Document, tempDir.DirPath,
                                                        Path.GetFileNameWithoutExtension(DocumentPath),
                                                        null,
                                                        ProgressMonitor);
                    if (ProgressMonitor != null && ProgressMonitor.IsCanceled)
                    {
                        return;
                    }

                    foreach (var librarySpec in Document.Settings.PeptideSettings.Libraries.LibrarySpecs)
                    {
                        var tempLibPath = Path.Combine(tempDir.DirPath, Path.GetFileName(librarySpec.FilePath) ?? string.Empty);
                        zip.AddFile(tempLibPath);

                        // If there is a .redundant.blib file that corresponds to a .blib file
                        // in the temp temporary directory, add that as well
                        IncludeRedundantBlib(librarySpec, zip, tempLibPath);
                    }
                }

                var auditLogDocPath = DocumentPath;
                tempDir = ShareDataAndView(zip, tempDir);
                if (ReferenceEquals(docOriginal, Document) && null == ShareType.SkylineVersion)
                {
                    zip.AddFile(DocumentPath);
                }
                else
                {
                    tempDir = ShareDocument(zip, tempDir, out auditLogDocPath);
                }

                SafeAuditLog(zip, auditLogDocPath);

                Save(zip);
            }
            finally
            {
                DeleteTempDir(tempDir);
            }
        }