当前位置: 首页>>代码示例>>C#>>正文


C# SortedSet.Where方法代码示例

本文整理汇总了C#中SortedSet.Where方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Where方法的具体用法?C# SortedSet.Where怎么用?C# SortedSet.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedSet的用法示例。


在下文中一共展示了SortedSet.Where方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            SortedSet<string> inputWords = new SortedSet<string>(Regex.Split(input, @"[\s,.?!]+"));

            Console.WriteLine($"[{string.Join(", ", inputWords.Where(w => w.SequenceEqual(w.Reverse())))}]");
        }
开发者ID:,项目名称:,代码行数:8,代码来源:

示例2: AuthSignature

        public AuthSignature(string appSecret, Uri url, SortedSet<PostParameter> postParameters)
            : this(appSecret, url)
        {
            var postValues = postParameters
                .Where(p => p is StringPostParameter)
                .Select(p => p.Value.ToString())
                .ToArray();

            _postValuesString = string.Join(",", postValues);
        }
开发者ID:adiospl,项目名称:WykopSharp,代码行数:10,代码来源:AuthSignature.cs

示例3: ShowInGenreList

        public void ShowInGenreList(IEnumerable<Playable> playables)
        {
            ISet<Path> paths = new SortedSet<Path>(playables.Select(e => e.Path));
            ISet<Song> songs = new SortedSet<Song>(paths.Where(e => m_DataModel.Database.Songs.ContainsKey(e)).Select(e => m_DataModel.Database.Songs[e]));
            ISet<GenreFilteredAlbum> albums = new SortedSet<GenreFilteredAlbum>(songs.Where(e => e.GenreFilteredAlbum != null).Select(e => e.GenreFilteredAlbum));
            ISet<Genre> genres = new SortedSet<Genre>(albums.Where(e => e.Genre != null).Select(e => e.Genre));

            foreach (IndexedLibraryItem row in Genres)
            {
                row.IsSelected = genres.Contains(row.ItemAs<Genre>());
            }

            m_DataModel.MainWindow.Dispatcher.BeginInvoke(new Action(() =>
            {
                foreach (IndexedLibraryItem row in AlbumsOfSelectedGenres)
                {
                    row.IsSelected = albums.Contains(row.ItemAs<GenreFilteredAlbum>());
                }

                m_DataModel.MainWindow.Dispatcher.BeginInvoke(new Action(() =>
                {
                    foreach (IndexedLibraryItem row in SongsOnSelectedAlbumsOfSelectedGenres)
                    {
                        row.IsSelected = songs.Contains(row.ItemAs<Song>());
                    }

                    OnSelectedSongsOnSelectedAlbumsOfSelectedGenresChanged();
                }), DispatcherPriority.Loaded);
            }), DispatcherPriority.Loaded);
        }
开发者ID:paukr,项目名称:auremo,代码行数:30,代码来源:DatabaseView.cs

示例4: ProjectReferencesList

        public static void ProjectReferencesList(Microsoft.CodeAnalysis.Project project, SortedSet<string> list)
        {
            if (!Configuration.ProcessReferencies)
                return;

            var name = project.Name;
            var ref1 = References.Instance.refList.Where((el) => el.CsProj.StartsWith(name + "."));
            var refList = project.ProjectReferences;
            var metaRefList = project.MetadataReferences;
            var fedAssemblies = Federation.ReferenceSourceAssemblies()[0];

            foreach (var refItem in ref1)
            {
                if (string.IsNullOrWhiteSpace(refItem.HintPath))
                {
                    var nameSplit = refItem.Dll.Split(new char[] { ',' });
                    var refAsm = nameSplit[0];

                    var find = fedAssemblies.Where((el) => el.StartsWith(refAsm, StringComparison.InvariantCultureIgnoreCase));
                    if (find.Any())
                    {
                        list.Add(refAsm);
                    }
                    continue;
                }

                string asm = Path.GetFileNameWithoutExtension(refItem.HintPath);
                var search = list.Where((a) => asm.StartsWith(a));
                if (search == null || !search.Any())
                {
                    list.Add(asm);
                }
            }
        }
开发者ID:akrisiun,项目名称:SourceBrowser,代码行数:34,代码来源:ExtendGenerator.cs

示例5: MakeAllPossibleWaysRec

        private IEnumerable<PrimaryFrameNode> MakeAllPossibleWaysRec(List<string> processed, ProjectionElement element, SortedSet<BoundingParameter> orderedParameters, int depth)
        {
            if (depth == int.MinValue)
                throw new InvalidOperationException("Ошибка при построении плана - слишком глубокая схема для разбора");
            if (depth == 0)
                return new PrimaryFrameNode[0];

            #region Проверка - был ли проверен текущий элемент, и добавление его к проверенным

            var hash = GetHashForElementAndParameters(element, new ParameterNames(orderedParameters.Select(k => k.Name)));

           
                if (processed.Contains(hash))
                    return new PrimaryFrameNode[0];

                processed.Add(hash);
            

            #endregion

            #region Добавление текущего элемента к родительским параметрам или обнуление глубины уже существующего параметра с данным именем

            foreach (var p in orderedParameters)
            {
                p.Depth++;
            }

            var parameter = orderedParameters.FirstOrDefault(k => k.Name == element.Name);
            int oldDepth;
            if (parameter == null)
            {
                parameter = new BoundingParameter(element.Name, 1);
                orderedParameters.Add(parameter);
                oldDepth = 0;
            }
            else
            {
                oldDepth = parameter.Depth;
                parameter.Depth = 1;
            }

            #endregion

            #region Обход детей дочерних нод

            var childElements = element.DownRelations
                .Select(k => new
                                 {
                                     relation = k,
                                     k.ChildElement,
                                     children =
                                 MakeAllPossibleWaysRec(processed, k.ChildElement, orderedParameters, depth - 1)
                                 }).ToArray();

            #endregion



            processed.Remove(hash);

            if (oldDepth == 0)
                orderedParameters.Remove(parameter);
            else
            {
                parameter.Depth = oldDepth;
            }


            #region Формирование списка нод вместе с дочерними

            var allNodes = childElements.Select(k =>
                                                new PrimaryFrameNode
                                                    {
                                                        Current = k.ChildElement,
                                                        OrderedParameters =
                                                            orderedParameters.Where(k2=>!StringComparer.InvariantCultureIgnoreCase.Equals(k2.Name,element.Name))
                                                                             .Select(k2 => new BoundingParameter(k2.Name, k2.Depth))
                                                                             .ToArray(),
                                                        Parent = element,
                                                        Relation = k.relation
                                                    })
                .Concat(childElements.SelectMany(k => k.children))
                .ToArray();

            #endregion


            foreach (var p in orderedParameters)
            {
                p.Depth--;
            }
          
            return allNodes;
        }
开发者ID:kayanme,项目名称:Dataspace,代码行数:94,代码来源:FramingPlanBuilder.cs

示例6: CreateNewLogFile

        /// <summary>
        /// Cleans up any old log files (according to maxage, maxsize settigns) and creates new log file [logdir]\[app]_[yyyymmdd]_[n].log.
        /// </summary>
        private FileStream CreateNewLogFile()
        {
            // Note: Log files are named [logdir]\[logfileprefix]_[yyyymmdd]_[nnnn].log
            // This makes it easy to find and sort log files.

            // Use a named mutex to ensure that when multiple instances of the same app are run at the same time they don't both try to cleanup logfiles at the same time or create a new logfile with the same name.
            Mutex logFileManipulationMutex = new Mutex(false, String.Format("Microsoft.Sonar.TextFileTraceListener.LogFileManipulationMutex.{0}", m_logFilePrefix));
            try
            {
                logFileManipulationMutex.WaitOne();
            }
            catch (AbandonedMutexException)
            {
                // This exception indicates that we successfully acquired the mutex, but it was not released normally - the previous owner died holding the mutex - and so anything
                // protected by the mutex could be in an inconsistent state. We re-enumerate the state of logdir after acquiring the mutex so that should not cause any problems.
            }

            try
            {
                // First cleanup any old logs according to maxage, maxsize, etc policies.
                // Use LastWriteTime instead of CreationTime because a log file could get created and then used for several days if the application doesn't restart and it doesn't get filled up.
                SortedSet<String> logFiles = new SortedSet<String>();
                Int64 logFilesTotalSize = 0;
                foreach (String logFile in Directory.EnumerateFiles(m_logDir, String.Format("{0}_*.log", m_logFilePrefix), SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        FileInfo logFileInfo = new FileInfo(logFile);
                        Int64 logFileSize = logFileInfo.Length;
                        if ((logFileInfo.LastWriteTime.ToUniversalTime() > DateTime.Now.ToUniversalTime()) || (DateTime.Now.ToUniversalTime().Subtract(logFileInfo.LastWriteTime.ToUniversalTime()).TotalDays > (Double)m_maxAge))
                        {
                            try
                            {
                                File.Delete(logFile);
                                continue;
                            }
                            catch
                            {
                                // Unable to delete old log file so account for its size.
                                // Maybe there is enough space anyway or other log files can be deleted to make space.
                            }
                        }

                        // Log file names are already in chronologically sorted order so no need for separate sort key.
                        logFiles.Add(logFile);
                        logFilesTotalSize += logFileSize;
                    }
                    catch (FileNotFoundException)
                    {
                        // If there are multiple app domains then another instance of TextFileTraceListener may have deleted the file between when it was enumerated and now.
                        continue;
                    }
                }

                // If the total log files size is greater than the max allowed then delete old log files until there is enough room.
                Int64 logFilesMaxTotalSize = m_maxSize - m_maxFileSize;
                if (logFilesTotalSize > logFilesMaxTotalSize)
                {
                    foreach (String logFile in logFiles)
                    {
                        try
                        {
                            FileInfo logFileInfo = new FileInfo(logFile);
                            Int64 logFileSize = logFileInfo.Length;
                            File.Delete(logFile);
                            logFilesTotalSize -= logFileSize;
                            if (logFilesTotalSize < logFilesMaxTotalSize)
                            {
                                // There is enough room to create a new log file now so we're done.
                                break;
                            }
                        }
                        catch
                        {
                            // Unable to delete old log file so account for its size.
                            // Maybe there is enough space anyway or other log files can be deleted to make space.
                        }
                    }
                }
                if (logFilesTotalSize > logFilesMaxTotalSize)
                {
                    // After deleting all the old log files we could there still isn't enough room for a new log file.
                    // This means we can't do tracing and will make it hard to debug application failures so making this fatal.
                    Environment.FailFast(String.Format("Unable to free up enough space to create a new log file. Space required = {0}MB, Max space allowed = {1}MB, Space taken up by existing un-deleteable log files = {1}MB.", m_maxFileSize / (1024 * 1024), m_maxSize / (1024 * 1024), logFilesTotalSize / (1024 * 1024)));
                    throw new Exception();
                }

                // Generate new log file name.
                // If there are already log files with today's date then take the last one and increment n.
                String logFilePrefixAndDate = String.Format("{0}_{1:yyyyMMdd}_", m_logFilePrefix, DateTime.Now.ToLocalTime());
                Int64 logFileIndex = 1;
                IEnumerable<string> totalLogFilesToday = logFiles.Where(logFile => Path.GetFileNameWithoutExtension(logFile).StartsWith(logFilePrefixAndDate, StringComparison.InvariantCultureIgnoreCase));

                if (totalLogFilesToday.Count() >= 9999)
                {
                    // There are more than 9999 log files in a single day, generated by a service. 
                    // It is an indicator that recurring restarts did not solve the issue thus we terminate the service immediately
//.........这里部分代码省略.........
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:101,代码来源:TextFileTraceListener.cs

示例7: CollectChanges

        /// <summary>
        /// Collects the changes.
        /// </summary>
        /// <param name="changeset1">The changeset1.</param>
        /// <param name="changeset2">The changeset2.</param>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        private IEnumerable<IChange> CollectChanges(MergableChangeset changeset1, MergableChangeset changeset2,
                                                    IReadOnlyList<string> source)
        {
            if ((changeset1 == null) || (changeset2 == null) || (source == null))
            {
                throw new ArgumentNullException();
            }

            changeset1.Verify(source.Count);
            changeset2.Verify(source.Count);

            var lines = new SortedSet<int>(changeset1.Keys.Union(changeset2.Keys));
            var removedLines = new HashSet<int>();
            bool swapped = false;
            foreach (int line in lines.Where(l => !removedLines.Contains(l)))
            {
                if (!changeset1.ContainsKey(line))
                {
                    Utils.Swap(ref changeset1, ref changeset2);
                    swapped = !swapped;
                }

                IMergableChange currentChange = changeset1.Extract(line);
                CollidingChanges collidingChanges = FindCollidingChanges(currentChange, changeset1, changeset2);

                if (collidingChanges.IsEmpty())
                {
                    yield return currentChange;
                    continue;
                }

                IMergableChange collidingChange = collidingChanges.TryGetSingle();
                if (collidingChange != null)
                {
                    removedLines.Add(collidingChange.Start);
                    if (swapped)
                    {
                        Utils.Swap(ref currentChange, ref collidingChange);
                    }
                    yield return ProcessCollision(source, currentChange, collidingChange);
                }
                else
                {
                    foreach (int l in collidingChanges.Keys)
                    {
                        removedLines.Add(l);
                    }
                    collidingChanges.ChangesFrom1.Add(currentChange);
                    yield return swapped
                        ? ProcessCollision(source, collidingChanges.ChangesFrom2, collidingChanges.ChangesFrom1)
                        : ProcessCollision(source, collidingChanges.ChangesFrom1, collidingChanges.ChangesFrom2);
                }
            }
        }
开发者ID:Vadim-Borovikov,项目名称:Automerger,代码行数:62,代码来源:SimpleMerger.cs

示例8: MergeUnits_DontMergeBookedUnits_Pass

        public void MergeUnits_DontMergeBookedUnits_Pass()
        {
            unit3.AssignedCourse = new Course();
            units1 = new SortedSet<TimeUnit>() { unit1, unit2, unit3 };
            units1.MergeUnits();

            Assert.AreEqual(2, units1.Count);
            var units = units1.Where(unit => unit.AssignedCourse == null).ToList();
            Assert.AreEqual(1, units.Count);
            Assert.AreEqual(start, units.First().Start);
            Assert.AreEqual(point2, units.First().End);
        }
开发者ID:cverhelst,项目名称:Timetable,代码行数:12,代码来源:ExtensionsTest.cs

示例9: UpdateConfiguration

        private void UpdateConfiguration()
        {
            try
            {
                if (!File.Exists(filename))
                {
                    if (ranges == null)
                    {
                        Log.Error("Config \"" + filename + "\" doesn't exist");
                    }
                    else
                    {
                        Log.Warn("Config file \"" + filename
                        + "\" doesn't exist, skipping update");
                    }
                    return;
                }

                Dictionary<IPAddress, int> rangesNew = new Dictionary<IPAddress, int>();
                Dictionary<string, string> rangesEmailNew = new Dictionary<string, string>();
                SortedSet<int> prefixesNew = new SortedSet<int>();

                // parse IP address ranges from text file
                using (StreamReader reader = new StreamReader(filename))
                {
                    int pos = 0;
                    string line;

                    while ((line = reader.ReadLine()) != null)
                    {
                        pos++;

                        if (line.StartsWith("#"))
                            continue;

                        if (line.Trim() == string.Empty)
                            continue;

                        try
                        {
                            string[] data = line.Split(separator);
                            Tuple<IPAddress, int> network = Utils.ParseNetwork(data[0].Trim());
                            IPAddress net = Utils.GetNetwork(network.Item1, network.Item2);

                            prefixesNew.Add(network.Item2);
                            if (data.Length > 1)
                            {
                                rangesEmailNew[net + "/" + network.Item2] = data[1];
                            }
                            else
                            {
                                rangesEmailNew[net + "/" + network.Item2] = null;
                            }

                            //if (rangesNew.ContainsKey(net) && rangesNew[net] <= network.Item2)
                            //    continue;

                            //rangesNew[net] = network.Item2;
                        }
                        catch (FormatException ex)
                        {
                            Log.Error("Unable to parse range in \"" + filename
                                + "\" (line #" + pos + "): " + line.Trim()
                                + " (" + ex.Message + ")");
                            continue;
                        }
                    }
                }

                // Optimization: remove overlapping IP subranges
                foreach (int prefix in prefixesNew)
                {
                    foreach (KeyValuePair<string, string> rangeEmail in rangesEmailNew)
                    {
                        if (!rangeEmail.Key.EndsWith("/" + prefix))
                            continue;

                        bool exists = false;
                        Tuple<IPAddress, int> network = Utils.ParseNetwork(rangeEmail.Key);

                        foreach (int prefixSmaler in prefixesNew.Where(u => u <= prefix))
                        {
                            IPAddress net = Utils.GetNetwork(network.Item1, prefixSmaler);

                            if (rangesNew.ContainsKey(net) && prefixSmaler >= network.Item2)
                            {
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            IPAddress net = Utils.GetNetwork(network.Item1, network.Item2);
                            rangesNew[net] = network.Item2;
                        }
                    }
                }

                // update configuration
//.........这里部分代码省略.........
开发者ID:vokac,项目名称:F2B,代码行数:101,代码来源:RangeFile.cs


注:本文中的SortedSet.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。