public string DataParseFuntion(List <PrintItemModel> templetModels, List <int> indexs) { try { if (indexs == null || indexs.Count < 1) { throw new Exception(string.Format("请正确设置数据条目中使用FunctionName=\"{0}\"的ProviderIndexs值.", this.GetType().Name)); } string reValue = string.Empty; int index = indexs[0]; PrintItemModel temp = templetModels.FirstOrDefault(p => { return(p.Index == index); }); if (temp == null) { throw new Exception(string.Format("未查询到Index={0}的打印条目", index)); } return(reValue = RandomStringHelper.GetRandomString(temp.FunctionData.RandomType, temp.FunctionData.RandomLength)); } catch (Exception ex) { throw new Exception(string.Format("执行{0}异常:{1}", this.GetType().Name, ex.Message)); } }
public virtual async Task <ActionResult> GetJsSdkWeChatPayParameters([FromQuery] string appId, string prepayId) { if (string.IsNullOrEmpty(prepayId)) { throw new UserFriendlyException("请传入有效的预支付订单 Id。"); } var nonceStr = RandomStringHelper.GetRandomString(); var timeStamp = DateTimeHelper.GetNowTimeStamp(); var package = $"prepay_id={prepayId}"; var signType = "MD5"; var option = await _optionsResolver.ResolveAsync(); var @params = new WeChatParameters(); @params.AddParameter("appId", appId); @params.AddParameter("nonceStr", nonceStr); @params.AddParameter("timeStamp", timeStamp); @params.AddParameter("package", package); @params.AddParameter("signType", signType); var paySignStr = _signatureGenerator.Generate(@params, MD5.Create(), option.ApiKey); return(new JsonResult(new { nonceStr, timeStamp, package, signType, paySign = paySignStr })); }
public virtual async Task <ActionResult> GetJsSdkConfigParameters([FromQuery] string jsUrl) { if (string.IsNullOrEmpty(jsUrl)) { throw new UserFriendlyException("需要计算的 JS URL 参数不能够为空。"); } var nonceStr = RandomStringHelper.GetRandomString(); var timeStamp = DateTimeHelper.GetNowTimeStamp(); var ticket = await _jsTicketAccessor.GetTicketAsync(); var @params = new WeChatParameters(); @params.AddParameter("noncestr", nonceStr); @params.AddParameter("jsapi_ticket", await _jsTicketAccessor.GetTicketAsync()); @params.AddParameter("url", HttpUtility.UrlDecode(jsUrl)); @params.AddParameter("timestamp", timeStamp); var signStr = _signatureGenerator.Generate(@params, SHA1.Create()).ToLower(); return(new JsonResult(new { appid = _optionsResolver.Resolve().AppId, noncestr = nonceStr, timestamp = timeStamp, signature = signStr, jsapi_ticket = ticket })); }
public void FillInEmailEntry() { _topEmailSignUp.Click(); _topEmailSignUp.Clear(); var email = $"{RandomStringHelper.GetRandomString(6)}.{RandomStringHelper.GetRandomString(8)}@random.com"; _topEmailSignUp.SendKeys(email); Thread.Sleep(1000); }
public void 委派方法() { RandomStringHelper fooRandomStringHelper = new RandomStringHelper(); for (int i = 0; i < 1500; i++) { fooListStrs.Add(fooRandomStringHelper.RandomString(5000)); } }
//private void btnDataReplacementType_Click(object sender, System.EventArgs e) //{ // // AddItemsToMenu(menuReplacement); // menuReplacement.Show(btnDataReplacementType, 0, btnDataReplacementType.Height); //} private void testBtn_Click(object sender, System.EventArgs e) { if (typeComboBox.SelectedIndex == -1) { return; } var t = (RandomType)Enum.Parse(typeof(RandomType), typeComboBox.SelectedIndex.ToString()); txtTextToType.Text = RandomStringHelper.RandomString(t, Convert.ToInt16(lenNumericUpDown.Value)); }
private ShortUrl CreateNewShortUrl(ShortenUrlDTO shortenUrlDTO) { var shortUrl = new ShortUrl { Id = Guid.NewGuid(), OriginalUrl = shortenUrlDTO.Url }; shortUrl.Alias = baseUrl + RandomStringHelper.RandomString(8); while (dbContext.ShortUrls.Any(su => su.Alias == shortUrl.Alias)) { shortUrl.Alias = baseUrl + RandomStringHelper.RandomString(8); } return(shortUrl); }
private string Format(string text) { if (string.IsNullOrEmpty(FormatString)) { return(text); } var ret = ""; if (FormatString[0] == '{' && FormatString[FormatString.Length - 1] == '}') { var arr = FormatString.Substring(1, FormatString.Length - 2).Split(":".ToCharArray()); var type = Convert.ToInt16(arr[0]); var size = Convert.ToInt16(arr[1]); ret = RandomStringHelper.RandomString((RandomType)Enum.Parse(typeof(RandomType), type.ToString()), size); } return(ret); }
private static void HashSetTestObject(int NumberOfStringsToGenerate, int LengthOfStrings) { WrapperStringObject temp_str = null; WrapperStringObject[] ss = new WrapperStringObject[NumberOfStringsToGenerate]; HashSet <WrapperStringObject> hs = new HashSet <WrapperStringObject>(); for (int x = 0; x < NumberOfStringsToGenerate; x++) { ss[x] = new WrapperStringObject(RandomStringHelper.RandomString(LengthOfStrings, x % 5)); if (x % 3 == 0) { temp_str = ss[x]; //to ensure there's always at least a few matches } else { temp_str = new WrapperStringObject(RandomStringHelper.RandomString(LengthOfStrings, x % 5)); } hs.Add(temp_str); } total = 0; Console.WriteLine(StartingSearchingAHashSetWrapper); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (hs.Contains(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAHashSetWrapper, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); }
private void OnNextAlgorithmStep(long l) { _currentStepIndex++; var progress = (double)_currentStepIndex / TotalStepCount * 100; var actualScanningFileName = RandomStringHelper.GetWord(5, 15); if (_generateWarnings && RandomHelper.GetBool(0.01)) { _warningCount++; } _fileScanned.OnNext(new FileScannedInfo(Status, progress, actualScanningFileName, _warningCount)); if (_currentStepIndex >= TotalStepCount) { _intervalSubscription.Dispose(); Status = AlgorithmStatus.Finished; _fileScanned.OnNext(new FileScannedInfo(Status, progress, null, _warningCount)); } }
/// <summary> /// 游戏信息解析。 /// Game info analysis. /// </summary> /// <param name="id">游戏文件夹名。Name of the game version's folder.</param> /// <returns>一个VersionInfo类。A VersionInfo class.</returns> private protected override VersionInfo ToVersion(string id) { // 反序列化。 // Deserialize. var rawVersion = ParseRawVersion(id); if (rawVersion == null) { return(null); } List <RawVersionModel> inherits = null; // 检查游戏是否存在继承关系。 // Check if there is inheritance. if (!string.IsNullOrEmpty(rawVersion.InheritsFrom)) { // 存在继承关系。 // Inheritance exists. inherits = new List <RawVersionModel>(); var current = rawVersion; var first = true; // 递归式地将所有反序列化的版本继承塞进一个表中。 // Add all deserialized inherited version to a list recursively. while (current != null && !string.IsNullOrEmpty(current.InheritsFrom)) { if (first) { inherits.Add(current); first = false; current = ParseRawVersion(current.InheritsFrom); inherits.Add(current); continue; } inherits.Add(ParseRawVersion(current.InheritsFrom)); current = ParseRawVersion(current.InheritsFrom); } if (inherits.Contains(null)) { return(null); } } // 生成一个随机的名字来防止重复。 // Generates a random name to avoid duplication. var rs = new RandomStringHelper().UseLower().UseUpper().UseNumbers().HardMix(1); var randomName = $"{id}-{rs.Generate(5)}-{rs.Generate(5)}"; var result = new VersionInfo { AssetInfo = rawVersion.AssetIndex, MainClass = rawVersion.MainClass, Libraries = new List <FileInfo>(), Natives = new List <NativeFileInfo>(), Id = rawVersion.Id, Name = randomName }; // 检查游戏是否存在继承关系。 // Check if there is inheritance. if (inherits?.Any() ?? false) { // 存在继承关系。 // Inheritance exists. var flag = true; var jvmSb = new StringBuilder(); var gameArgsSb = new StringBuilder(); result.RootVersion = inherits.Last().Id; // 遍历所有的继承 // Go through all inherits for (var i = inherits.Count - 1; i >= 0; i--) { if (result.AssetInfo == null && inherits[i].AssetIndex != null) { result.AssetInfo = inherits[i].AssetIndex; } if (flag) { var rootLibs = GetNatives(inherits[i].Libraries); result.Libraries = rootLibs.Item2; result.Natives = rootLibs.Item1; jvmSb.Append(ParseJvmArguments(inherits[i].Arguments?.Jvm)); var rootArgs = ParseGameArguments( new Tuple <string, List <object> >(inherits[i].MinecraftArguments, inherits[i].Arguments?.Game)); gameArgsSb.Append(rootArgs.Item1); result.AvailableGameArguments = rootArgs.Item2; flag = false; continue; } var middleLibs = GetNatives(inherits[i].Libraries); foreach (var mL in middleLibs.Item2) { var mLMaven = mL.Name.ResolveMavenString(); var mLFlag = false; for (var j = 0; j < result.Libraries.Count; j++) { var lMaven = result.Libraries[j].Name.ResolveMavenString(); if (!lMaven.GetMavenFullName().Equals(mLMaven.GetMavenFullName(), StringComparison.Ordinal)) { continue; } var v1 = new Version(lMaven.Version); var v2 = new Version(mLMaven.Version); if (v2 > v1) { result.Libraries[j] = mL; } mLFlag = true; } if (mLFlag) { continue; } result.Libraries.Add(mL); } var currentNativesNames = new List <string>(); result.Natives.ForEach(n => { currentNativesNames.Add(n.FileInfo.Name); }); var moreMiddleNatives = middleLibs.Item1.Where(mL => !currentNativesNames.Contains(mL.FileInfo.Name)).ToList(); result.Natives.AddRange(moreMiddleNatives); var jvmArgs = ParseJvmArguments(inherits[i].Arguments?.Jvm); var middleGameArgs = ParseGameArguments( new Tuple <string, List <object> >(inherits[i].MinecraftArguments, inherits[i].Arguments?.Game)); if (string.IsNullOrEmpty(inherits[i].MinecraftArguments)) { jvmSb.Append(" ").Append(jvmArgs); gameArgsSb.Append(" ").Append(middleGameArgs.Item1); result.AvailableGameArguments = result.AvailableGameArguments .Union(middleGameArgs.Item2) .ToDictionary(x => x.Key, y => y.Value); } else { result.JvmArguments = jvmArgs; result.GameArguments = middleGameArgs.Item1; result.AvailableGameArguments = middleGameArgs.Item2; } result.Id = inherits[i].Id ?? result.Id; result.MainClass = inherits[i].MainClass ?? result.MainClass; } var finalJvmArgs = (result.JvmArguments ?? string.Empty).Split(' ').ToList(); finalJvmArgs.AddRange(jvmSb.ToString().Split(' ')); result.JvmArguments = string.Join(" ", finalJvmArgs.Distinct()); var finalGameArgs = (result.GameArguments ?? string.Empty).Split(' ').ToList(); finalGameArgs.AddRange(gameArgsSb.ToString().Split(' ')); result.GameArguments = string.Join(" ", finalGameArgs.Distinct()); goto ProcessProfile; } var libs = GetNatives(rawVersion.Libraries); result.Libraries = libs.Item2; result.Natives = libs.Item1; result.JvmArguments = ParseJvmArguments(rawVersion.Arguments?.Jvm); var gameArgs = ParseGameArguments(new Tuple <string, List <object> >(rawVersion.MinecraftArguments, rawVersion.Arguments?.Game)); result.GameArguments = gameArgs.Item1; result.AvailableGameArguments = gameArgs.Item2; ProcessProfile: var oldProfile = LauncherProfileParser.LauncherProfile.Profiles.FirstOrDefault(p => p.Value.LastVersionId?.Equals(id, StringComparison.Ordinal) ?? true); if (oldProfile.Equals(default(KeyValuePair <string, GameProfileModel>))) { LauncherProfileParser.LauncherProfile.Profiles.Add(randomName.ToGuidHash().ToString("N"), new GameProfileModel { GameDir = GamePathHelper.GetGamePath(RootPath, id), LastVersionId = id, Name = randomName, Created = DateTime.Now }); LauncherProfileParser.SaveProfile(); return(result); } result.Name = oldProfile.Value.Name; oldProfile.Value.GameDir = GamePathHelper.GetGamePath(RootPath, id); oldProfile.Value.LastVersionId = id; LauncherProfileParser.LauncherProfile.Profiles[oldProfile.Key] = oldProfile.Value; LauncherProfileParser.SaveProfile(); return(result); }
public async Task <IActionResult> AddUser([FromBody] AddUserRequestDTO user) { // Return 400 Bad Request if AddUserRequestDTO validations fail if (!ModelState.IsValid) { return(BadRequest()); } try { // Return 400 Bad Request if user email is already present and active in the database var emailResult = context.Emails.Where(e => e.Address.ToLower() == user.Email.ToLower() && e.IsActive == true).Select(e => e); if (emailResult.Count() > 0) { return(BadRequest()); } // Return 400 Bad Request if username is already present and active in the database var usernameResult = context.Users.Where(u => u.Username.ToLower() == user.Username.ToLower()).Select(u => u); if (usernameResult.Count() > 0) { return(BadRequest()); } // Generate PBKDH2 hash of the plain password with a salt and store it in the Password table string salt = PasswordHelper.GenerateRandomSalt(16); string passwordHash = PasswordHelper.ComputePbkdf2Hash(user.Password, salt); Password pass = new Password { PasswordHash = passwordHash, Salt = salt }; context.Add(pass); // Add an entry to the Emails table string verificationCode = RandomStringHelper.GenerateRandomString(16); Email emailAddress = new Email { Address = user.Email, IsActive = false, VerificationCode = verificationCode }; context.Add(emailAddress); await context.SaveChangesAsync(); // Add the user to the Users table User newUser = new User { Username = user.Username, PasswordId = pass.Id, EmailId = emailAddress.Id, CompanyId = user.CompanyId, UserRoleId = (int)UserRoles.Member, UserStatusId = (int)UserStatuses.AccountVerificationPending }; context.Add(newUser); await context.SaveChangesAsync(); // Send account verification email EmailHelper.SendAccountVerficationEmail(emailAddress.Address, verificationCode); } catch (Exception e) { return(Ok(false)); } return(Ok(true)); }
public void RandomStringTest() { var v = RandomStringHelper.RandomString(4, 2); var v2 = RandomStringHelper.RandomString(4, 1); int i = 0; }
public void NextNumberString() { System.Console.WriteLine(RandomStringHelper.NextNumberString(4)); }
public void NextNickname() { System.Console.WriteLine(RandomStringHelper.NextNickname()); }
public void NextLettersString() { System.Console.WriteLine(RandomStringHelper.NextLettersString(4)); }
//what is the fastest structure to lookup a string? //hashset.contains //dictionary key //concurrent dictionary key //sorted dictionary //list.containsvalue //array static void TestFastestStructureForStringLookup(int NumberOfStringsToGenerate, int LengthOfStrings) { Console.WriteLine("######## " + System.Reflection.MethodBase.GetCurrentMethod().Name); Console.WriteLine("Number of Random Strings that will be generated: " + NumberOfStringsToGenerate.ToString("#,##0")); Console.WriteLine("Length of Random Strings that will be generated: " + LengthOfStrings.ToString("#,##0")); Console.WriteLine(); object lockObject = new object(); int total = 0; DateTime end = DateTime.Now; DateTime start = DateTime.Now; string temp_str = String.Empty; string[] a = new string[NumberOfStringsToGenerate]; string[] a_bs = new string[NumberOfStringsToGenerate]; //for a binary search List <string> l = new List <string>(NumberOfStringsToGenerate); List <string> l_bs = new List <string>(NumberOfStringsToGenerate); //for binary search SortedList <string, string> sl = new SortedList <string, string>(NumberOfStringsToGenerate); ArrayList al = new ArrayList(NumberOfStringsToGenerate); Dictionary <string, string> d = new Dictionary <string, string>(NumberOfStringsToGenerate); ConcurrentDictionary <string, string> cd = new ConcurrentDictionary <string, string>(Environment.ProcessorCount, NumberOfStringsToGenerate); SortedDictionary <string, string> sd = new SortedDictionary <string, string>(); HashSet <string> hs = new HashSet <string>(); Hashtable ht = new Hashtable(NumberOfStringsToGenerate); //the strings to look up string[] ss = new string[NumberOfStringsToGenerate]; //Generate the string arrays that all the structures will read from. //This is to make sure every structure uses the same set of strings during the run. //strings to be searched. Completely random. Using generate password method to come up with all sorts of mixtures. Console.WriteLine("Generating strings to look up."); for (int x = 0; x < NumberOfStringsToGenerate; x++) { ss[x] = RandomStringHelper.RandomString(LengthOfStrings, x % 5); if (x % 3 == 0) { temp_str = ss[x]; //to ensure there's always at least a few matches } else { temp_str = RandomStringHelper.RandomString(LengthOfStrings, x % 5); } //so all the collections have the exact same strings. a[x] = temp_str; a_bs[x] = temp_str; al.Add(temp_str); l.Add(temp_str); l_bs.Add(temp_str); sl.Add(temp_str, temp_str); if (!d.ContainsKey(temp_str)) { d.Add(temp_str, temp_str); sd.Add(temp_str, temp_str); cd[temp_str] = temp_str; } hs.Add(temp_str); ht.Add(temp_str, temp_str); } Array.Sort(a_bs); //presort the binarysearch array as otherwise the results may be incorrect. l_bs.Sort(); //presort Console.WriteLine("###########################################################"); Console.WriteLine(); total = 0; Console.WriteLine(StartingSearchingAnArray + start.ToLongTimeString()); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { for (int y = 0; y < a.Length; y++) { if (a[y].Contains(ss[x])) { //found it. total += 1; break; } } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAnArray, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAnArrayUsingTheCustomMethod + start.ToLongTimeString()); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { for (int y = 0; y < a.Length; y++) { if ((ss[x].Length - ss[x].Replace(a[y], String.Empty).Length) / a[y].Length > 0) { //found it. total += 1; break; } } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAnArrayUsingTheCustomMethod, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingBinarySearchingAnArray + start.ToLongTimeString()); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { int y = Array.BinarySearch(a_bs, ss[x]); if (y >= 0) { total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingBinarySearchingAnArray, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAnArrayListUsingContains); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (al.Contains(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAnArrayListUsingContains, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAnArrayListUsingAForLoop); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { for (int y = 0; y < al.Count; y++) { if (al[y] == ss[x]) { //found it. total += 1; break; } } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAnArrayListUsingAForLoop, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAListUsingContains); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (l.Contains(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAListUsingContains, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAListUsingAForLoop); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { for (int y = 0; y < l.Count; y++) { if (l[y] == ss[x]) { //found it. total += 1; break; } } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAListUsingAForLoop, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingBinarySearchingAList); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { int y = l_bs.BinarySearch(ss[x]); if (y >= 0) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingBinarySearchingAList, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingASortedList); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (sl.ContainsKey(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingASortedList, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingADictionaryKey); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (d.ContainsKey(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingADictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingADictionaryValue); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (d.ContainsValue(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingADictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingASortedDictionaryKey); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (sd.ContainsKey(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingASortedDictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingASortedDictionaryValue); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (sd.ContainsValue(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingASortedDictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAConcurrentDictionaryKey); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (cd.ContainsKey(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAConcurrentDictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAConcurrentDictionaryValue); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (cd.Values.Any(z => z == ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAConcurrentDictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAHashSet); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (hs.Contains(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAHashSet, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAHashTableKey); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (ht.ContainsKey(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAHashTableKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingSearchingAHashTableValue); start = DateTime.Now; for (int x = 0; x < ss.Length; x++) { if (ht.ContainsValue(ss[x])) { //found it. total += 1; } } end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingSearchingAHashTableValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine("#########Starting the parallel implementations#############"); Console.WriteLine("############################################################"); total = 0; Console.WriteLine(StartingParallelSearchingAnArray + start.ToLongTimeString()); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { for (int y = 0; y < a.Length; y++) { if (a[y].Contains(ss[x])) { //found it. subtotal += 1; break; } } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingAnArray, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAnArrayUsingCustomMethod + start.ToLongTimeString()); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { for (int y = 0; y < a.Length; y++) { if ((ss[x].Length - ss[x].Replace(a[y], String.Empty).Length) / a[y].Length > 0) { //found it. subtotal += 1; break; } } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingAnArrayUsingCustomMethod, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelBinarySearchingAnArray + start.ToLongTimeString()); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { int y = Array.BinarySearch(a_bs, ss[x]); if (y >= 0) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelBinarySearchingAnArray, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAnArrayListUsingContains); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (al.Contains(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingAnArrayListUsingContains, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAnArrayListUsingAForLoop); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { for (int y = 0; y < al.Count; y++) { if (al[y] == ss[x]) { //found it. subtotal += 1; break; } } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingAnArrayListUsingAForLoop, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAListUsingContains); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { for (int y = 0; y < l.Count; y++) { if (l[y] == ss[x]) { //found it. total += 1; break; } } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingAListUsingContains, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelBinarySearchingAList); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { int y = l_bs.BinarySearch(ss[x]); if (y >= 0) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelBinarySearchingAList, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingASortedList); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (sl.ContainsKey(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingASortedList, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingADictionaryKey); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (d.ContainsKey(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingADictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingADictionaryValue); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (d.ContainsValue(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingADictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingASortedDictionaryKey); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (sd.ContainsKey(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingASortedDictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingASortedDictionaryValue); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (sd.ContainsValue(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingASortedDictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingConcurrentDictionaryKey); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (cd.ContainsKey(ss[x])) { subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingConcurrentDictionaryKey, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingConcurrentDictionaryValue); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (cd.Values.Any(z => z == ss[x])) { subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallelSearchingConcurrentDictionaryValue, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallerSearchingAHashSet); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (hs.Contains(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); e.Add(StartingParallerSearchingAHashSet, diff); Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAHashTableKey); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (ht.ContainsKey(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); if (LengthOfStrings == los) { e.Add(StartingParallelSearchingAHashTableKey, diff); } Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Thread.Sleep(1000); //Sleep to give the system time to recover for next run total = 0; Console.WriteLine(StartingParallelSearchingAHashTableValue); start = DateTime.Now; Parallel.For(0, ss.Length, () => 0, (x, loopState, subtotal) => { if (ht.ContainsValue(ss[x])) { //found it. subtotal += 1; } return(subtotal); }, (s) => { lock (lockObject) { total += s; } } ); end = DateTime.Now; Console.WriteLine("Finished at: " + end.ToLongTimeString()); diff = (end - start); Console.WriteLine("Time: " + diff); if (LengthOfStrings == los) { e.Add(StartingParallelSearchingAHashTableValue, diff); } Console.WriteLine("Total finds: " + total + Environment.NewLine); Console.WriteLine(); Console.WriteLine("###########################################################"); Console.WriteLine(); Array.Clear(ss, 0, ss.Length); ss = null; Array.Clear(a, 0, a.Length); a = null; al.Clear(); al = null; l.Clear(); l = null; l_bs.Clear(); l_bs = null; sl.Clear(); sl = null; d.Clear(); d = null; sd.Clear(); sd = null; cd.Clear(); cd = null; hs.Clear(); hs = null; ht.Clear(); ht = null; GC.Collect(); } //TestFastestStructureForStringLookup