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


C# ConcurrentDictionary.Single方法代码示例

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


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

示例1: using

 public void Dispose_CalledWheMultipleStreamsInTheSession_ExpectOnlyDisposedStreamIsRemovedFromTheSessionCollection()
 {
     var sessionCollection = new ConcurrentDictionary<Guid, IEventStream>();
     using (var nonDisposedStream = new NEventStoreSessionStream(sessionCollection, DummyEventStream()))
     {
         var stream = new NEventStoreSessionStream(sessionCollection, DummyEventStream());
         stream.Dispose();
         sessionCollection.Single().Value.Should().BeSameAs(nonDisposedStream);
     }
 }
开发者ID:pete-restall,项目名称:Ichnaea,代码行数:10,代码来源:NEventStoreSessionStreamTest.cs

示例2: ProcessGroundForcesWikiHtmlFiles

        public void ProcessGroundForcesWikiHtmlFiles(ConcurrentDictionary<string, HtmlDocument> vehicleWikiPagesContent, ConcurrentDictionary<string, string> localFileChanges, Dictionary<string, GroundVehicle> vehicleDetails, List<HtmlNode> vehicleWikiEntryLinks, List<string> errorsList, int indexPosition, int expectedNumberOfLinks, bool createJsonFiles, bool createHtmlFiles, bool createExcelFile)
        {
            try
            {
                _consoleManager.WriteLineInColour(ConsoleColor.Yellow, "Press ENTER to begin extracting data from the vehicle pages.");
                _consoleManager.WaitUntilKeyIsPressed(ConsoleKey.Enter);

                foreach (string vehicleWikiPageLinkTitle in vehicleWikiPagesContent.Keys)
                {
                    // Page to traverse
                    HtmlDocument vehicleWikiPage = vehicleWikiPagesContent.Single(x => x.Key == vehicleWikiPageLinkTitle).Value;
                    // Get the header that holds the page title | document.getElementsByClassName('firstHeading')[0].firstChild.innerText
                    HtmlNode pageTitle = vehicleWikiPage.DocumentNode.Descendants().Single(d => d.Id == "firstHeading").FirstChild;
                    // Get the div that holds all of the content under the title section | document.getElementById('bodyContent')
                    HtmlNode wikiBody = vehicleWikiPage.DocumentNode.Descendants().Single(d => d.Id == "bodyContent");
                    // Get the div that holds the content on the RHS of the page where the information table is | document.getElementById('bodyContent').getElementsByClassName('right-area')
                    HtmlNode rightHandContent = wikiBody.Descendants("div").SingleOrDefault(d => d.Attributes["class"] != null && d.Attributes["class"].Value.Contains("right-area"));

                    // Get the able that holds all of the vehicle information | document.getElementsByClassName('flight-parameters')[0]
                    HtmlNode infoBox = rightHandContent != null
                        ? rightHandContent.Descendants("table").SingleOrDefault(d => d.Attributes["class"].Value.Contains("flight-parameters"))
                        : null;

                    // Name
                    string vehicleName = _stringHelper.RemoveInvalidCharacters(System.Net.WebUtility.HtmlDecode(vehicleWikiPageLinkTitle));

                    // Link
                    HtmlNode urlNode = vehicleWikiEntryLinks.SingleOrDefault(v => v.InnerText.Equals(vehicleName));
                    string relativeUrl = urlNode != null
                        ? urlNode.Attributes["href"].Value.ToString()
                        : "";
                    string vehicleWikiEntryFullUrl = new Uri(new Uri(ConfigurationManager.AppSettings["BaseWikiUrl"]), relativeUrl).ToString();

                    // Fail fast and create error if there is no info box
                    if (infoBox == null)
                    {
                        _consoleManager.WriteLineInColour(ConsoleColor.Red, $"Error processing item {indexPosition} of {expectedNumberOfLinks}", false);
                        _consoleManager.WriteBlankLine();

                        errorsList.Add($"No Information found for '{vehicleName}' - {vehicleWikiEntryFullUrl}");

                        _consoleManager.ResetConsoleTextColour();
                        indexPosition++;
                        continue;
                    }
                    else
                    {
                        // Setup local vars
                        Dictionary<string, string> vehicleAttributes = new Dictionary<string, string>();
                        HtmlNodeCollection rows = infoBox.SelectNodes("tr");

                        _consoleManager.WriteTextLine($"The following values were found for {vehicleName}");

                        _webCrawler.GetAttributesFromInfoBox(vehicleAttributes, rows);

                        _consoleManager.ResetConsoleTextColour();

                        // Country
                        string countryRawValue = vehicleAttributes.Single(k => k.Key == "Country").Value.ToString();
                        CountryEnum vehicleCountry = _vehicleCountryHelper.GetVehicleCountryFromName(countryRawValue).CountryEnum;

                        // Weight
                        string weightRawValue = vehicleAttributes.Single(k => k.Key == "Weight").Value.ToString();
                        int weightWithoutUnits = int.Parse(Regex.Match(weightRawValue, @"\d+").Value);
                        string weightUnitsAbbreviation = (Regex.Matches(weightRawValue, @"\D+").Cast<Match>()).Last().Value.Trim();
                        VehicleWeightUnitHelper vehicleWeightUnit = _vehicleWeightUnitHelper.GetWeightUnitFromAbbreviation(weightUnitsAbbreviation);

                        // Vehicle class
                        string typeRawValue = vehicleAttributes.Single(k => k.Key == "Type").Value.ToString();
                        GroundVehicleTypeHelper vehicleType = _vehicleTypeHelper.GetGroundVehicleTypeFromName(typeRawValue);

                        // Rank
                        int rankRawValue = int.Parse(vehicleAttributes.Single(k => k.Key == "Rank").Value.ToString());
                        int vehicleRank = rankRawValue;

                        // Battle rating
                        double ratingRawValue = double.Parse(vehicleAttributes.Single(k => k.Key == "Rating").Value.ToString());
                        double vehicleBattleRating = ratingRawValue;

                        // Engine power
                        string enginePowerRawValue = vehicleAttributes.Single(k => k.Key == "Engine power").Value.ToString();
                        int enginePowerWithoutUnits = int.Parse(Regex.Match(enginePowerRawValue, @"\d+").Value);
                        string enginePowerUnitsAbbreviation = (Regex.Matches(enginePowerRawValue, @"\D+").Cast<Match>()).Last().Value.Trim();
                        VehicleEnginePowerUnitHelper vehicleEngineUnit = _vehicleEnginePowerUnitHelper.GetEngineUnitFromAbbreviation(enginePowerUnitsAbbreviation);

                        // Max speed
                        string maxSpeedRawValue = vehicleAttributes.Single(k => k.Key == "Max speed").Value.ToString();
                        double maxSpeedWithoutUnits = double.Parse(Regex.Match(maxSpeedRawValue, @"\d+\.*\d*").Value);
                        string maxSpeedUnits = (Regex.Matches(maxSpeedRawValue, @"\D+").Cast<Match>()).Last().Value.Trim();
                        VehicleSpeedUnitHelper vehicleSpeedUnit = _vehicleSpeedUnitHelper.GetSpeedUnitFromAbbreviation(maxSpeedUnits);

                        // Hull armour
                        string hullArmourRawValue = vehicleAttributes.Single(k => k.Key == "Hull armour thickness").Value.ToString();
                        string vehicleHullArmourThickness = hullArmourRawValue;

                        // Superstructure armour
                        string superstructureArmourRawValue = vehicleAttributes.Single(k => k.Key == "Superstructure armour thickness").Value.ToString();
                        string vehicleSuperstructureArmourThickness = superstructureArmourRawValue;

                        // Repair time
//.........这里部分代码省略.........
开发者ID:BeigeBadger,项目名称:wt-wiki-scraper,代码行数:101,代码来源:IDataProcessor.cs

示例3: Constructor_Called_ExpectStreamAddsItselfToTheSessionCollection

 public void Constructor_Called_ExpectStreamAddsItselfToTheSessionCollection()
 {
     var sessionCollection = new ConcurrentDictionary<Guid, IEventStream>();
     using (var stream = new NEventStoreSessionStream(sessionCollection, DummyEventStream()))
     {
         sessionCollection.Single().Value.Should().BeSameAs(stream);
     }
 }
开发者ID:pete-restall,项目名称:Ichnaea,代码行数:8,代码来源:NEventStoreSessionStreamTest.cs


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