Пример #1
0
        public async Task <bool> Flush()
        {
            var      rawReader       = new RawReader();
            IRegHive hiveRegistry    = null;
            IRegHive hiveUser        = null;
            IRegHive hiveUserClasses = null;

            if (File.Exists(this.fileRegistry))
            {
                hiveRegistry = await rawReader.Open(this.fileRegistry).ConfigureAwait(false);
            }

            if (File.Exists(this.fileUser))
            {
                hiveUser = await rawReader.Open(this.fileUser).ConfigureAwait(false);
            }

            if (File.Exists(this.fileUserClasses))
            {
                hiveUserClasses = await rawReader.Open(this.fileUserClasses).ConfigureAwait(false);
            }

            if (hiveUserClasses == null && hiveRegistry == null && hiveUser == null)
            {
                return(false);
            }

            var foundAnythingRegistry    = false;
            var foundAnythingUser        = false;
            var foundAnythingUserClasses = false;

            using (hiveRegistry)
            {
                using (hiveUser)
                {
                    using (hiveUserClasses)
                    {
                        foreach (var key in this.deletedKeys)
                        {
                            var msix = RegistryPathConverter.ToMsixRegistryPath(key);

                            if (hiveRegistry != null)
                            {
                                using var foundKey = this.GetExistingRegistryKey(hiveRegistry.Root, msix);
                                if (foundKey != null)
                                {
                                    foundAnythingRegistry = true;
                                    RemoveRecurse(foundKey);
                                }
                            }

                            if (hiveUser != null)
                            {
                                using var foundKey = this.GetExistingRegistryKey(hiveUser.Root, msix);

                                if (foundKey != null)
                                {
                                    foundAnythingUser = true;
                                    RemoveRecurse(foundKey);
                                }
                            }

                            if (hiveUserClasses != null)
                            {
                                using var foundKey = this.GetExistingRegistryKey(hiveUserClasses.Root, msix);

                                if (foundKey != null)
                                {
                                    foundAnythingUserClasses = true;
                                    RemoveRecurse(foundKey);
                                }
                            }
                        }

                        if (foundAnythingRegistry)
                        {
                            await hiveRegistry.Save(this.fileRegistry).ConfigureAwait(false);
                        }

                        if (foundAnythingUser)
                        {
                            await hiveUser.Save(this.fileUser).ConfigureAwait(false);
                        }

                        if (foundAnythingUserClasses)
                        {
                            await hiveUserClasses.Save(this.fileUserClasses).ConfigureAwait(false);
                        }
                    }
                }
            }

            this.deletedKeys.Clear();
            return(foundAnythingRegistry || foundAnythingUser || foundAnythingUserClasses);
        }
        public override List <IsobaricItem> ReadFromFile(string fileName)
        {
            var result = new List <IsobaricItem>();

            RawReader.Open(fileName);
            try
            {
                int startScan = RawReader.GetFirstSpectrumNumber();
                int endScan   = RawReader.GetLastSpectrumNumber();

                Progress.SetRange(startScan, endScan);

                for (int scan = startScan; scan <= endScan; scan++)
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }

                    Progress.SetPosition(scan);

                    if (2 == RawReader.GetMsLevel(scan))
                    {
                        string scanMode = RawReader.GetScanMode(scan);
                        if (string.IsNullOrEmpty(scanMode))
                        {
                            AppendScan(result, scan, "UNKNOWN");
                            continue;
                        }

                        scanMode = scanMode.ToLower();
                        if (scanMode.Equals("pqd"))
                        {
                            AppendScan(result, scan, "PQD");
                        }
                        else if (scanMode.Equals("cid"))
                        {
                            //如果上一个scan是pqd,那么,现在这个cid的结果从该pqd读取。
                            if (result.Count > 0 && result[result.Count - 1].RawPeaks.ScanTimes[0].Scan == scan - 1 && result[result.Count - 1].RawPeaks.ScanMode == "PQD")
                            {
                                var lastItem = result[result.Count - 1];

                                var item = new IsobaricItem(lastItem);
                                item.Scan     = RawReader.GetScanTime(scan);
                                item.ScanMode = "CID";

                                result.Add(item);
                            }
                            else//否则,从自己的peaklist中读取。
                            {
                                AppendScan(result, scan, "CID");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Scan {0} is skipped with mode {1}", scan, scanMode);
                        }
                    }
                }
            }
            finally
            {
                RawReader.Close();
            }

            return(result);
        }
Пример #3
0
        public async Task <bool> Flush()
        {
            var reader = new RawReader();

            if (this.msixRegistryFacade.Registry.Any())
            {
                IRegHive hive;

                if (!File.Exists(this.fileRegistry))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(this.fileRegistry)))
                    {
                        // ReSharper disable once AssignNullToNotNullAttribute
                        Directory.CreateDirectory(Path.GetDirectoryName(this.fileRegistry));
                    }

                    hive = await reader.Create().ConfigureAwait(false);
                }
                else
                {
                    hive = await reader.Open(this.fileRegistry).ConfigureAwait(false);
                }

                using (hive)
                {
                    this.CommitEntries(hive.Root, this.msixRegistryFacade.Registry);
                    await hive.Save(this.fileRegistry).ConfigureAwait(false);
                }
            }

            if (this.msixRegistryFacade.User.Any())
            {
                IRegHive hive;

                if (!File.Exists(this.fileUser))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(this.fileUser)))
                    {
                        // ReSharper disable once AssignNullToNotNullAttribute
                        Directory.CreateDirectory(Path.GetDirectoryName(this.fileUser));
                    }

                    hive = await reader.Create().ConfigureAwait(false);
                }
                else
                {
                    hive = await reader.Open(this.fileUser).ConfigureAwait(false);
                }

                using (hive)
                {
                    this.CommitEntries(hive.Root, this.msixRegistryFacade.User);
                    await hive.Save(this.fileUser).ConfigureAwait(false);
                }
            }

            if (this.msixRegistryFacade.UserClasses.Any())
            {
                IRegHive hive;

                if (!File.Exists(this.fileUserClasses))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(this.fileUserClasses)))
                    {
                        // ReSharper disable once AssignNullToNotNullAttribute
                        Directory.CreateDirectory(Path.GetDirectoryName(this.fileUserClasses));
                    }

                    hive = await reader.Create().ConfigureAwait(false);
                }
                else
                {
                    hive = await reader.Open(this.fileUserClasses).ConfigureAwait(false);
                }

                using (hive)
                {
                    this.CommitEntries(hive.Root, this.msixRegistryFacade.UserClasses);
                    await hive.Save(this.fileUserClasses).ConfigureAwait(false);
                }
            }

            var hasChanges = this.msixRegistryFacade.Registry.Any() || this.msixRegistryFacade.User.Any() || this.msixRegistryFacade.UserClasses.Any();

            this.msixRegistryFacade.Registry.Clear();
            this.msixRegistryFacade.User.Clear();
            this.msixRegistryFacade.UserClasses.Clear();

            return(hasChanges);
        }
        public virtual List <IsobaricItem> ReadFromFile(string fileName)
        {
            var result = new List <IsobaricItem>();

            var askedScanMode = GetScanMode();
            var lowerScanMode = new HashSet <string>(from a in askedScanMode
                                                     select a.ToLower());


            RawReader.Open(fileName);
            try
            {
                FirstScan = RawReader.GetFirstSpectrumNumber();
                EndScan   = RawReader.GetLastSpectrumNumber();

                DoAfterFileOpen();

                var firstIsolationWidth = 0.0;

                var icount = 0;
                for (int scan = FirstScan; scan <= EndScan; scan++)
                {
                    if (!RawReader.IsScanValid(scan))
                    {
                        continue;
                    }

                    if (this.MsLevel == RawReader.GetMsLevel(scan))
                    {
                        firstIsolationWidth = RawReader.GetIsolationWidth(scan);
                        if (firstIsolationWidth > 0 && firstIsolationWidth < 5)
                        {
                            break;
                        }
                        icount++;
                        if (icount > 10)
                        {
                            break;
                        }
                    }
                }

                if (firstIsolationWidth == 0.0)
                {
                    firstIsolationWidth = defaultIsolationWidth;
                }

                Progress.SetMessage("Reading channel information ...");
                Progress.SetRange(FirstScan, EndScan);

                for (int scan = FirstScan; scan <= EndScan; scan++)
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }

                    if (!RawReader.IsScanValid(scan))
                    {
                        continue;
                    }

                    Progress.SetPosition(scan);

                    if (this.MsLevel == RawReader.GetMsLevel(scan))
                    {
                        string scanMode = RawReader.GetScanMode(scan).ToLower();
                        if (string.IsNullOrEmpty(scanMode))
                        {
                            AppendScan(result, scan, "UNKNOWN", firstIsolationWidth);
                        }
                        else if (lowerScanMode.Count == 0 || lowerScanMode.Contains(scanMode))
                        {
                            AppendScan(result, scan, scanMode.ToUpper(), firstIsolationWidth);
                        }
                        else
                        {
                            Console.WriteLine("Scan {0} is skipped with mode {1}", scan, scanMode);
                        }
                    }
                }
            }
            finally
            {
                RawReader.Close();
            }

            return(result);
        }