/// <summary> /// Get a previously added content type handler /// </summary> /// <param name="contentType">The Accept header value that identifies the handler</param> /// <returns>The deserializer that can handle the given content type.</returns> /// <remarks> /// This function returns NULL if the handler for the given content type cannot be found. /// </remarks> public IDeserializer GetHandler(string contentType) { if (string.IsNullOrEmpty(contentType) && _contentHandlers.ContainsKey("*")) { return(_contentHandlers["*"]); } if (contentType == null) { contentType = string.Empty; } var semicolonIndex = contentType.IndexOf(';'); if (semicolonIndex != -1) { contentType = contentType.Substring(0, semicolonIndex).TrimEnd(); } if (_contentHandlers.ContainsKey(contentType)) { return(_contentHandlers[contentType]); } if (_contentHandlers.ContainsKey("*")) { return(_contentHandlers["*"]); } return(null); }
private void AddActiveTransfer(string key, TransferFileProgressArgs value) { bool contains = ActiveTransfers.ContainsKey(key); if (!contains) { ActiveTransfers.Add(key, value); } }
public void ObservableDictionary() { var list = new ObservableDictionary() { "hello" }; list.Add("world"); list["yo"] = "heyy"; list.Add("saturn"); list.Add("pluto"); Assert.IsTrue(list.ContainsKey(0)); Assert.IsTrue(list.ContainsKey(1)); Assert.IsTrue(list.ContainsKey("yo")); Assert.IsTrue(list.ContainsKey(3)); Assert.IsTrue(list.ContainsKey(4)); list.Remove(3); list.Remove(4); list.Add("hello there"); Assert.AreEqual(4, list.Count); Assert.IsTrue(list.ContainsKey(0)); Assert.IsTrue(list.ContainsKey(1)); Assert.IsTrue(list.ContainsKey("yo")); Assert.IsTrue(list.ContainsKey(3)); }
public void ObservableDictionaryMultipleRedoCutoff(ObservableDictionary <int, int> dict) { // ARRANGE EnvironmentSettings.AlwaysSuppressCurrentSynchronizationContext = true; dict.Add( 15, 15); dict.Add( 89, 89); dict.Add( 3, 3); dict.Add( 2, 2); dict.Add( 57, 57); // ACT dict.Undo(); dict.Undo(); dict.Undo(); dict.Redo(); dict.Add( 74, 74); dict.Redo(); dict.Redo(); dict.Redo(); // ASSERT Assert.True( dict.ContainsKey(3), "Element not found: 3"); Assert.False( dict.ContainsKey(57), "Element found: 57"); Assert.False( dict.ContainsKey(2), "Element found: 2"); Assert.True( dict.ContainsKey(74), "Element not found: 74"); }
private async Task LoadDataFromRuntimeLocationTrack() { foreach (var vplace in Util.UserProfileData.ProbableVisitedPlaces) { if (!VisitedPlaces.ContainsKey(vplace.UniqueId)) { VisitedPlaces[vplace.UniqueId] = vplace; (VisitedPlaces[vplace.UniqueId] as Place).DisplayName = (VisitedPlaces[vplace.UniqueId] as Place).Address; ProbableVisitedPlaces.Insert(0, VisitedPlaces[vplace.UniqueId] as Place); //refresh the map to show best possible route await ShowBestPossibleRoutes(); } } }
public int Add(ItemTypeObject type, int quantity) { var availableSpace = AvailableSpace(type); var dropQuantity = availableSpace < quantity ? availableSpace : quantity; if (_items.ContainsKey(type)) { _items[type].Drop(dropQuantity); } else { _items.Add(type, new ItemViewModel(type, dropQuantity)); } return(quantity - dropQuantity); }
/// <summary> /// Converti un Jtoken en une ObservableDictionary /// </summary> /// <param name="jTokenOeuvre">Le JToken à convertir</param> /// <returns>L'ObservableDictionary convertie</returns> private static ObservableDictionary <StringVérifié, StringVérifié> JTokenVersObservableDictionnaryString(JToken jTokenCollectionOeuvres) { var dictionnaryRetour = new ObservableDictionary <StringVérifié, StringVérifié>(); foreach (JObject j in jTokenCollectionOeuvres["infos"]) { //On vérifie qu'il n'y ait pas plusieurs informations avec le même nom if (dictionnaryRetour.ContainsKey(new StringVérifié((string)j["nomInfo"]))) { int i = 0; //Si le nom de l'information est trop grand if (new StringVérifié($"{(string)j["nomInfo"]} {i}").LeString.Length > 16) { while (dictionnaryRetour.ContainsKey(new StringVérifié($"Inconnu {i}"))) { i++; } dictionnaryRetour.Add(new StringVérifié($"Inconnu {i}"), new StringVérifié((string)j["lInfo"])); continue; } while (dictionnaryRetour.ContainsKey(new StringVérifié($"{(string)j["nomInfo"]} {i}"))) { i++; } //Si le nom de l'information est trop grand if (new StringVérifié($"{(string)j["nomInfo"]} {i}").LeString.Length > 16) { i = 0; while (dictionnaryRetour.ContainsKey(new StringVérifié($"Inconnu {i}"))) { i++; } dictionnaryRetour.Add(new StringVérifié($"Inconnu {i}"), new StringVérifié((string)j["lInfo"])); continue; } dictionnaryRetour.Add(new StringVérifié($"{(string)j["nomInfo"]} {i}"), new StringVérifié((string)j["lInfo"])); } else { dictionnaryRetour.Add(new StringVérifié((string)j["nomInfo"]), new StringVérifié((string)j["lInfo"])); } } return(dictionnaryRetour); }
public void ContainsKeyTest() { var dic = new ObservableDictionary <int, string>(); dic.Add(1, "1"); dic.ContainsKey(1).Should().BeTrue(); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Length < 2) { return(null); } if (values[0] == null) { return(null); } ObservableDictionary <GraphNodeVM, Point> nodes = values[0] as ObservableDictionary <GraphNodeVM, Point>; if (nodes == null) { return(null); } if (values[1] == null) { return(null); } GraphNodeVM node = values[1] as GraphNodeVM; if (node == null) { return(null); } if (!nodes.ContainsKey(node)) { return(null); } return(nodes[node]); }
public void ObservableDictionaryRedoAtClear(ObservableDictionary <int, int> dict) { // ARRANGE EnvironmentSettings.AlwaysSuppressCurrentSynchronizationContext = true; dict.Clear(); dict.Undo(); Assert.True( dict.ContainsKey(1), "Element not found: 1"); Assert.True( dict.ContainsKey(7), "Element not found: 7"); Assert.True( dict.ContainsKey(19), "Element not found: 19"); Assert.True( dict.ContainsKey(23), "Element not found: 23"); Assert.True( dict.ContainsKey(4), "Element not found: 4"); // ACT dict.Redo(); // ASSERT Assert.False( dict.ContainsKey(1), "Element found: 1"); Assert.False( dict.ContainsKey(7), "Element found: 7"); Assert.False( dict.ContainsKey(19), "Element found: 19"); Assert.False( dict.ContainsKey(23), "Element found: 23"); Assert.False( dict.ContainsKey(4), "Element found: 4"); }
public void ObservableDictionaryTest4() { var dic = new ObservableDictionary <string, string>(1, StringComparer.OrdinalIgnoreCase) { { "a", "1" } }; dic.ContainsKey("A").Should().BeTrue(); }
public void ObservableDictionaryUndoAtRemove(ObservableDictionary <int, int> dict) { // ARRANGE EnvironmentSettings.AlwaysSuppressCurrentSynchronizationContext = true; // ACT _ = dict.Remove(7); Assert.False( dict.ContainsKey(7), "Element found: 7"); dict.Undo(); // ASSERT Assert.True( dict.ContainsKey(7), "Element not found: 7"); }
private void showStatisticalInfo() { if (defaultViewModel.ContainsKey(GradesTrend)) { TotalCreditsTextBlock.Text = string.Format("总学分:{0}", Term.statistics[0]); AveragePointsTextBlock.Text = string.Format("平均绩点:{0:F}", Term.statistics[1] / Term.statistics[0]); CommanCognitionTextBlock.Text = string.Format("通识总学分(不包括通核、新生研讨课、学科导论){0},其中人文社科组{1}学分", Term.statistics[2], Term.statistics[3]); } }
public void ObservableDictionaryTest1() { var dic0 = new Dictionary <string, string>() { { "a", "1" } }; var dic = new ObservableDictionary <string, string>(dic0); dic.ContainsKey("a").Should().BeTrue(); }
/// <summary> /// <para>Loads all <see cref="TaskPlugin"/>s that are not found or enabled in settings</para> /// </summary> private void Refresh() { ObservableDictionary <string, bool> plugins = TaskOptions.GetPluginsSetting(); List <Type> types = new List <Type>(this.TaskPluginsAvailable); types = types.FindAll(new Predicate <Type>(item => { return(!plugins.ContainsKey(item.Name) || plugins[item.Name]); })); types.ForEach(new Action <Type>(item => loadTask(item))); }
public void AddMeasureAttributesWidths(Tuple <double, double, double> attributesWidths) { this.attributesWidths = attributesWidths; double maxClef = attributesWidths.Item1; double maxKey = attributesWidths.Item2; double maxTime = attributesWidths.Item3; sharedFractions.Add(-3, new FractionHelper(-3, 0)); sharedFractions.Add(-2, new FractionHelper(-2, maxClef)); sharedFractions.Add(-1, new FractionHelper(-1, maxKey + maxClef)); if (sharedFractions.ContainsKey(0)) { sharedFractions[0].Position = maxClef + maxKey + maxTime; } else { sharedFractions.Add(0, new FractionHelper(0, maxClef + maxKey + maxTime)); } }
/// <summary> /// Get a previously added content encoding handler /// </summary> /// <param name="encodingIds">The Accept-Encoding header value that identifies the handler</param> /// <returns>The handler that can decode the given content encoding.</returns> /// <remarks> /// This function returns NULL if the handler for the given content encoding cannot be found. /// </remarks> public IEncoding GetEncoding(IEnumerable <string> encodingIds) { if (encodingIds != null) { foreach (var encodingId in encodingIds) { if (_encodingHandlers.ContainsKey(encodingId)) { return(_encodingHandlers[encodingId]); } } } if (_encodingHandlers.ContainsKey("*")) { return(_encodingHandlers["*"]); } return(null); }
public bool IsDeclared(string name) { VarAccessEventArgs eventArgs = new VarAccessEventArgs(); OnVarAccess(eventArgs); if (eventArgs.IsInstanced) { string instancedName = VarNameToInstancedName(name, eventArgs); for (string stepName = instancedName; stepName.IndexOf(RepeatedSuffix) >= 0; stepName = stepName.Substring(0, stepName.LastIndexOf(RepeatedSuffix))) { if (variables.ContainsKey(stepName)) { return(true); } } } return(variables.ContainsKey(name)); }
public void AddFilterProperty(string key, string value) { // If key doesn't exist, add it and a new list if (!_FilterProperties.ContainsKey(key)) { _FilterProperties.Add(key, new List <string>()); } if (!_FilterProperties[key].Contains(value)) { _FilterProperties[key].Add(value); } }
public void ContainsKeyFalse() { var observableDictionary = new ObservableDictionary <int, int>() { { 1, 1 } }; var success = observableDictionary.ContainsKey(2); Assert.IsFalse(success); }
public void Setdictval(string key, object data) { if (observableDictionary.ContainsKey(key)) { int index = observableDictionary.Keys.ToList().IndexOf(key); observableDictionary[key] = data; //the obs dict does a weird remove and add thing... so i do too. object o = DictionaryValues[index]; DictionaryValues.RemoveAt(index); //DictionaryValues.Add(data); } }
private static async System.Threading.Tasks.Task ReceiveAsync(ClientWebSocket webSocket) { ArraySegment <Byte> buffer = new ArraySegment <byte>(new Byte[receiveChunkSize]); while (webSocket.State == WebSocketState.Open) { WebSocketReceiveResult result = null; using (var ms = new MemoryStream()) { do { result = await webSocket.ReceiveAsync(buffer, CancellationToken.None); if (result.MessageType == WebSocketMessageType.Close) { await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); } else { await ms.WriteAsync(buffer.Array, buffer.Offset, result.Count); } } while (!result.EndOfMessage); ms.Seek(0, SeekOrigin.Begin); if (result.MessageType == WebSocketMessageType.Text) { using (var reader = new StreamReader(ms, Encoding.UTF8)) { var content = await reader.ReadToEndAsync(); var type = JObject.Parse(content).SelectToken("$.Type").Value <string>(); if (type == "RoundTrip") { var rt = GetFirstInstance <RoundTrip>("Payload", content); if (roundtrips.ContainsKey(rt.EntryId)) { roundtrips[rt.EntryId] = rt; } else { roundtrips.Add(rt.EntryId, rt); } } } } } } }
public bool AddAnimation([NotNull] AnimationWrapper animation) { if (animation == null) { throw new ArgumentNullException(nameof(animation)); } if (_animationCache.ContainsKey(animation.Name)) { return(false); } _animationCache.Add(animation.Name, animation); return(true); }
private void ProcessDiscovResp(IPEndPoint endpoint, string machineName) { lock (locker) { if (peerDict.ContainsKey(machineName)) { peerDict[machineName] = new Peer(machineName, endpoint); } else { peerDict.Add(machineName, new Peer(machineName, endpoint)); } } }
private void AddProcessorOptionsForTable(string subTableName) { logger.Information($"Creating processors for subtable {subTableName}"); var subTable = baseTable.GetSubTable(subTableName); var tableType = subTable.GetString("~TYPE~", ""); logger.Information($"Subtable {subTableName} has a Dashboard type of '{tableType}'"); var selectedProcessors = new ObservableCollection <IViewProcessor>(GetSortedTableProcessorsForType(subTable, subTableName, tableType)); logger.Information($"Found {selectedProcessors.Count} applicable subprocessors for table '{subTableName}'"); if (!keyToMultiProcessorMap.ContainsKey(subTableName)) { keyToMultiProcessorMap.Add(subTableName, selectedProcessors); } }
private void Initialise() { var minerals = systemBodyInfo.Minerals; _mineralDeposits.Clear(); foreach (var kvp in minerals) { MineralSD mineral = _staticData.Minerals[kvp.Key]; if (!_mineralDeposits.ContainsKey(kvp.Key)) { _mineralDeposits.Add(kvp.Key, new PlanetMineralInfoVM(mineral.Name, kvp.Value)); } } OnPropertyChanged(nameof(MineralDeposits)); }
public void ContainsKeyShouldThrowDisposedExceptionAfterDisposal() { // given var observableDictionary = new ObservableDictionary <string, string>(); observableDictionary.Dispose(); // when Action action = () => { var value = observableDictionary.ContainsKey("One"); }; // then action.Should().Throw <ObjectDisposedException>(); }
public void ObservableDictionaryRedoAtAdd(ObservableDictionary <int, int> dict) { // ARRANGE EnvironmentSettings.AlwaysSuppressCurrentSynchronizationContext = true; dict.Add( 6, 6); Assert.True( dict.ContainsKey(6), "Element not found: 6"); dict.Undo(); Assert.False( dict.ContainsKey(6), "Element found: 6"); // ACT dict.Redo(); // ASSERT Assert.True( dict.ContainsKey(6), "Element not found: 6"); }
private LanguageEntry GetOrCreateLanguageEntry(string key) { LanguageEntry entry; if (languageResources.ContainsKey(key)) { entry = languageResources[key]; } else { entry = new LanguageEntry(); entry.Key = key; languageResources.Add(key, entry); } return(entry); }
public static ObservableDictionary<string, string> AsObservableDictionary(this ValidationResult result) { var dictionary = new ObservableDictionary<string, string>(); foreach (var item in result.ErrorList) { var key = item.Target.ToString(); var text = item.ErrorText; if (dictionary.ContainsKey(key)) { dictionary[key] = dictionary.Keys + Environment.NewLine + text; } else { dictionary[key] = text; } } return dictionary; }
public void AddLoginNameMarkupColor(out string loginName, out Color markupColor) { const string newuser = "******"; var i = 0; while (_userMarkupPropertiesDictionary.ContainsKey(newuser + i)) { i++; } loginName = newuser + i; markupColor = GetLoginNameMarkupColor(loginName); SetLoginNameMarkupColor(loginName, markupColor); }
private void cmdOnlineView_Click(object sender, RoutedEventArgs e) { try { var btn = sender as ToggleButton; if (btn.IsChecked.Value) { _connectionDictionary = new ObservableDictionary<string, PLCConnection>(); var conns = from rw in varTabRows group rw by rw.ConnectionName; foreach (var conn in conns) { if (!string.IsNullOrEmpty(conn.Key)) _connectionDictionary.Add(conn.Key, new PLCConnection(conn.Key)); } if (!string.IsNullOrEmpty(DefaultConnection) && !_connectionDictionary.ContainsKey(DefaultConnection)) _connectionDictionary.Add(DefaultConnection, new PLCConnection(DefaultConnection)); lblStatus.Content = ""; foreach (var varTabRowWithConnection in varTabRows) { //Register Notify Changed Handler vor <connected Property var conn = varTabRowWithConnection.Connection; if (conn != null) conn.Configuration.ConnectionName = conn.Configuration.ConnectionName; } Parallel.ForEach(_connectionDictionary, plcConnection => { try { plcConnection.Value.AutoConnect = false; plcConnection.Value.Connect(); } catch (Exception ex) { } }); var st = new ThreadStart(BackgroundReadingProc); BackgroundReadingThread = new Thread(st); BackgroundReadingThread.Name = "Background Reading Thread"; BackgroundReadingThread.Start(); ProgressBarOnlineStatus.IsIndeterminate = true; IsOnline = true; } else { this.StopOnlineView(); } } catch(Exception ex) { lblStatus.Content = ex.Message; } }
public void ContainsKeyShouldReturnTrueForExistingKey() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when var result = observableDictionary.ContainsKey(1); // then result.Should().Be(true); } }
public void ContainsKeyThrowsOnNullKey() { // given using (var observableDictionary = new ObservableDictionary<string, string>()) { // when Action retrieval = () => observableDictionary.ContainsKey((string)null); // then retrieval .ShouldThrow<ArgumentNullException>() .WithMessage("Value cannot be null.\r\nParameter name: key"); } }
public void ObservableDictionaryContainsKeyTest() { ObservableDictionary<GenericParameterHelper, GenericParameterHelper> target = new ObservableDictionary<GenericParameterHelper, GenericParameterHelper>(); KeyValuePair<GenericParameterHelper, GenericParameterHelper> itemAdded = new KeyValuePair<GenericParameterHelper, GenericParameterHelper>(new GenericParameterHelper(1), new GenericParameterHelper(1)); KeyValuePair<GenericParameterHelper, GenericParameterHelper> itemNotAdded = new KeyValuePair<GenericParameterHelper, GenericParameterHelper>(new GenericParameterHelper(2), new GenericParameterHelper(2)); target.Add(itemAdded); bool expectedAdded = true; bool expectedNotAdded = false; bool actualAdded = target.ContainsKey(new GenericParameterHelper(1)); bool actualNotAdded = target.ContainsKey(new GenericParameterHelper(2)); Assert.AreEqual(expectedAdded, actualAdded); Assert.AreEqual(expectedNotAdded, actualNotAdded); }