示例#1
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);
            }
        }
        private void ShareMinimal(ZipFile 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, string.Empty);
                    }
                }
                if (Document.Settings.HasOptimizationLibraryPersisted)
                {
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.TransitionSettings.Prediction.OptimizedLibrary.PersistMinimized(
                        tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath, string.Empty);
                    }
                }
                if (Document.Settings.HasIonMobilityLibraryPersisted)
                {
                    // Minimize any persistable drift time predictor
                    tempDir = new TemporaryDirectory();
                    string tempDbPath = Document.Settings.PeptideSettings.Prediction.DriftTimePredictor
                                        .IonMobilityLibrary.PersistMinimized(tempDir.DirPath, Document);
                    if (tempDbPath != null)
                    {
                        zip.AddFile(tempDbPath, string.Empty);
                    }
                }
                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),
                                                        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, string.Empty);

                        // 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);
                    }
                }

                ShareDataAndView(zip);
                if (ReferenceEquals(docOriginal, Document))
                {
                    zip.AddFile(DocumentPath, string.Empty);
                }
                else
                {
                    // If minimizing changed the document, then serialize and archive the new document
                    var stringWriter = new XmlStringWriter();
                    using (var writer = new XmlTextWriter(stringWriter)
                    {
                        Formatting = Formatting.Indented
                    })
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(SrmDocument));
                        ser.Serialize(writer, Document);
                        zip.AddEntry(Path.GetFileName(DocumentPath), stringWriter.ToString(), Encoding.UTF8);
                    }
                }
                Save(zip);
            }
            finally
            {
                if (tempDir != null)
                {
                    try
                    {
                        tempDir.Dispose();
                    }
                    catch (IOException x)
                    {
                        var message = TextUtil.LineSeparate(string.Format(Resources.SrmDocumentSharing_ShareMinimal_Failure_removing_temporary_directory__0__,
                                                                          tempDir.DirPath),
                                                            x.Message);
                        throw new IOException(message);
                    }
                }
            }
        }