public object Load(Guid contentHash) { byte[] data; if (!_backingStore.TryGetValue(contentHash, out data)) { this.Log().ErrorFormat("Failed to load object: {0}", contentHash); return(null); } this.Log().DebugFormat("Loaded {0}", contentHash); return(this._serializerFactory(contentHash).Deserialize(data, Utility.GetTypeByName(_itemTypeNames[contentHash]))); }
/// <summary> /// Обновляет статистику игрока, основываясь на информации о новом матче /// </summary> /// <param name="endpoint">Уникальный идентификатор сервера</param> /// <param name="timestamp">Временная метка окончания матча</param> /// <param name="index">Индекс игрока в списке игроков</param> /// <param name="matchInfo">Информация о матче</param> private void CalcPlayerStats(string endpoint, string timestamp, int index, MatchInfo matchInfo) { var info = matchInfo.Scoreboard[index]; var playerName = info.Name.ToLower(); var place = index + 1; lock (_locks.GetOrAdd(playerName, _ => new object())) { PlayerStats oldStats; if (!_stats.TryGetValue(playerName, out oldStats)) { oldStats = new PlayerStats { PublicStats = new PublicPlayerStats() }; } var newStats = oldStats.CalcNew(timestamp.ToUtc(), place, matchInfo, info); newStats.PublicStats = oldStats.PublicStats.CalcNew(endpoint, timestamp, place, newStats, matchInfo, info); if (newStats.TotalDeaths != 0 && newStats.PublicStats.TotalMatchesPlayed >= 10) { UpdateBestPlayersReport(playerName, newStats.PublicStats); } _stats[playerName] = newStats; } }
public static bool TryGetOnDiskLayoutVersion(PersistentDictionary <string, string> repoMetadata, out int version, out string error) { version = -1; error = string.Empty; string value; try { if (!repoMetadata.TryGetValue(Keys.DiskLayoutVersion, out value)) { error = MissingVersionError; return(false); } if (!int.TryParse(value, out version)) { error = "Failed to parse persisted disk layout version number: " + value; return(false); } } catch (EsentException ex) { error = ex.Message; return(false); } return(true); }
/// <summary> /// Test dictionary insert/replace/delete. /// </summary> /// <typeparam name="TKey">Key type of the dictionary.</typeparam> /// <typeparam name="TValue">Value type of the dictionary.</typeparam> /// <param name="dictionary">The dictionary to test.</param> /// <param name="key">Key that is present in the dictionary.</param> /// <param name="value">Value associated with the key in the dictionary.</param> private static void TestBasicOperations <TKey, TValue>(PersistentDictionary <TKey, TValue> dictionary, TKey key, TValue value) where TKey : IComparable <TKey> { var kvp = new KeyValuePair <TKey, TValue>(key, value); // Add a record dictionary.Add(key, value); // Test PersistentDictionary.Add error handling try { dictionary.Add(key, value); Assert.Fail("Expected ArgumentException from Add"); } catch (ArgumentException) { // Expected } // Overwrite a value dictionary[key] = value; // Retrieve a value Assert.AreEqual(value, dictionary[key], "Retrieve with [] failed"); TValue t; Assert.IsTrue(dictionary.TryGetValue(key, out t), "TryGetValue({0}) failed", key); Assert.AreEqual(value, t, "TryGetValue({0}) returned the wrong value", key); // Clear and re-insert dictionary.Clear(); Assert.AreEqual(0, dictionary.Count, "Dictionary is empty. Count is wrong"); dictionary[key] = value; Assert.AreEqual(1, dictionary.Count, "Item was just inserted. Count is wrong"); // Get the keys and values Assert.AreEqual(dictionary.Keys.First(), key, "Keys collection"); Assert.AreEqual(dictionary.Values.First(), value, "Values collection"); // Test PersistentDictionary.Contains (true) Assert.IsTrue(dictionary.ContainsKey(key), "Dictionary should have contained key {0}", key); Assert.IsTrue(dictionary.ContainsValue(value), "Dictionary should have contained value {0}", value); Assert.IsTrue(dictionary.Contains(kvp), "Dictionary should have contained <{0},{1}>", key, value); // Test PersistentDictionary.Remove Assert.IsTrue(dictionary.Remove(key), "Key {0} should exist, but removal failed", key); Assert.IsFalse(dictionary.Remove(key), "Key {0} doesn't exist, but removal succeeded", key); dictionary.Add(kvp); Assert.IsTrue(dictionary.Remove(kvp), "KeyValuePair <{0},{1}> should exist, but removal failed", kvp.Key, kvp.Value); Assert.IsFalse(dictionary.Remove(kvp), "KeyValuePair <{0},{1}> doesn't exist, but removal succeeded", kvp.Key, kvp.Value); // Test PersistentDictionary.Contains (false) Assert.IsFalse(dictionary.ContainsKey(key), "Dictionary should have contained key {0}", key); Assert.IsFalse(dictionary.ContainsValue(value), "Dictionary should have contained value {0}", value); Assert.IsFalse(dictionary.Contains(kvp), "Dictionary should have contained <{0},{1}>", key, value); }
private UserData TryGetUserData(string username) { string data; if (_users.TryGetValue(username, out data)) { return(JsonConvert.DeserializeObject <UserData>(data)); } return(null); }
/// <summary> /// If the key box is filled in, lookup that key in the dictionary /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LookupKeyValue_Click(object sender, RoutedEventArgs e) { universalWindowsDB.TryGetValue(keyLookup.Text, out string value); if (!string.IsNullOrEmpty(value)) { valueLookup.Text = value; } else { valueLookup.Text = "Value not found"; } }
private void PopulateNamedEntrySizes( GVFSGitObjects gitObjects, PersistentDictionary <string, long> blobSizes, string parentVirtualPath, GVFSContext context, IEnumerable <GitTreeEntry> entries) { List <GitTreeEntry> blobs = entries.Where(e => e.IsBlob).ToList(); // Then try to find as many blob sizes locally as possible. List <GitTreeEntry> entriesMissingSizes = new List <GitTreeEntry>(); foreach (GitTreeEntry namedEntry in blobs.Where(b => b.Size == 0)) { long blobLength = 0; if (blobSizes.TryGetValue(namedEntry.Sha, out blobLength)) { namedEntry.Size = blobLength; } else if (gitObjects.TryGetBlobSizeLocally(namedEntry.Sha, out blobLength)) { namedEntry.Size = blobLength; blobSizes[namedEntry.Sha] = blobLength; } else { entriesMissingSizes.Add(namedEntry); } } // Anything remaining should come from the remote. if (entriesMissingSizes.Count > 0) { Dictionary <string, long> objectLengths = gitObjects.GetFileSizes(entriesMissingSizes.Select(e => e.Sha).Distinct()).ToDictionary(s => s.Id, s => s.Size, StringComparer.OrdinalIgnoreCase); foreach (GitTreeEntry namedEntry in entriesMissingSizes) { long blobLength = 0; if (objectLengths.TryGetValue(namedEntry.Sha, out blobLength)) { namedEntry.Size = blobLength; blobSizes[namedEntry.Sha] = blobLength; } else { EventMetadata metadata = new EventMetadata(); metadata.Add("ErrorMessage", "GvFltException: Failed to download size for: " + namedEntry.Name + ", SHA: " + namedEntry.Sha); context.Tracer.RelatedError(metadata, Keywords.Network); throw new GvFltException(StatusCode.StatusFileNotAvailable); } } } }
private string GetPersistedDiskLayoutVersion() { using (PersistentDictionary <string, string> dictionary = new PersistentDictionary <string, string>( Path.Combine(this.Enlistment.DotGVFSRoot, RepoMetadataDatabaseName))) { string value; if (dictionary.TryGetValue(DiskLayoutVersionKey, out value)) { return(value); } return(null); } }
public static string GetPersistedDiskLayoutVersion(string dotGVFSRoot) { using (PersistentDictionary <string, string> dictionary = new PersistentDictionary <string, string>( Path.Combine(dotGVFSRoot, RepoMetadataDatabaseName))) { string value; if (dictionary.TryGetValue(DiskLayoutVersionKey, out value)) { return(value); } return(null); } }
public static bool CheckDiskLayoutVersion(PersistentDictionary <string, string> repoMetadata, out string error) { error = string.Empty; string value; if (repoMetadata.TryGetValue(DiskLayoutVersionKey, out value)) { int persistedVersionNumber; if (!int.TryParse(value, out persistedVersionNumber)) { error = "Failed to parse persisted disk layout version number"; return(false); } if (persistedVersionNumber < MinDiskLayoutVersion) { error = string.Format( "Breaking change to GVFS disk layout has been made since cloning. \r\nEnlistment disk layout version: {0} \r\nGVFS disk layout version: {1} \r\nMinimum supported version: {2}", persistedVersionNumber, CurrentDiskLayoutVerion, MinDiskLayoutVersion); return(false); } else if (persistedVersionNumber > MaxDiskLayoutVersion) { error = string.Format( "Changes to GVFS disk layout do not allow mounting after downgrade. Try mounting again using a more recent version of GVFS. \r\nEnlistment disk layout version: {0} \r\nGVFS disk layout version: {1}", persistedVersionNumber, CurrentDiskLayoutVerion); return(false); } } else { error = MissingVersionError; return(false); } return(true); }
public static bool TryGetOnDiskLayoutVersion(PersistentDictionary <string, string> repoMetadata, out int version, out string error) { version = -1; error = string.Empty; string value; if (repoMetadata.TryGetValue(DiskLayoutVersionKey, out value)) { if (!int.TryParse(value, out version)) { error = "Failed to parse persisted disk layout version number: " + value; return(false); } } else { error = MissingVersionError; return(false); } return(true); }
/// <summary> /// Обновляет статистику сервера, основываясь на информации о новом матче /// </summary> /// <param name="endpoint">Уникальный идентификатор сервера</param> /// <param name="timestamp">Временная метка окончания матча</param> /// <param name="info">Информация о матче</param> private void CalcStats(string endpoint, string timestamp, MatchInfo info) { var time = timestamp.ToUtc(); ServerStats oldStats; if (!_stats.TryGetValue(endpoint, out oldStats)) { oldStats = new ServerStats { LastMatchDay = time.Date, PublicStats = new PublicServerStats() }; } var newStats = oldStats.CalcNew(time, info); var serverName = _servers[endpoint].Name; newStats.PublicStats = oldStats.PublicStats.CalcNew(info, newStats); UpdateRecentMatchesReport(endpoint, timestamp, info); UpdatePopularServersReport(serverName, endpoint, newStats.PublicStats); _stats[endpoint] = newStats; }
/// <inheritdoc /> public override bool TryGetValue(string key, out Target value) { return(index.TryGetValue(key, out value)); }