// Calculate metric weights based on standard deviations public void CalculateMetricWeights() { Hashtable reverser = new Hashtable(); List <string> metric_list = new List <string>(); double metric_total = 0; // Grab metrics used and their value sum foreach (var metric in standard_deviations.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).ToList()) { metric_list.Add(metric.Key.ToString()); metric_total += (double)metric.Value; } Console.WriteLine("TOTAL:::::::::: " + metric_total); // Add initial weights that will be reversed after for (int i = 0; i < metric_list.Count; i++) { reverser.Add(metric_list[i], (double)standard_deviations[metric_list[i]] / metric_total); } // Associate first metric with the weight of the last one, second with second last, etc int size = metric_list.Count - 1; for (int i = 0; i < metric_list.Count; i++) { metric_weights.Add(metric_list[size - i], reverser[metric_list[i]]); } }
public IEnumerable <string> Find(IEnumerable <string> wordStream) { // gather lenght of matrix var xWidth = _matrix[0].Length; //combine matrix and rotated matrix List <string> mtrx = new List <string>(); mtrx.AddRange(_matrix); mtrx.AddRange(_rotatedMatrix); // execution time aux. code //Stopwatch timer = new Stopwatch(); // traverse each element of wordStream. // If a word in the stream has already been found, accumulate it's entry // on the table without commiting to search it again.If a word peeked on the stream // is found on the matrix , add it on a new hash entry. // timer.Start(); foreach (string word in wordStream) { //if word is already in our hash, there's no need of search it in the matrix again, just accumulate on the hashTable entry. if (_mostRepeated.ContainsKey(word)) { _mostRepeated[word] = (int)_mostRepeated[word] + 1; } else { //new word , search for a match foreach (string line in mtrx) { // try with contains if (line.Contains(word)) { _mostRepeated.Add(word, 1); // word found , break out word-match-matrix loop and resume looping on stream. break; } } //foreach line in mtrx. } } //foreach word in stream. // timer.Stop(); // Console.WriteLine($"find function main loop elapsed time: { timer.ElapsedTicks}"); var rptd = _mostRepeated.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).Reverse().ToList(); var myKeys = rptd.Select(ent => (string)ent.Key); return(myKeys.Take(10).ToList()); }
public static Dictionary <string, object> ToDictionary(this Hashtable hashtable, bool addValueLayer) { if (hashtable == null) { return(null); } else { var dictionary = new Dictionary <string, object>(); foreach (var entry in hashtable.Cast <DictionaryEntry>()) { var valueAsHashtable = entry.Value as Hashtable; if (valueAsHashtable != null) { dictionary[(string)entry.Key] = valueAsHashtable.ToDictionary(addValueLayer); } else { if (addValueLayer) { dictionary[(string)entry.Key] = new Hashtable() { { "value", entry.Value.ToString() } }; } else { dictionary[(string)entry.Key] = entry.Value; } } } return(dictionary); } }
// ReSharper disable once SuggestBaseTypeForParameter public HashtableSelector(Hashtable hashtable) { table = hashtable.Cast <DictionaryEntry>().ToDictionary( p => p.Key, p => new PipelineSelector(p.Value) as ISelector ); }
private void btnHashT_Click(object sender, EventArgs e) { DataTable dt = GetData(); Hashtable customers = new Hashtable(); for (int i = 0; i < dt.Rows.Count; i++) { Customer newCust = new Customer() { ID = (int)dt.Rows[i].ItemArray[0], fName = (string)dt.Rows[i].ItemArray[1], lName = (string)dt.Rows[i].ItemArray[2] }; customers.Add(i, newCust); } int j = 0; // Three lines down: used to flip the Hashtable entries in reverse var dict = customers.Cast <DictionaryEntry>().ToDictionary(kvp => (int)kvp.Key, kvp => (Customer)kvp.Value); var sorted = new SortedDictionary <int, Customer>(dict); ICollection values = sorted.Values; foreach (Customer cust in values) { dgvCustomers.Rows.Add(); dgvCustomers.Rows[j].Cells[0].Value = cust.ID; dgvCustomers.Rows[j].Cells[1].Value = cust.fName; dgvCustomers.Rows[j].Cells[2].Value = cust.lName; j++; } }
public static void SetTemplateMetadata(ProvisioningTemplate template, string templateDisplayName, string templateImagePreviewUrl, Hashtable templateProperties) { if (!String.IsNullOrEmpty(templateDisplayName)) { template.DisplayName = templateDisplayName; } if (!String.IsNullOrEmpty(templateImagePreviewUrl)) { template.ImagePreviewUrl = templateImagePreviewUrl; } if (templateProperties != null && templateProperties.Count > 0) { var properties = templateProperties .Cast <DictionaryEntry>() .ToDictionary(i => (String)i.Key, i => (String)i.Value); foreach (var key in properties.Keys) { if (!String.IsNullOrEmpty(key)) { template.Properties[key] = properties[key]; } } } }
public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>(this Hashtable table, Func <object, TKey> castKey, Func <object, TValue> castValue) { var dict = table.Cast <DictionaryEntry>() .ToDictionary(kvp => castKey(kvp.Key), kvp => castValue(kvp.Value)); return(dict); }
/// <summary> /// Gets the specified product sku. /// </summary> /// <param name="countryCode">The country used to obtain the offer.</param> /// <param name="productId">Identifier for the product.</param> /// <param name="context">The list of variables needed to execute an inventory check on this item.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="countryCode"/> is empty or null. /// or /// <paramref name="productId"/> is empty or null. /// or /// <paramref name="context"/> is empty or null. /// </exception> private void GetProductInventory(string countryCode, string productId, string skuId, Hashtable context) { IEnumerable <InventoryItem> item; InventoryCheckRequest request; countryCode.AssertNotEmpty(nameof(countryCode)); productId.AssertNotEmpty(nameof(productId)); try { request = new InventoryCheckRequest() { TargetItems = string.IsNullOrEmpty(skuId) ? new InventoryItem[] { new InventoryItem { ProductId = productId } } : new InventoryItem[] { new InventoryItem { ProductId = productId, SkuId = skuId } }, InventoryContext = context.Cast <DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value) }; item = Partner.Extensions.Product.ByCountry(countryCode).CheckInventory(request); WriteObject(item.Select(i => new PSInventoryItem(i)), true); } catch (PartnerException ex) { throw new PSPartnerException(null, ex); } finally { item = null; request = null; } }
public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>(this Hashtable table) { var dict = table.Cast <DictionaryEntry>() .ToDictionary(kvp => (TKey)kvp.Key, kvp => (TValue)kvp.Value); return(dict); }
/// <summary> /// Gets the specified product SKU. /// </summary> /// <param name="countryCode">The country used to obtain the offer.</param> /// <param name="productId">Identifier for the product.</param> /// <param name="context">The list of variables needed to execute an inventory check on this item.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="countryCode"/> is empty or null. /// or /// <paramref name="productId"/> is empty or null. /// or /// <paramref name="context"/> is empty or null. /// </exception> private void GetProductInventory(string countryCode, string productId, string skuId, Hashtable context) { IEnumerable <InventoryItem> item; InventoryCheckRequest request; countryCode.AssertNotEmpty(nameof(countryCode)); productId.AssertNotEmpty(nameof(productId)); request = new InventoryCheckRequest() { TargetItems = string.IsNullOrEmpty(skuId) ? new InventoryItem[] { new InventoryItem { ProductId = productId } } : new InventoryItem[] { new InventoryItem { ProductId = productId, SkuId = skuId } }, }; foreach (KeyValuePair <string, string> kvp in context.Cast <DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value)) { request.InventoryContext.Add(kvp.Key, kvp.Value); } item = Partner.Extensions.Product.ByCountry(countryCode).CheckInventoryAsync(request).GetAwaiter().GetResult(); WriteObject(item.Select(i => new PSInventoryItem(i)), true); }
private string Upload(string uri, string method, Hashtable vars) { // 1. format body data var data = ""; if (vars != null) { data = vars.Cast <DictionaryEntry>().Aggregate(data, (current, d) => current + (d.Key.ToString() + "=" + d.Value.ToString() + "&")); } // 2. setup basic authenication var authstring = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", _id, _token))); // 3. perform POST/PUT/DELETE using WebClient ServicePointManager.Expect100Continue = false; var postbytes = Encoding.ASCII.GetBytes(data); var client = new WebClient(); client.Headers.Add("Authorization", String.Format("Basic {0}", authstring)); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); var resp = client.UploadData(uri, method, postbytes); return(Encoding.ASCII.GetString(resp)); }
public static AzureStoragePropertyDictionaryResource ConvertToAzureStorageAccountPathPropertyDictionary(this Hashtable hashtable) { if (hashtable == null) { return(null); } AzureStoragePropertyDictionaryResource result = new AzureStoragePropertyDictionaryResource(); result.Properties = hashtable.Cast <DictionaryEntry>() .ToDictionary( kvp => kvp.Key.ToString(), kvp => { var typeValuePair = new Hashtable((Hashtable)kvp.Value, StringComparer.OrdinalIgnoreCase); return(new AzureStorageInfoValue { AccessKey = typeValuePair["AccessKey"].ToString(), AccountName = typeValuePair["AccountName"].ToString(), MountPath = typeValuePair["MountPath"].ToString(), ShareName = typeValuePair["ShareName"].ToString(), Type = (AzureStorageType)Enum.Parse(typeof(AzureStorageType), typeValuePair["Type"].ToString(), true) }); }); return(result); }
private static List <SelectListItem> BindEnumList(Hashtable hashtable, string selectedValue, bool isFirstEmptyItem, string EmptyString) { List <SelectListItem> lst = new List <SelectListItem>(); if (isFirstEmptyItem) { SelectListItem en1 = new SelectListItem(); en1.Value = ""; en1.Text = EmptyString; lst.Add(en1); } Dictionary <object, object> r = hashtable.Cast <DictionaryEntry>().ToDictionary(d => d.Key, d => d.Value); var l = r.OrderBy(key => key.Key); var dic = l.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); foreach (var entry in dic) { SelectListItem en = new SelectListItem(); en.Value = Convert.ToString(entry.Key); en.Text = Convert.ToString(entry.Value); if (en.Value == selectedValue) { en.Selected = true; } lst.Add(en); } return(lst); }
private string Download(string uri, Hashtable vars) { // 1. format query string if (vars != null) { var query = vars.Cast <DictionaryEntry>().Aggregate("", (current, d) => current + ("&" + d.Key.ToString() + "=" + d.Value.ToString())); if (query.Length > 0) { uri = uri + "?" + query.Substring(1); } } // 2. setup basic authenication var authstring = Convert.ToBase64String( Encoding.ASCII.GetBytes(String.Format("{0}:{1}", _id, _token))); // 3. perform GET using WebClient var client = new WebClient(); client.Headers.Add("Authorization", String.Format("Basic {0}", authstring)); var resp = client.DownloadData(uri); return(Encoding.ASCII.GetString(resp)); }
public static Func <string, IEnumerable <string> > LookupFuncStrings(this Hashtable hashtable) { if (hashtable == null || hashtable.Count == 0) { return((x) => Enumerable.Empty <string>()); } return((index) => { // get the key from the inext var key = hashtable.Cast <object>().FirstOrDefault <object>(each => each != null && index.Equals(each.ToString(), StringComparison.CurrentCultureIgnoreCase)); if (!Equals(null, key)) { // get the item in the collection var obj = hashtable[key]; // if it's a string, return it as a single item if (obj is string) { return new [] { obj as string }; } // otherwise, try to cast it to a collection of string-like-things var collection = obj as IEnumerable; if (collection != null) { return collection.Cast <object>().Select(each => each.ToString()).ByRef(); } // meh. ToString, and goodnight. return new[] { obj.ToString() }; } return Enumerable.Empty <string>(); }); }
async void tepHranice() { Hashtable TepTable = new Hashtable(); var all1 = _context.Pulse.ToList(); foreach (var a in all1) { int hod = (int)Math.Round(a.Hodnota); if (TepTable.ContainsKey(hod)) { int pocet = int.Parse(TepTable[hod].ToString()); TepTable[hod] = pocet + 1; // System.Diagnostics.Debug.WriteLine("Moje stare " + " " + hod + " " + TepTable[hod]); } else { TepTable.Add(hod, 1); //System.Diagnostics.Debug.WriteLine("Moje stare update " + " " + hod + " " + TepTable[hod]); } } var tablelist = TepTable.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).ToList(); foreach (var l in tablelist) { System.Diagnostics.Debug.WriteLine("Moje " + " " + l.Key + " " + l.Value); } }
private static String extractResults(List <int> values) { Hashtable votes = new Hashtable(); foreach (int value in values) { if (votes.ContainsKey(value)) { votes[value] = (int)votes[value] + 1; } else { votes.Add(value, 1); } } Console.WriteLine(); List <DictionaryEntry> dictionaryEntries = new List <DictionaryEntry>(); dictionaryEntries = votes.Cast <DictionaryEntry>().OrderByDescending(entry => entry.Value).ToList(); string result = "Balsavimo rezultatai:\n"; foreach (DictionaryEntry value in dictionaryEntries) { result += $"#{value.Key} gavo {value.Value} balsu\n"; } return(result); }
/// <summary> /// 添加请求记录 /// </summary> /// <param name="mobile"></param> /// <param name="apiRequestType"></param> public static void Add(string mobile, string apiRequestType) { //如果是新的一天的头条数据,添加对应的子明细表 string dateKey = System.DateTime.Now.ToString("yyyy-MM-dd"); if (_mainHt[dateKey] == null) { _mainHt[dateKey] = new Hashtable(); } //移除历史记录 var query = from item in _mainHt.Cast <DictionaryEntry>() where item.Key.ToString() != dateKey select item.Key.ToString(); foreach (var q in query) { _mainHt.Remove(q); } string key = mobile + "_" + apiRequestType; Hashtable _detailHt = (Hashtable)_mainHt[dateKey]; //保存手机号和请求类别添加到明细表 if (_detailHt.ContainsKey(key)) { int count = int.Parse(_detailHt[key].ToString()); _detailHt[key] = count + 1; } else { _detailHt[key] = 1; } }
/// <summary> /// Company Relationship in DB /// </summary> /// <param name="companyId"></param> /// <param name="statusId"></param> /// <returns></returns> public List <DictionaryEntry> CompanyReporterTypes(int companyId, int?statusId = null) { Hashtable _reporter_type = new Hashtable(); if (db.company_relationship.Any(o => o.company_id == companyId)) { List <company_relationship> _list = db.company_relationship.Where(s => s.company_id == companyId && s.status_id == 2).OrderBy(t => t.relationship_en).ToList(); foreach (company_relationship cst in _list) { if (statusId.HasValue) { if (cst.status_id == statusId) { _reporter_type.Add(cst.id, cst.relationship_en); } } else { _reporter_type.Add(cst.id, cst.relationship_en); } } } else { List <relationship> _list = db.relationship.ToList(); foreach (relationship stm in _list) { _reporter_type.Add(stm.id, stm.relationship_en); } } return(_reporter_type.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).ToList()); }
public void PrintWeights() { Console.WriteLine("Metric weights for metrics performed on " + Name + "\n"); foreach (var score in metric_weights.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).ToList()) { Console.WriteLine("{0}: {1}", score.Key, score.Value); } }
public void PrintGoals() { Console.WriteLine("Goal values for metrics performed on " + Name + "\n"); foreach (var score in goal_values.Cast <DictionaryEntry>().OrderBy(entry => entry.Value).ToList()) { Console.WriteLine("{0}: {1}", score.Key, score.Value); } }
public static List <CustomKeyValuePair> ToKeyList(this Hashtable ht) { return(ht.Cast <DictionaryEntry>().Select(de => new CustomKeyValuePair { Key = de.Key.ToString(), Value = de.Value.ToString() }).ToList()); }
public static IOrderedEnumerable <KeyValuePair <string, IOrderedEnumerable <KeyValuePair <string, string> > > > ConvertToKeyValuePairs(Hashtable htParents) { return(htParents.Cast <DictionaryEntry>() .ToDictionary(parent => (string)parent.Key, parent => (parent.Value as Hashtable) .Cast <DictionaryEntry>() .ToDictionary(child => (string)child.Key, child => (string)child.Value) .OrderByDescending(child => child.Key)) .OrderByDescending(parent => parent.Key)); }
public void Cast_CastsParametersWithDotNotation() { var parameters = new Hashtable { { "Octopus.Machine.Name", "some machine name" } }; var sut = parameters.Cast <DotNotationParameter>(); Assert.Equal("some machine name", sut.OctopusMachineName); }
public void Cast_OnlySetsWritableProperties() { var parameters = new Hashtable { { "Port", 80 } }; var sut = parameters.Cast <ReadonlyParameter>(); Assert.Equal(90, sut.Port); }
public void Cast_DoesNotThrowWhenNotRequiredParamNotGiven() { var parameters = new Hashtable { { "SiteName", "MySite" } }; var sut = parameters.Cast <RequiredParameters>(); Assert.Equal("MySite", sut.SiteName); }
public void Cast_ConvertsDecimalParamCorrectly() { var parameters = new Hashtable { { "NetFramework", "4.5" } }; var sut = parameters.Cast <SingleDecimalParameter>(); Assert.Equal(4.5M, sut.NetFramework); }
public void WriteXml(XmlWriter writer) { writer.WriteStartElement("data"); foreach (DictionaryEntry entry in data.Cast <DictionaryEntry> ().OrderBy(l => l.Key)) { writer.WriteElementString((string)entry.Key, (string)entry.Value); } writer.WriteEndElement(); }
public void Ini(Hashtable _iniPara) { var list = _iniPara.Cast <DictionaryEntry>().OrderBy(k => k.Key).Select(s => s.Value.ToString()).ToList(); labelControl.Text = list[0]; pdmsGadgetName = list[1]; pdmsGadgetCallBack = list[2]; pdmsGadgetIncrement = Convert.ToInt32(list[3]); }
private ApplicationTypeVersionResource GetNewAppTypeVersionParameters(string applicationTypeName, string location, string packageUrl, Hashtable tags) { return(new ApplicationTypeVersionResource( appPackageUrl: packageUrl, name: this.ClusterName, type: applicationTypeName, location: location, tags: tags?.Cast <DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string))); }