public void ReadOnlyDictionary_Basic() { Dictionary <string, string> dictionary = new Dictionary <string, string>(); IDictionary <string, string> readOnly; string value; readOnly = new ReadOnlyDictionary <string, string>(dictionary); Assert.IsTrue(readOnly.IsReadOnly); Assert.AreEqual(0, readOnly.Count); Assert.IsFalse(readOnly.ContainsKey("test")); Assert.IsFalse(readOnly.TryGetValue("test", out value)); dictionary.Add("foo", "bar"); dictionary.Add("hello", "world"); readOnly = new ReadOnlyDictionary <string, string>(dictionary); Assert.AreEqual(2, readOnly.Count); Assert.IsTrue(readOnly.ContainsKey("hello")); Assert.IsTrue(readOnly.TryGetValue("hello", out value)); Assert.AreEqual("world", value); Assert.AreEqual("world", readOnly["hello"]); readOnly = dictionary.ToReadOnly(); Assert.AreEqual(2, readOnly.Count); Assert.IsTrue(readOnly.ContainsKey("hello")); Assert.IsTrue(readOnly.TryGetValue("hello", out value)); Assert.AreEqual("world", value); Assert.AreEqual("world", readOnly["hello"]); }
public static ReadOnlyDictionary <MethodBase, MethodBase> MapInterfacesToImpls(this Type t, IEnumerable <Type> ifaces) { var map = new Dictionary <MethodBase, MethodBase>(); ifaces.ForEach(iface => map.AddElements(t.MapInterfacesToImpls(iface))); return(map.ToReadOnly()); }
public void AddWhenIsReadOnlyShouldThrowException() { Dictionary <int, string> testDict = new Dictionary <int, string>(2); testDict.ToReadOnly(); Assert.Throws <NotSupportedException>(() => testDict.Add(3, "c")); Assert.Equal(0, testDict.Count); }
static IReadOnlyDictionary <string, IReadOnlyList <string> > GetTraits(_IMethodInfo method) { var result = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); foreach (var traitAttribute in method.GetCustomAttributes(typeof(TraitAttribute))) { var ctorArgs = traitAttribute.GetConstructorArguments().ToList(); result.Add((string)ctorArgs[0] !, (string)ctorArgs[1] !); } return(result.ToReadOnly()); }
public void RemoveWhenPairAndIsReadOnlyShouldThrowException() { Dictionary <string, string> testDict = new Dictionary <string, string>(5); testDict.Add("a", "a"); testDict.Add("b", "b"); testDict.Add("c", "c"); testDict.ToReadOnly(); Assert.Throws <NotSupportedException>(() => testDict.Remove(new KeyValuePair <string, string>("c", "c"))); }
static IReadOnlyDictionary <string, IReadOnlyList <string> > GetTraits(MethodInfo method) { var result = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); foreach (var traitAttribute in method.GetCustomAttributesData().Where(cad => cad.AttributeType.IsAssignableFrom(typeof(TraitAttribute)))) { var ctorArgs = traitAttribute.ConstructorArguments.ToList(); result.Add((string)ctorArgs[0].Value !, (string)ctorArgs[1].Value !); } return(result.ToReadOnly()); }
public NullMouse() { var buttons = new Dictionary <MouseButton, IButton>(); foreach (MouseButton button in Enum.GetValues(typeof(MouseButton))) { if (button != MouseButton.None) { buttons.Add(button, NullButton.Instance); } } m_buttons = buttons.ToReadOnly(); }
public NullKeyboard() { var keys = new Dictionary <Key, IButton>(); foreach (Key key in Enum.GetValues(typeof(Key))) { if (key != Key.None) { keys.Add(key, NullButton.Instance); } } m_keys = keys.ToReadOnly(); }
public void ClearWhenIsReadOnlyShouldThrowException() { Dictionary <int, string> testDict = new Dictionary <int, string>(5); testDict.Add(1, "a"); testDict.Add(2, "b"); testDict.Add(3, "c"); testDict.ToReadOnly(); Assert.Throws <NotSupportedException>(() => testDict.Clear()); Assert.Equal(3, testDict.Count); }
public void IndexerWhenSetAndIsReadOnlyShouldThrowException() { Dictionary <int, string> testDict = new Dictionary <int, string>(5); testDict.Add(1, "a"); testDict.Add(2, "b"); testDict.Add(3, "c"); testDict.ToReadOnly(); Assert.Throws <NotSupportedException>(() => testDict[3] = "d"); Assert.Equal("c", testDict[3]); }
public static IReadOnlyDictionary <Type, MessageType> GenerateNetworkIds(this IEnumerable <Type> networkMessageTypes) { var networkMessages = networkMessageTypes .OrderBy(type => type.FullName); var messageTypes = new Dictionary <Type, MessageType>(); var messageId = 0u; foreach (var networkMessageType in networkMessages) { messageTypes.Add(networkMessageType, new MessageType(messageId)); messageId++; } return(messageTypes.ToReadOnly()); }
public SDL2Mouse(SDL2Window window) { m_window = window; m_buttons = new Dictionary <MouseButton, IButton>(); m_buttonsReadOnly = m_buttons.ToReadOnly(); foreach (MouseButton button in Enum.GetValues(typeof(MouseButton))) { if (button != MouseButton.None) { m_buttons.Add(button, new SimpleButton()); } } m_hadMouseFocus = false; Update(); }
public static ReadOnlyDictionary<MethodBase, MethodBase> MapInterfacesToImpls(this Type t, Type iface) { if (t == null || iface == null) return null; return _if2imCache.GetOrCreate(Tuple.Create(t, iface), () => { var map = t.GetInterfaceMap(iface); var res = new Dictionary<MethodBase, MethodBase>(); for (var i = 0; i < map.TargetMethods.Length; i++) { res.Add(map.InterfaceMethods[i], map.TargetMethods[i]); } return res.ToReadOnly(); }); }
public SDL2Keyboard(SDL2Window window) { m_window = window; m_keys = new Dictionary <Key, IButton>(); m_keysReadOnly = m_keys.ToReadOnly(); m_text = ""; m_pendingText = new StringBuilder(); foreach (Key key in Enum.GetValues(typeof(Key))) { if (key != Key.None) { m_keys.Add(key, new SimpleButton()); } } m_hadFocus = false; Update(); }
public void ToReadOnly() { IDictionary <int, string> intStringDictionary = new Dictionary <int, string>() { { 1, "111" }, { 2, "222" }, { 3, "333" }, }; IDictionary <string, int> stringIntDictionary = new Dictionary <string, int>() { { "111", 1 }, { "222", 2 }, { "333", 3 }, }; Assert.NotNull(intStringDictionary.ToReadOnly()); Assert.NotNull(stringIntDictionary.ToReadOnly()); }
public static ReadOnlyDictionary <MethodBase, MethodBase> MapInterfacesToImpls(this Type t, Type iface) { if (t == null || iface == null) { return(null); } return(_if2imCache.GetOrCreate(Tuple.Create(t, iface), () => { var map = t.GetInterfaceMap(iface); var res = new Dictionary <MethodBase, MethodBase>(); for (var i = 0; i < map.TargetMethods.Length; i++) { res.Add(map.InterfaceMethods[i], map.TargetMethods[i]); } return res.ToReadOnly(); })); }
public SteamController(SteamControllerCollection owner, IWindow window, ControllerHandle_t handle) { m_owner = owner; m_window = window; m_handle = handle; // Buttons m_buttons = new Dictionary <string, IButton>(); m_buttonsReadOnly = m_buttons.ToReadOnly(); foreach (string name in m_owner.DigitalActionNames) { m_buttons.Add(name, new SimpleButton()); } // Axes m_axes = new Dictionary <string, IAxis>(); m_axesReadOnly = m_axes.ToReadOnly(); foreach (string name in m_owner.AnalogTriggerActionNames) { m_axes.Add(name, new SimpleAxis()); } // Joysticks m_joysticks = new Dictionary <string, IJoystick>(); m_joysticksReadOnly = m_joysticks.ToReadOnly(); foreach (string name in m_owner.AnalogActionNames) { m_joysticks.Add(name, new SimpleJoystick()); } // State m_connected = true; App.Log("Steam controller connected"); // Set initial action set m_currentActionSet = m_owner.ActionSetNames.First(); global::Steamworks.SteamController.ActivateActionSet(m_handle, m_owner.GetActionSetHandle(m_currentActionSet)); // Get initial state Update(); }
private static Dictionary <string, string> voiceNameMap; // Maps friendly voice names to the internal name /// <summary> /// Starts the engine if it is not already running. /// </summary> /// <param name="settings">The engine settings.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="settings"/> is <c>null</c>.</exception> public static void Start(SpeechEngineSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } lock (syncLock) { if (SpeechEngine.isRunning) { return; } SpeechEngine.settings = settings; SpeechEngine.cache = new PhraseCache(settings); SpeechEngine.isRunning = true; // Create the default audio formats. format_8000KHz = new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Eight, AudioChannel.Mono); format_11025KHz = new SpeechAudioFormatInfo(11025, AudioBitsPerSample.Eight, AudioChannel.Mono); format_16000KHz = new SpeechAudioFormatInfo(16000, AudioBitsPerSample.Eight, AudioChannel.Mono); // Get the fully qualified paths to the error files. noVoicesPath = Path.Combine(CoreApp.InstallPath, "Audio", "NoVoicesError.wav"); synthErrorPath = Path.Combine(CoreApp.InstallPath, "Audio", "SpeechSynthError.wav"); // Enumerate the installed voices and select the default voice. // // Note: The Microsoft Speech Platform voices have really clunky names like: // // "Microsoft Server Speech Text to Speech Voice (en-AU, Hayley)" // // I'm going to simplify these to be just "Microsoft <name>" and maintain // a table that maps back to the original name. voiceNameMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); using (var synth = new SpeechSynthesizer()) { var voices = new Dictionary <string, VoiceInfo>(StringComparer.OrdinalIgnoreCase); foreach (var voice in synth.GetInstalledVoices()) { var voiceName = voice.VoiceInfo.Name; if (!voice.Enabled) { continue; } // $hack(jeff.lill): // // Make sure that the voice can actually be used. I've run into // situations where [Microsoft Anna] was present and enabled but // could not be selected. I believe this may be a 64-bit issue // or perhaps installing Cepstral voices messes with Anna. try { synth.SelectVoice(voice.VoiceInfo.Name); } catch { continue; } if (voiceName.StartsWith("Microsoft Server Speech Text to Speech Voice (")) { int p = voiceName.IndexOf(','); if (p != -1) { voiceName = voiceName.Substring(p + 1); voiceName = "Microsoft " + voiceName.Replace(")", string.Empty).Trim(); voiceNameMap[voiceName] = voice.VoiceInfo.Name; } } voices.Add(voiceName, voice.VoiceInfo); } SpeechEngine.InstalledVoices = voices.ToReadOnly(); SpeechEngine.DefaultVoice = null; SpeechEngine.DefaultVoiceInfo = null; // First see if the desired default voice exists. if (!string.IsNullOrWhiteSpace(settings.DefaultVoice) && String.Compare(settings.DefaultVoice, "auto") != 0) { VoiceInfo voiceInfo; if (voices.TryGetValue(settings.DefaultVoice, out voiceInfo)) { SpeechEngine.DefaultVoice = voiceInfo.Name; } else { SysLog.LogWarning("[SpeechEngine] was not able to locate the requested default voice [{0}]. Another voice will be selected automatically.", settings.DefaultVoice); } } // If not look for an alternative if (SpeechEngine.DefaultVoice == null) { if (voices.ContainsKey("Microsoft Helen")) { SpeechEngine.DefaultVoice = "Microsoft Helen"; } else if (voices.ContainsKey("Microsoft Anna")) { SpeechEngine.DefaultVoice = "Microsoft Anna"; } else { SysLog.LogWarning("[SpeechEngine] was not able to locate the [Microsoft Anna] voice."); var v = voices.Keys.FirstOrDefault(); if (v == null) { SpeechEngine.DefaultVoice = null; SysLog.LogError("[SpeechEngine] was not able to locate any speech synthesis voices. Speech synthesis will be disabled."); } else { SpeechEngine.DefaultVoice = v; } } } if (SpeechEngine.DefaultVoice != null) { SpeechEngine.DefaultVoiceInfo = SpeechEngine.InstalledVoices[GetVoice(SpeechEngine.DefaultVoice)]; } } } }
public SDL2Gamepad(SDL2Window window, int joystickIndex) { m_window = window; m_joystickIndex = joystickIndex; m_gameController = SDL.SDL_GameControllerOpen(m_joystickIndex); m_joystick = SDL.SDL_GameControllerGetJoystick(m_gameController); m_instanceID = SDL.SDL_JoystickInstanceID(m_joystick); m_name = SDL.SDL_GameControllerName(m_gameController); m_joystickName = SDL.SDL_JoystickName(m_joystick); DetectType(); // Lets get ready to rumple m_haptic = SDL.SDL_HapticOpenFromJoystick(m_joystick); if (m_haptic != IntPtr.Zero) { if (SDL.SDL_HapticRumbleSupported(m_haptic) == (int)SDL.SDL_bool.SDL_FALSE || SDL.SDL_HapticRumbleInit(m_haptic) < 0) { SDL.SDL_HapticClose(m_haptic); m_haptic = IntPtr.Zero; } } // Axes m_axes = new Dictionary <GamepadAxis, IAxis>(); m_axesReadOnly = m_axes.ToReadOnly(); foreach (GamepadAxis axis in Enum.GetValues(typeof(GamepadAxis))) { if (axis != GamepadAxis.None) { var simpleAxis = new SimpleAxis(); switch (axis) { case GamepadAxis.LeftStickX: case GamepadAxis.LeftStickY: { simpleAxis.DeadZone = 0.239f; // Derived from XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE break; } case GamepadAxis.RightStickX: case GamepadAxis.RightStickY: { simpleAxis.DeadZone = 0.265f; // Derived from XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE break; } case GamepadAxis.LeftTrigger: case GamepadAxis.RightTrigger: { simpleAxis.DeadZone = 0.117f; // Derived from XINPUT_GAMEPAD_TRIGGER_THRESHOLD break; } } m_axes.Add(axis, simpleAxis); } } // Buttons m_buttons = new Dictionary <GamepadButton, IButton>(); m_buttonsReadOnly = m_buttons.ToReadOnly(); foreach (GamepadButton button in Enum.GetValues(typeof(GamepadButton))) { if (button != GamepadButton.None && !button.IsVirtual()) { m_buttons.Add(button, new SimpleButton()); } } m_buttons.Add(GamepadButton.LeftStickUp, new AxisButton(m_axes[GamepadAxis.LeftStickY], -0.5f)); m_buttons.Add(GamepadButton.LeftStickDown, new AxisButton(m_axes[GamepadAxis.LeftStickY], 0.5f)); m_buttons.Add(GamepadButton.LeftStickLeft, new AxisButton(m_axes[GamepadAxis.LeftStickX], -0.5f)); m_buttons.Add(GamepadButton.LeftStickRight, new AxisButton(m_axes[GamepadAxis.LeftStickX], 0.5f)); m_buttons.Add(GamepadButton.RightStickUp, new AxisButton(m_axes[GamepadAxis.RightStickY], -0.5f)); m_buttons.Add(GamepadButton.RightStickDown, new AxisButton(m_axes[GamepadAxis.RightStickY], 0.5f)); m_buttons.Add(GamepadButton.RightStickLeft, new AxisButton(m_axes[GamepadAxis.RightStickX], -0.5f)); m_buttons.Add(GamepadButton.RightStickRight, new AxisButton(m_axes[GamepadAxis.RightStickX], 0.5f)); m_buttons.Add(GamepadButton.LeftTrigger, new AxisButton(m_axes[GamepadAxis.LeftTrigger], 0.6f)); // Sometimes buggy triggers idle at 0.5, using 0.6 ensures we don't use these values m_buttons.Add(GamepadButton.RightTrigger, new AxisButton(m_axes[GamepadAxis.RightTrigger], 0.6f)); // Sometimes buggy triggers idle at 0.5, using 0.6 ensures we don't use these values // Joysticks m_joysticks = new Dictionary <GamepadJoystick, IJoystick>(); m_joysticksReadOnly = m_joysticks.ToReadOnly(); m_joysticks.Add(GamepadJoystick.Left, new TwoAxisJoystick(m_axes[GamepadAxis.LeftStickX], m_axes[GamepadAxis.LeftStickY])); m_joysticks.Add(GamepadJoystick.Right, new TwoAxisJoystick(m_axes[GamepadAxis.RightStickX], m_axes[GamepadAxis.RightStickY])); // State m_connected = true; App.Log("{0} controller connected ({1}, {2})", m_type, m_name, m_joystickName); if (m_haptic != IntPtr.Zero) { App.Log("Rumble supported"); } Update(); }
public static ReadOnlyDictionary<MethodBase, MethodBase> MapInterfacesToImpls(this Type t, IEnumerable<Type> ifaces) { var map = new Dictionary<MethodBase, MethodBase>(); ifaces.ForEach(iface => map.AddElements(t.MapInterfacesToImpls(iface))); return map.ToReadOnly(); }
/// <summary> /// Capture all of the current Order Data /// </summary> /// <returns></returns> public ImmutableOrderData cloneFormOrderData(string orderNum) { Func<string, bool> queryTestSent = test => getSqlServer .asBoolOption(string.Format("SELECT [hl7Sent] FROM [downtime].[dbo].[ordersWithTests] where ordernumber = '{0}' and test = '{1}'", orderNum, test)) .getOrElse(() => false); var testsToOrder = new Dictionary<DataRow, bool>(); this.orderedTests.forEach(x => testsToOrder.Add(x, queryTestSent.Invoke(x["Id"].ToString()))); return new ImmutableOrderData(orderNum, collectiontime.Text, receivetime.Text, comboBoxWard.Text, ComboBoxPriority.Text, mrn.Text, DOB.Text, firstname.Text, problem.Text, cal1.Text, comment.Text, lastname.Text, TextBoxTechId.Text, TextBoxbillingnumber.Text,this.TextboxCollectDate.Text, testsToOrder.ToReadOnly()); }