public UC_customKeystrokes() { InitializeComponent(); m_focusedListView = lW_triggerDown; m_identifier = Page.Keystrokes; m_next = Page.Gesture; m_previous = Page.Action; foreach (MyKey k in AllKeys.Ordinary) { lB_keys.Items.Add(k.KeyName); } foreach (MyKey k in AllKeys.Modifiers) { lB_modifiers.Items.Add(k.KeyName); } foreach (MyKey k in AllKeys.MouseActions) { lB_special.Items.Add(k.KeyName); } m_selectedKey = null; gB_modifiers.Text = Translation.GetText("C_CK_gB_modifiers"); gB_keys.Text = Translation.GetText("C_CK_gB_keys"); gB_mouseActions.Text = Translation.GetText("C_CK_gB_mouseActions"); btn_add.Text = Translation.GetText("C_CK_btn_add"); btn_remove.Text = Translation.GetText("C_CK_btn_remove"); gB_keyScript.Text = Translation.GetText("C_CK_gB_keyScript"); cH_holdBtn_down.Text = Translation.GetText("C_WK_cH_holdBtn_down"); cH_holdBtn_up.Text = Translation.GetText("C_WK_cH_holdBtn_up"); cH_wheelMove_down.Text = Translation.GetText("C_WK_cH_wheelMove_down"); cH_wheelMove_up.Text = Translation.GetText("C_WK_cH_wheelMove_up"); m_errMoreDownInline = Translation.GetText("C_CK_errMoreDownInline"); m_errMoreUpInline = Translation.GetText("C_CK_errMoreUpInline"); m_errDownWithoutUp = Translation.GetText("C_CK_errDownWithoutUp"); m_errOneMouseActionAllowed = Translation.GetText("C_CK_errOneMouseActionAllowed"); }
public void TestRehash() { // This map should rehash on adding the ninth element. HashMap <MyKey, Object> hm = new HashMap <MyKey, Object>(10, 0.5f); // Ordered set of keys. MyKey[] keyOrder = new MyKey[9]; for (int i = 0; i < keyOrder.Length; i++) { keyOrder[i] = new MyKey(); } // Store eight elements for (int i = 0; i < 8; i++) { hm.Put(keyOrder[i], i); } // Check expected ordering (inverse of adding order) MyKey[] returnedKeys = hm.KeySet().ToArray(); for (int i = 0; i < 8; i++) { Assert.AreSame(keyOrder[i], returnedKeys[7 - i]); } // The Next Put causes a rehash hm.Put(keyOrder[8], 8); // Check expected new ordering (adding order) returnedKeys = hm.KeySet().ToArray(); for (int i = 0; i < 9; i++) { Assert.AreSame(keyOrder[i], returnedKeys[i]); } }
private void listBox_SelectedIndexChanged(object sender, EventArgs e) { if (((ListBox)sender).SelectedIndex == -1) { return; } if (((ListBox)sender) == lB_modifiers) { lB_keys.SelectedIndex = -1; lB_special.SelectedIndex = -1; m_selectedKey = AllKeys.Modifiers[lB_modifiers.SelectedIndex]; } else if (((ListBox)sender) == lB_keys) { lB_modifiers.SelectedIndex = -1; lB_special.SelectedIndex = -1; m_selectedKey = AllKeys.Ordinary[lB_keys.SelectedIndex]; } else if (((ListBox)sender) == lB_special) { lB_keys.SelectedIndex = -1; lB_modifiers.SelectedIndex = -1; m_selectedKey = AllKeys.MouseActions[lB_special.SelectedIndex]; } }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: The key is a custom class and the value is char"); try { IDictionary iDictionary = new Dictionary<object,object>(); MyKey key = new MyKey(); char value = TestLibrary.Generator.GetCharLetter(-55); iDictionary.Add(key, value); if ((char)iDictionary[key] != value) { TestLibrary.TestFramework.LogError("003", "The result is not the value as expected "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return retVal; }
public void GetAuthenticatedEncryptorByKeyId_DefersInstantiation_AndReturnsRevocationInfo() { // Arrange var expectedEncryptorInstance1 = new Mock <IAuthenticatedEncryptor>().Object; var expectedEncryptorInstance2 = new Mock <IAuthenticatedEncryptor>().Object; var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance1, isRevoked: true); var key2 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance2); // Act var keyRing = new KeyRing(key2, new[] { key1, key2 }); // Assert Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out var isRevoked)); Assert.True(isRevoked); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); Assert.True(isRevoked); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Equal(0, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked)); Assert.False(isRevoked); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked)); Assert.False(isRevoked); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); }
public ActionResult UserTornado(string Location, DateTime?StartDate = null, DateTime?EndDate = null) { MyKey key = new MyKey(); string APIkey = key.GetKey(); string APIText = $"https://maps.googleapis.com/maps/api/geocode/json?components=" + $"locality:{Location}|country:US&key={APIkey}"; HttpWebRequest request = WebRequest.CreateHttp(APIText); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader rd = new StreamReader(response.GetResponseStream()); string data = rd.ReadToEnd(); rd.Close(); JToken UserLocation = JToken.Parse(data); List <JToken> ParsedLocation = UserLocation["results"].ToList(); if (ParsedLocation.Count == 0) { ViewBag.TitleError = "Wrong Country"; ViewBag.Error = "You gave a country out of bounds!"; return(View("Error")); } ViewBag.Address = ParsedLocation[0]["formatted_address"].ToString(); ViewBag.UserLat = ParsedLocation[0]["geometry"]["location"]["lat"].ToString(); ViewBag.UserLong = ParsedLocation[0]["geometry"]["location"]["lng"].ToString(); UserLocation User = new UserLocation(); string latitude = ParsedLocation[0]["geometry"]["location"]["lat"].ToString(); float.TryParse(latitude, out float UserLat); string longitude = ParsedLocation[0]["geometry"]["location"]["lng"].ToString(); float.TryParse(longitude, out float UserLong); User.Location = ParsedLocation[0]["formatted_address"].ToString(); User.Latitude = UserLat; User.Longitude = UserLong; Session["UserInfo"] = User; if (!StartDate.HasValue) { StartDate = DateTime.Now; } if (!EndDate.HasValue) { EndDate = DateTime.Now.AddDays(0.1); } //maybe change this later - not certain how we want to calculate risk if they just want to see a specific location. //DateTime date = StartDate; TimeSpan userTime = (DateTime)EndDate - (DateTime)StartDate; int userMonth = StartDate.Value.Month; //code to grab the month out of the StartDate - what will we do if the user selects multiple months? Session["UserTime"] = userTime; return(View()); }
public void DebugDraw() { Vector3?prePosition = null; for (int i = 0; i < Keys.Count - 1; i++) { MyKey key0 = Keys[(int)MathHelper.Clamp(i - 1, 0, Keys.Count - 1)]; MyKey key1 = Keys[(int)MathHelper.Clamp(i, 0, Keys.Count - 1)]; MyKey key2 = Keys[(int)MathHelper.Clamp(i + 1, 0, Keys.Count - 1)]; MyKey key3 = Keys[(int)MathHelper.Clamp(i + 2, 0, Keys.Count - 1)]; MyDebugDraw.DrawAxis(Matrix.CreateTranslation(key1.Position), 10, 1); int steps = 50; for (int j = 0; j < steps; j++) { float amount = 1.0f * j / steps; Vector3 position = new Vector3( MathHelper.CatmullRom(key0.Position.X, key1.Position.X, key2.Position.X, key3.Position.X, amount), MathHelper.CatmullRom(key0.Position.Y, key1.Position.Y, key2.Position.Y, key3.Position.Y, amount), MathHelper.CatmullRom(key0.Position.Z, key1.Position.Z, key2.Position.Z, key3.Position.Z, amount)); if (prePosition.HasValue) { MyDebugDraw.DrawLine3D(prePosition.Value, position, Color.Orange, Color.Orange); } prePosition = position; } } MyDebugDraw.DrawAxis(Matrix.CreateTranslation(Keys[Keys.Count - 1].Position), 10, 1); }
public static object ReadReg(string AppName, string ValueName) { RegistryKey MyKey; try { MyKey = Registry.CurrentUser.OpenSubKey("Software\\" + AppName, RegistryKeyPermissionCheck.ReadWriteSubTree); if (MyKey == null) { throw new NullReferenceException(); } } catch { MyKey = Registry.CurrentUser.CreateSubKey("Software\\" + AppName, RegistryKeyPermissionCheck.ReadWriteSubTree); } try { object obj = MyKey.GetValue(ValueName); if (obj == null) { throw new Exception(); } return(obj); } catch { WriteRegStr(AppName, ValueName, false); object obj = MyKey.GetValue(ValueName); return(obj); } }
public void Run() { this.IsRunning = true; try { this.MyExecutor.Run(this.MyName, this.MyKey, this.SqlDialect, this.ExportFileName, this.UseFs); if (Send) { List <string> files = new List <string>(); files.Add(ExportFileName); try { MyExecutor.SendFiles(files, MyKey.ToString()); MessageBox.Show("File sent successfully. (" + ExportFileName + ")"); } catch (Exception e) { MessageBox.Show("File was not sent successfully: " + e.Message); } } else { MessageBox.Show("Completed succesfully. Data are saved on disk! " + this.ExportFileName); } } catch (Exception ex) { string msg = ex.Message; Logger.Log(msg); MessageBox.Show(msg); } this.IsRunning = false; }
public void GetAuthenticatedEncryptorByKeyId_DefersInstantiation_AndReturnsRevocationInfo() { // Arrange var expectedEncryptorInstance1 = new Mock<IAuthenticatedEncryptor>().Object; var expectedEncryptorInstance2 = new Mock<IAuthenticatedEncryptor>().Object; var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance1, isRevoked: true); var key2 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance2); // Act var keyRing = new KeyRing(key2, new[] { key1, key2 }); // Assert bool isRevoked; Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); Assert.True(isRevoked); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked)); Assert.True(isRevoked); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Equal(0, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked)); Assert.False(isRevoked); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked)); Assert.False(isRevoked); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance2, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled); }
public UC_customKeystrokes() { InitializeComponent(); m_focusedListView = lW_triggerDown; m_identifier = Page.Keystrokes; m_next = Page.Gesture; m_previous = Page.Action; foreach (MyKey k in AllKeys.Ordinary) lB_keys.Items.Add(k.KeyName); foreach (MyKey k in AllKeys.Modifiers) lB_modifiers.Items.Add(k.KeyName); foreach (MyKey k in AllKeys.MouseActions) lB_special.Items.Add(k.KeyName); m_selectedKey = null; gB_modifiers.Text = Translation.GetText("C_CK_gB_modifiers"); gB_keys.Text = Translation.GetText("C_CK_gB_keys"); gB_mouseActions.Text = Translation.GetText("C_CK_gB_mouseActions"); btn_add.Text = Translation.GetText("C_CK_btn_add"); btn_remove.Text = Translation.GetText("C_CK_btn_remove"); gB_keyScript.Text = Translation.GetText("C_CK_gB_keyScript"); cH_holdBtn_down.Text = Translation.GetText("C_WK_cH_holdBtn_down"); cH_holdBtn_up.Text = Translation.GetText("C_WK_cH_holdBtn_up"); cH_wheelMove_down.Text = Translation.GetText("C_WK_cH_wheelMove_down"); cH_wheelMove_up.Text = Translation.GetText("C_WK_cH_wheelMove_up"); m_errMoreDownInline = Translation.GetText("C_CK_errMoreDownInline"); m_errMoreUpInline = Translation.GetText("C_CK_errMoreUpInline"); m_errDownWithoutUp = Translation.GetText("C_CK_errDownWithoutUp"); m_errOneMouseActionAllowed = Translation.GetText("C_CK_errOneMouseActionAllowed"); }
public void Connexion(string code, string nom, string mdp) // vérification de connexion login { // crée ou ouvre les sous dossier MyKey = Registry.CurrentUser.CreateSubKey("Software"); MyKey = MyKey.CreateSubKey("HEPL"); // choix du prochain sous dossier selon le code switch (code.Length) { case 2: MyKey = MyKey.CreateSubKey("Code_Company"); break; case 3: MyKey = MyKey.CreateSubKey("Code_Airport"); break; } // crée sous dossier du nom du code ou ouvre s'il existe deja MyKey = MyKey.CreateSubKey(code); // si utilisateur n'est pas enregistré if (MyKey.GetValue(nom) == null) { throw new Exception("Unknown user !"); } // si mot de passe ne correspond pas a valeur affectée à l'utilisateur if ((string)MyKey.GetValue(nom) != mdp) { throw new Exception("Incorrect password !"); } Image = (string)MyKey.GetValue("Image"); Ville = (string)MyKey.GetValue("Ville"); Nom = (string)MyKey.GetValue("Nom"); }
private void GetValues(float time, out Vector3 position, out Quaternion rotation) { int index = -1; foreach (var key in Keys) { if (key.Time < time) { ++index; } else { break; } } MyKey key0 = Keys[(int)MathHelper.Clamp(index - 1, 0, Keys.Count - 1)]; MyKey key1 = Keys[(int)MathHelper.Clamp(index, 0, Keys.Count - 1)]; MyKey key2 = Keys[(int)MathHelper.Clamp(index + 1, 0, Keys.Count - 1)]; MyKey key3 = Keys[(int)MathHelper.Clamp(index + 2, 0, Keys.Count - 1)]; float deltaTime = key2.Time - key1.Time; float amount = deltaTime > 0 ? (time - key1.Time) / deltaTime : 1; position = new Vector3( MathHelper.CatmullRom(key0.Position.X, key1.Position.X, key2.Position.X, key3.Position.X, amount), MathHelper.CatmullRom(key0.Position.Y, key1.Position.Y, key2.Position.Y, key3.Position.Y, amount), MathHelper.CatmullRom(key0.Position.Z, key1.Position.Z, key2.Position.Z, key3.Position.Z, amount)); rotation = Quaternion.Slerp(key1.Rotation, key2.Rotation, amount); }
private void buttonSort_Click(object sender, EventArgs e) { List <MyKey> listkey = new List <MyKey>(); listkey.Clear(); for (int i = 0; i < listBoxSave.Items.Count; i++) { MyKey keys = new MyKey(); listBoxSave.SelectedIndex = i; keys = (MyKey)listBoxSave.SelectedItem; listkey.Add(keys); } listkey.Sort(SortCompare); listBoxSave.Items.Clear(); for (int i = 0; i < listkey.Count; i++) { listBoxSave.Items.Add(listkey[i]); } listBoxShow.Items.Clear(); for (int i = 0; i < listBoxSave.Items.Count; i++) { MyKey keys = new MyKey(); listBoxSave.SelectedIndex = i; keys = (MyKey)listBoxSave.SelectedItem; listBoxShow.Items.Add(keys.myKeyShow); } listkey.Clear(); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: The key is a custom class and the value is char"); try { IDictionary iDictionary = new Dictionary <object, object>(); MyKey key = new MyKey(); char value = TestLibrary.Generator.GetCharLetter(-55); iDictionary.Add(key, value); if ((char)iDictionary[key] != value) { TestLibrary.TestFramework.LogError("003", "The result is not the value as expected "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e); retVal = false; } return(retVal); }
//点击列表进行修改 private void listBoxShow_SelectedIndexChanged(object sender, EventArgs e) { //暂停播放 musicPlayer.Ctlcontrols.pause(); //点击list时,读取该项的信息,显示修改按钮 if (listBoxShow.SelectedIndex == -1) { return; //防止无项目时出错 } listBoxSave.SelectedIndex = listBoxShow.SelectedIndex; mykey = (MyKey)listBoxSave.SelectedItem; numericMin.Value = mykey.timeMin; numericSec.Value = mykey.timeSec; numericMs.Value = mykey.timeMs; numericKeyCount.Value = mykey.keyCount; buttonDelete.Visible = true; buttonSort.Visible = true; buttonWriteToList.Visible = false; buttonRewrite.Visible = true; buttonCancelReWrite.Visible = true; checkBoxA.Checked = mykey.A; checkBoxD.Checked = mykey.D; checkBoxF.Checked = mykey.F; checkBoxJ.Checked = mykey.J; checkBoxK.Checked = mykey.K; checkBoxL.Checked = mykey.L; checkBoxS.Checked = mykey.S; checkBoxSem.Checked = mykey.Sem; checkBoxSpace.Checked = mykey.Space; }
public static void TestCustomDictionaryKey() { var key = new MyKey(1); var listingLevelNames = new Dictionary <MyKey, string>(); listingLevelNames.Add(key, "None"); Assert.AreEqual("{\"Value\":1}", Serialize(key, false), "Object serialized correctly."); Assert.AreEqual("{\"1\":\"None\"}", Serialize(listingLevelNames, false), "Custom dictionary serialized correctly."); }
static void Main(string[] args) { var dep = new MyKey(true); // also try passing this to cwt.Add ConditionalWeakTable<MyKey, MyKey> cwt = new ConditionalWeakTable<MyKey, MyKey>(); cwt.Add(new MyKey(true), dep); // try doing this 5 times f.ex. GC.Collect(GC.MaxGeneration); GC.WaitForFullGCComplete(); Console.WriteLine("Wait"); Console.ReadLine(); // Put a breakpoint here and inspect cwt to see that the IntPtr is still there }
public void testWeakHashMapCollect() { var map = CreateWeakMap(); var key2 = new MyKey(); map.Put(key2, new MyValue()); GC.Collect(); map = map.Clone(map.Size); AssertNotNull(map.Get(key2)); AssertEquals(1, map.Size); }
public void DefaultKeyId_Prop() { // Arrange var key1 = new MyKey(); var key2 = new MyKey(); // Act var keyRing = new KeyRing(key2, new[] { key1, key2 }); // Assert Assert.Equal(key2.KeyId, keyRing.DefaultKeyId); }
public void DefaultKeyIdAndEncryptor_IfDefaultKeyNotPresentInAllKeys() { // Arrange var key1 = new MyKey(); var key2 = new MyKey(); var key3 = new MyKey(expectedEncryptorInstance: new Mock <IAuthenticatedEncryptor>().Object); // Act var keyRing = new KeyRing(key3, new[] { key1, key2 }); // Assert Assert.Equal(key3.KeyId, keyRing.DefaultKeyId); Assert.Equal(key3.CreateEncryptor(), keyRing.GetAuthenticatedEncryptorByKeyId(key3.KeyId, out var _)); }
public void DefaultKeyIdAndEncryptor_IfDefaultKeyNotPresentInAllKeys() { // Arrange var key1 = new MyKey(); var key2 = new MyKey(); var key3 = new MyKey(expectedEncryptorInstance: new Mock<IAuthenticatedEncryptor>().Object); // Act var keyRing = new KeyRing(key3, new[] { key1, key2 }); // Assert bool unused; Assert.Equal(key3.KeyId, keyRing.DefaultKeyId); Assert.Equal(key3.CreateEncryptorInstance(), keyRing.GetAuthenticatedEncryptorByKeyId(key3.KeyId, out unused)); }
public void Nouveau(string code, string password, string password2, string login, string ville, string companyName) { if (!password.Equals(password2)) { throw new Exception("Incorrect password !"); } // crée ou ouvre les sous dossier MyKey = Registry.CurrentUser.CreateSubKey("Software"); MyKey = MyKey.CreateSubKey("HEPL"); // choix du prochain sous dossier selon le code switch (code.Length) { case 2: MyKey = MyKey.CreateSubKey("Code_Company"); break; case 3: MyKey = MyKey.CreateSubKey("Code_Airport"); break; } // crée sous dossier du nom du code ou ouvre s'il existe deja MyKey = MyKey.CreateSubKey(code); if ((string)MyKey.GetValue(login) == null) { MyKey.SetValue(login, password); } if ((string)MyKey.GetValue("Ville") == null) { MyKey.SetValue("Ville", ville); Ville = (string)MyKey.GetValue("Ville"); } if ((string)MyKey.GetValue("Nom") == null) { MyKey.SetValue("Nom", companyName); Nom = (string)MyKey.GetValue("Nom"); } if ((string)MyKey.GetValue("Image") == null) // on va chercher image { System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog { FileName = Directory.GetCurrentDirectory() }; // aussi dans Win32 if (dialog.ShowDialog() == DialogResult.OK) { MyKey.SetValue("Image", dialog.FileName); } Image = dialog.FileName; } }
public void Cache_matchesEqualKeyOfDifferentReference() { Func <MyKey, string> creator = (MyKey inputKey) => { return(inputKey.Data + "value"); }; int capacity = 7; var cache = new RecentItemsCache <MyKey, string>(capacity); // Two keys: equal in data/value but of different references var key1 = new MyKey(0); var key2 = new MyKey(0); AddNewItem <MyKey, string>(cache, key1, creator); GetExistingItem <MyKey, string>(cache, key2, creator); }
public void testWeakHashMap1() { var key1 = new MyKey(); var key2 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var map = new OpenWeakReferenceHashMap <MyKey, MyValue>(16); map.Put(key1, value1); map.Put(key2, value2); AssertEquals(value1, map.Get(key1)); AssertEquals(value2, map.Get(key2)); AssertEquals(2, map.Size); }
public void Cache_matchesKeyOfSameReference() { Func <MyKey, string> creator = (MyKey inputKey) => { return(inputKey.Data + "value"); }; int capacity = 7; var cache = new RecentItemsCache <MyKey, string>(capacity); // Keys have the same Reference var key1 = new MyKey(0); var key2 = key1; AddNewItem <MyKey, string>(cache, key1, creator); GetExistingItem <MyKey, string>(cache, key2, creator); }
public static void BrokenConcurrentDictionary () { const string msg = "Broken ConcurrentDictionary: https://bugzilla.xamarin.com/show_bug.cgi?id=6225"; var keyA = new MyKey(1); var keyB = new MyKey(1); var dict = new ConcurrentDictionary<MyKey, string>(1, 2); if (!dict.TryAdd(keyA, "a")) Fail(msg); string foundValue; if (!dict.TryGetValue(keyA, out foundValue) || foundValue != "a") Fail(msg); if (dict.TryGetValue(keyB, out foundValue)) Fail(msg); }
public void testWeakHashMap1() { var key1 = new MyKey(); var key2 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var map = new OpenWeakReferenceHashMap<MyKey, MyValue>(16); map.Put(key1, value1); map.Put(key2, value2); AssertEquals(value1, map.Get(key1)); AssertEquals(value2, map.Get(key2)); AssertEquals(2, map.Size); }
private static int SortCompare(MyKey p1, MyKey p2) { try { if (p1.timeMin == p2.timeMin) { if (p1.timeSec == p2.timeSec) { if (p1.timeMs < p2.timeMs) { return(-1); } else { return(1); } } else { if (p1.timeSec < p2.timeSec) { return(-1); } else { return(1); } } } else { if (p1.timeMin < p2.timeMin) { return(-1); } else { return(1); } } } catch (Exception exc) { MessageBox.Show("出现错误,ErrorCode:0X2004,ErrorInfo:" + exc); return(0); } }
public void testWeakPutIfAbsent() { var key1 = new MyKey(); var key2 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var map = new OpenWeakReferenceHashMap <MyKey, MyValue>(16); AssertEquals(null, map.Put(key1, value1)); AssertEquals(value1, map.Put(key1, value2)); AssertEquals(value2, map.Put(key1, value1)); AssertEquals(value1, map.PutIfAbsent(key1, value2)); AssertEquals(null, map.PutIfAbsent(key2, value2)); AssertEquals(value2, map.PutIfAbsent(key2, value1)); }
public void testWeakPutIfAbsent() { var key1 = new MyKey(); var key2 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var map = new OpenWeakReferenceHashMap<MyKey, MyValue>(16); AssertEquals(null, map.Put(key1, value1)); AssertEquals(value1, map.Put(key1, value2)); AssertEquals(value2, map.Put(key1, value1)); AssertEquals(value1, map.PutIfAbsent(key1, value2)); AssertEquals(null, map.PutIfAbsent(key2, value2)); AssertEquals(value2, map.PutIfAbsent(key2, value1)); }
public void DefaultAuthenticatedEncryptor_Prop_InstantiationIsDeferred() { // Arrange var expectedEncryptorInstance = new Mock<IAuthenticatedEncryptor>().Object; var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance); var key2 = new MyKey(); // Act var keyRing = new KeyRing(key1, new[] { key1, key2 }); // Assert Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); // should've been cached }
public void DefaultAuthenticatedEncryptor_Prop_InstantiationIsDeferred() { // Arrange var expectedEncryptorInstance = new Mock <IAuthenticatedEncryptor>().Object; var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance); var key2 = new MyKey(); // Act var keyRing = new KeyRing(key1, new[] { key1, key2 }); // Assert Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor); Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); // should've been cached }
public void Option() // on utilise pour changer le dossier de data { // crée ou ouvre les sous dossier MyKey = Registry.CurrentUser.CreateSubKey("Software"); MyKey = MyKey.CreateSubKey("HEPL"); FolderBrowserDialog fbd = new FolderBrowserDialog { SelectedPath = Directory.GetCurrentDirectory() }; if (fbd.ShowDialog() == DialogResult.OK) { MyKey.SetValue("Workplace", fbd.SelectedPath); } // récupération de la valeur WorkPlace = (string)MyKey.GetValue("Workplace"); }
private void Login_Click(object sender, RoutedEventArgs e) { var privateKey = PrivateKeyTextBox.Text.ToString(); if (!string.IsNullOrEmpty(privateKey)) { var account = new Nethereum.Web3.Accounts.Account(privateKey); if (account != null) { var myKey = new MyKey { PublicKey = account.Address, PrivateKey = privateKey }; GeneratorButton.Visibility = Visibility.Collapsed; LoginButton.Visibility = Visibility.Collapsed; BalanceContainer.Visibility = Visibility.Visible; string balance = BlockChainService.Instance.GetBalance(myKey.PublicKey).ToString(); BalanceTextBox.Text = !string.IsNullOrEmpty(balance) ? balance + " $" : "0 $"; GlobalVariables.isLogined = true; GlobalVariables.Key = myKey; onActivateAllScreen?.Invoke(); PublicKeyTextBox.Text = myKey.PublicKey; ErrorText.Content = "Login Success !!!"; PrivateKeyTextBox.IsReadOnly = true; ErrorText.Visibility = Visibility.Visible; } else { ErrorText.Visibility = Visibility.Visible; } } else { ErrorText.Visibility = Visibility.Visible; } }
public void Init() // on utilise le dossier courant (workplace) pour data { // crée ou ouvre les sous dossier MyKey = Registry.CurrentUser.CreateSubKey("Software"); MyKey = MyKey.CreateSubKey("HEPL"); // si aucune valeur existe pour Workplace on lui donne une valeur if ((string)MyKey.GetValue("Workplace") == null) { FolderBrowserDialog fbd = new FolderBrowserDialog { SelectedPath = Directory.GetCurrentDirectory() }; if (fbd.ShowDialog() == DialogResult.OK) { MyKey.SetValue("Workplace", fbd.SelectedPath); } } // récupération de la valeur WorkPlace = (string)MyKey.GetValue("Workplace"); }
public void testPutIfAbsent() { var key1 = new MyKey(); var key2 = new MyKey(); var key3 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var value3 = new MyValue(); var map = new OpenIdentityHashMap<MyKey, MyValue>(); AssertEquals(null, map.Put(key1, value1)); AssertEquals(value1, map.Put(key1, value2)); AssertEquals(value2, map.Put(key1, value1)); AssertEquals(null, map.Put(key3, value3)); AssertEquals(value1, map.PutIfAbsent(key1, value2)); AssertEquals(null, map.PutIfAbsent(key2, value2)); AssertEquals(value2, map.PutIfAbsent(key2, value1)); AssertEquals(value3, map.Put(key3, value2)); }
public void testPutIfAbsent() { var key1 = new MyKey(); var key2 = new MyKey(); var key3 = new MyKey(); var value1 = new MyValue(); var value2 = new MyValue(); var value3 = new MyValue(); var map = new OpenIdentityHashMap <MyKey, MyValue>(); AssertEquals(null, map.Put(key1, value1)); AssertEquals(value1, map.Put(key1, value2)); AssertEquals(value2, map.Put(key1, value1)); AssertEquals(null, map.Put(key3, value3)); AssertEquals(value1, map.PutIfAbsent(key1, value2)); AssertEquals(null, map.PutIfAbsent(key2, value2)); AssertEquals(value2, map.PutIfAbsent(key2, value1)); AssertEquals(value3, map.Put(key3, value2)); }
public void TestCustomComparer() { // Pass in a custom IEqualityComparer object to use for the keys var m = new Multimap <MyKey, int>(new MyKey()); //keyA and keyB should be considered to be the same var keyA = new MyKey() { ID = 1 }; var keyB = new MyKey() { ID = 1 }; m.Add(keyA, 1); m.Add(keyB, 2); Utilities.TestSequenceEqual(m[keyA], new[] { 1, 2 }); Utilities.TestSequenceEqual(m[keyB], new[] { 1, 2 }); // Make sure only one can be removed Assert.True(m.Remove(keyA)); Assert.False(m.Remove(keyB)); m.Add(keyA, 1); m.Add(keyB, 2); // Make sure only one can be removed, starting with keyB Assert.True(m.Remove(keyB)); Assert.False(m.Remove(keyA)); Assert.False(m.ContainsKey(keyA)); Assert.False(m.ContainsKey(keyB)); Assert.False(m[keyA].Any()); Assert.False(m[keyB].Any()); Assert.True(m.FindFirst(keyA) == 0); }
public Car(int x) { carKey = new MyKey(x); nazwa = "SuperCar" + x; }
private int CompareKeysByTime(MyKey a, MyKey b) { return a.Time.CompareTo(b.Time); }
public MyObject() { keyCount++; key = new MyKey(); key.key = keyCount; }
private void listBox_SelectedIndexChanged(object sender, EventArgs e) { if (((ListBox)sender).SelectedIndex == -1) return; if (((ListBox)sender) == lB_modifiers) { lB_keys.SelectedIndex = -1; lB_special.SelectedIndex = -1; m_selectedKey = AllKeys.Modifiers[lB_modifiers.SelectedIndex]; } else if (((ListBox)sender) == lB_keys) { lB_modifiers.SelectedIndex = -1; lB_special.SelectedIndex = -1; m_selectedKey = AllKeys.Ordinary[lB_keys.SelectedIndex]; } else if (((ListBox)sender) == lB_special) { lB_keys.SelectedIndex = -1; lB_modifiers.SelectedIndex = -1; m_selectedKey = AllKeys.MouseActions[lB_special.SelectedIndex]; } }
public static void ExecuteKeyInput(MyKey key) { Win32.INPUT[] input = CreateInput(key, key.KeyAction); Win32.SendInput((uint)input.Length, input, (int)System.Runtime.InteropServices.Marshal.SizeOf(input[0].GetType())); }
public static Win32.INPUT[] CreateInput(MyKey key, MyKey.Action action) { List<Win32.INPUT> inputRange; Win32.INPUT[] input = null; ushort mouseValue; bool swapedButtons = Win32.GetSystemMetrics(Win32.SM_SWAPBUTTON) == 0 ? false : true; switch (action) { case MyKey.Action.KeyDown: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_KEYBOARD; input[0].ki = Win32.CreateKeybdInput(key.Value, 0); break; case MyKey.Action.KeyUp: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_KEYBOARD; input[0].ki = Win32.CreateKeybdInput(key.Value, Win32.KEYEVENTF_KEYUP); break; case MyKey.Action.KeyClick: input = new Win32.INPUT[2]; input[0].type = Win32.INPUT_KEYBOARD; input[0].ki = Win32.CreateKeybdInput(key.Value, 0); input[1].type = Win32.INPUT_KEYBOARD; input[1].ki = Win32.CreateKeybdInput(key.Value, Win32.KEYEVENTF_KEYUP); break; case MyKey.Action.MouseClick: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_MOUSE; mouseValue = key.Value; if (swapedButtons) { if (key.Value == AllKeys.MOUSE_LBUTTON_CLICK.Value) mouseValue = AllKeys.MOUSE_RBUTTON_CLICK.Value; else if (key.Value == AllKeys.MOUSE_RBUTTON_CLICK.Value) mouseValue = AllKeys.MOUSE_LBUTTON_CLICK.Value; } input[0].mi = Win32.CreateMouseInput(0, 0, 0, 0, mouseValue); break; case MyKey.Action.MouseDblClick: inputRange = new List<Win32.INPUT>(); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseClick)); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseClick)); input = inputRange.ToArray(); break; case MyKey.Action.MouseX1Click: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_MOUSE; input[0].mi = Win32.CreateMouseInput(0, 0, Win32.XBUTTON1, 0, key.Value); break; case MyKey.Action.MouseX1DblClick: inputRange = new List<Win32.INPUT>(); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseX1Click)); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseX1Click)); input = inputRange.ToArray(); break; case MyKey.Action.MouseX2Click: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_MOUSE; input[0].mi = Win32.CreateMouseInput(0, 0, Win32.XBUTTON2, 0, key.Value); break; case MyKey.Action.MouseX2DblClick: inputRange = new List<Win32.INPUT>(); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseX2Click)); inputRange.AddRange(CreateInput(key, MyKey.Action.MouseX2Click)); input = inputRange.ToArray(); break; case MyKey.Action.MouseWheelDown: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_MOUSE; input[0].mi = Win32.CreateMouseInput(0, 0, 120, 0, key.Value); break; case MyKey.Action.MouseWheelUp: input = new Win32.INPUT[1]; input[0].type = Win32.INPUT_MOUSE; input[0].mi = Win32.CreateMouseInput(0, 0, -120, 0, key.Value); break; } return input; }