本文整理汇总了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);
}
}
示例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
//.........这里部分代码省略.........
示例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);
}
}