Example #1
0
        public bool OpenSkyFile(string skylineFile)
        {
            try
            {
                var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty));
                using (var stream = new StreamReaderWithProgress(skylineFile, progressMonitor))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(SrmDocument));
                    _out.WriteLine(Resources.CommandLine_OpenSkyFile_Opening_file___);

                    _doc = ConnectDocument((SrmDocument)xmlSerializer.Deserialize(stream), skylineFile);
                    if (_doc == null)
                        return false;

                    _out.WriteLine(Resources.CommandLine_OpenSkyFile_File__0__opened_, Path.GetFileName(skylineFile));
                }
            }
            catch (FileNotFoundException)
            {
                _out.WriteLine(Resources.CommandLine_OpenSkyFile_Error__The_Skyline_file__0__does_not_exist_, skylineFile);
                return false;
            }
            catch (Exception x)
            {
                _out.WriteLine(Resources.CommandLine_OpenSkyFile_Error__There_was_an_error_opening_the_file__0_, skylineFile);
                _out.WriteLine(XmlUtil.GetInvalidDataMessage(skylineFile, x));
                return false;
            }
            _skylineFile = skylineFile;
            return true;
        }
Example #2
0
        public bool OpenFile(string path, FormEx parentWindow = null)
        {
            // Remove any extraneous temporary chromatogram spill files.
            var spillDirectory = Path.Combine(Path.GetDirectoryName(path) ?? "", "xic");    // Not L10N
            if (Directory.Exists(spillDirectory))
                DirectoryEx.SafeDelete(spillDirectory);

            Exception exception = null;
            SrmDocument document = null;

            try
            {
                using (var longWaitDlg = new LongWaitDlg(this)
                {
                    Text = Resources.SkylineWindow_OpenFile_Loading___,
                    Message = Path.GetFileName(path),
                    ProgressValue = 0
                })
                {
                    longWaitDlg.PerformWork(parentWindow ?? this, 500, progressMonitor =>
                    {
                        using (var reader = new StreamReaderWithProgress(path, progressMonitor))
                        {
                            XmlSerializer ser = new XmlSerializer(typeof (SrmDocument));
                            document = (SrmDocument) ser.Deserialize(reader);
                        }
                    });

                    if (longWaitDlg.IsCanceled)
                        document = null;
                }
            }
            catch (Exception x)
            {
                exception = x;
            }

            if (exception == null)
            {
                if (document == null)
                    return false;

                try
                {
                    document = ConnectDocument(parentWindow ?? this, document, path);
                    if (document == null || !CheckResults(document, path))
                        return false;

                    // Make sure settings lists contain correct values for
                    // this document.
                    document.Settings.UpdateLists(path);
                }
                catch (Exception x)
                {
                    exception = x;
                }
            }

            if (exception == null)
            {
                try
                {
                    using (new SequenceTreeForm.LockDoc(_sequenceTreeForm))
                    {
                        // Switch over to the opened document
                        SwitchDocument(document, path);
                    }
                    // Locking the sequenceTree can throw off the node count status
                    UpdateNodeCountStatus();
                }
                catch (Exception x)
                {
                    exception = x;
                }
            }

            if (exception != null)
            {
                new MessageBoxHelper(parentWindow ?? this).ShowXmlParsingError(
                    string.Format(Resources.SkylineWindow_OpenFile_Failure_opening__0__, path), path, exception);
                return false;
            }

            if (SequenceTree != null && SequenceTree.Nodes.Count > 0 && !SequenceTree.RestoredFromPersistentString)
                SequenceTree.SelectedNode = SequenceTree.Nodes[0];

            return true;
        }