/// <summary> /// 签名规则:hex(md5(secret+sorted(header_params+url_params+form_params)+body)+secret) /// </summary> private static string Sign(IDictionary<string, string> parameters, string body, string secret, string charset) { IEnumerator<KeyValuePair<string, string>> em = parameters.GetEnumerator(); // 第1步:把所有参数名和参数值串在一起 StringBuilder query = new StringBuilder(secret); while (em.MoveNext()) { string key = em.Current.Key; if (!TOP_FIELD_SIGN.Equals(key)) { string value = em.Current.Value; query.Append(key).Append(value); } } if (body != null) { query.Append(body); } query.Append(secret); // 第2步:使用MD5加密 MD5 md5 = MD5.Create(); byte[] bytes = md5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(query.ToString())); // 第3步:把二进制转化为大写的十六进制 StringBuilder result = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { result.Append(bytes[i].ToString("X2")); } return result.ToString(); }
public static void OverwriteSequenceNumbers(TagLib.Ogg.File file, long position, IDictionary<uint, int> shiftTable) { if (file == null) { throw new ArgumentNullException("file"); } if (shiftTable == null) { throw new ArgumentNullException("shiftTable"); } bool flag = true; IEnumerator<KeyValuePair<uint, int>> enumerator = shiftTable.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair<uint, int> current = enumerator.Current; if (current.Value != 0) { flag = false; goto Label_0065; } } } finally { if (enumerator == null) { } enumerator.Dispose(); } Label_0065: if (flag) { return; } while (position < (file.Length - 0x1bL)) { PageHeader header = new PageHeader(file, position); int length = (int) (header.Size + header.DataSize); if (shiftTable.ContainsKey(header.StreamSerialNumber) && (shiftTable[header.StreamSerialNumber] != 0)) { file.Seek(position); ByteVector vector = file.ReadBlock(length); ByteVector data = ByteVector.FromUInt(header.PageSequenceNumber + ((uint) ((long) shiftTable[header.StreamSerialNumber])), false); for (int i = 0x12; i < 0x16; i++) { vector[i] = data[i - 0x12]; } for (int j = 0x16; j < 0x1a; j++) { vector[j] = 0; } data.Add(ByteVector.FromUInt(vector.Checksum, false)); file.Seek(position + 0x12L); file.WriteBlock(data); } position += length; } }
public string DoPost(string url, IDictionary<string, string> parameters, string input) { HttpWebRequest req = GetWebRequest(url, "POST"); req.ContentType = "application/json"; #region build header IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator(); while (dem.MoveNext()) { string name = dem.Current.Key; string value = dem.Current.Value; // 忽略参数名或参数值为空的参数 if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) req.Headers.Add(name, HttpUtility.UrlEncode(value, Encoding.UTF8)); } #endregion byte[] postData = Encoding.UTF8.GetBytes(input); System.IO.Stream reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); reqStream.Close(); HttpWebResponse rsp = (HttpWebResponse)req.GetResponse(); return GetResponseString(rsp, System.Text.Encoding.UTF8); }
private void PopulateValues(IDictionary from, System.Collections.Generic.List<KeyValue> to) { IDictionaryEnumerator ide = from.GetEnumerator(); ValueWithType valueWithType = null; KeyValue keyValue = null; while (ide.MoveNext()) { keyValue = new KeyValue(); keyValue.key = ide.Key.ToString(); if (ide.Value is ArrayList) { ArrayList list = (ArrayList)ide.Value; foreach (object value in list) { valueWithType = new ValueWithType(); valueWithType.value = GetValueString(value); valueWithType.type = value.GetType().FullName; keyValue.value.Add(valueWithType); } } else { valueWithType = new ValueWithType(); valueWithType.value = GetValueString(ide.Value); valueWithType.type = ide.Value.GetType().FullName; keyValue.value.Add(valueWithType); } to.Add(keyValue); } }
/// <summary> /// 组装普通文本请求参数。 /// </summary> /// <param name="parameters">Key-Value形式请求参数字典。</param> /// <returns>URL编码后的请求数据。</returns> private static string BuildPostData(IDictionary<string, string> parameters) { StringBuilder postData = new StringBuilder(); bool hasParam = false; IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator(); while (dem.MoveNext()) { string name = dem.Current.Key; string value = dem.Current.Value; // 忽略参数名或参数值为空的参数 if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) { if (hasParam) { postData.Append("&"); } postData.Append(name); postData.Append("="); postData.Append(Uri.EscapeUriString(value)); hasParam = true; } } return postData.ToString(); }
/// <summary> /// 组装普通文本请求参数。 /// </summary> /// <param name="parameters">Key-Value形式请求参数字典</param> /// <returns>URL编码后的请求数据</returns> public static string BuildQuery(IDictionary<string, string> parameters) { StringBuilder postData = new StringBuilder(); bool hasParam = false; IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator(); while (dem.MoveNext()) { string name = dem.Current.Key; string value = dem.Current.Value; // 忽略参数名或参数值为空的参数 if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) { if (hasParam) { postData.Append("&"); } postData.Append(name); postData.Append("="); postData.Append(HttpUtility.UrlEncode(value, Encoding.UTF8)); hasParam = true; } } return postData.ToString(); }
public static string BuildQuery(IDictionary<string, string> parameters) { StringBuilder builder = new StringBuilder(); bool flag = false; IEnumerator<KeyValuePair<string, string>> enumerator = parameters.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, string> current = enumerator.Current; string key = current.Key; KeyValuePair<string, string> pair2 = enumerator.Current; string str2 = pair2.Value; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(str2)) { if (flag) { builder.Append("&"); } builder.Append(key); builder.Append("="); builder.Append(HttpUtility.UrlEncode(str2, Encoding.UTF8)); flag = true; } } return builder.ToString(); }
/// <summary> /// Update any existing rows for the given values, and remove them from the values collection. /// </summary> /// <param name="configName"></param> /// <param name="values"></param> /// <param name="conn"></param> /// <param name="transaction"></param> /// <returns></returns> public bool UpdateExisting(string configName, IDictionary<long, MonitorRecord<double>> values, IDbConnection conn, IDbTransaction transaction = null) { var result = false; if (values.Count == 0) return true; MonitorInfo monitorInfo; if (_cache.MonitorInfo.TryGetValue(configName, out monitorInfo)) { var reduceLevel = monitorInfo.FirstReduceLevel; var reduceMethod = reduceLevel.AggregationClass; var startTime = values.First().Value.TimeStamp; var tableName = Support.MakeReducedName(configName, reduceLevel.Resolution); var updateList = new List<MonitorRecord<double>>(); var combineList = new List<MonitorRecord<double>>(); //Based on the timestamp we have we pull out from the database all recrods that have a date //grater than the timestamp we have. For each value we find loop through and find the value //that is the next greatest time past our current value from the database var existingList = _storageCommands.SelectListForUpdateExisting(tableName, startTime, conn, transaction); foreach (var existingValue in existingList) { var hasNext = false; var matchingValue = _cache.Empty; var valuesEnumerator = values.GetEnumerator(); while ((hasNext = valuesEnumerator.MoveNext()) && ((matchingValue = valuesEnumerator.Current.Value).TimeStamp < existingValue.TimeStamp)) ; combineList.Clear(); if (hasNext && !_cache.Empty.Equals(matchingValue)) { combineList.Add(existingValue); combineList.Add(matchingValue); values.Remove(matchingValue.TimeStamp.Ticks); } else continue; //Reduce the value we have from the database with the value we have here (thats what is in the combined list) var update = reduceMethod.Reduce(existingValue.TimeStamp, combineList); updateList.Add(update); } //Update everything in the database _storageCommands.Update(tableName, updateList, conn, transaction); result = true; } else throw new DataException("No monitor config found for " + configName); return result; }
private void WriteElements(IWriteContext context, IDictionary map, KeyValueHandlerPair handlers) { IEnumerator elements = map.GetEnumerator(); while (elements.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)elements.Current; context.WriteObject(handlers._keyHandler, entry.Key); context.WriteObject(handlers._valueHandler, entry.Value); } }
public virtual void AddRange(IDictionary c) { if(c != null) { IDictionaryEnumerator e = c.GetEnumerator(); while(e.MoveNext()) { ((IKeyedCollection)this).Add(e.Value, e.Key); } } }
public Hashtable(IDictionary d, float loadFactor, IEqualityComparer equalityComparer) : this((d != null) ? d.Count : 0, loadFactor, equalityComparer) { if (d == null) { throw new ArgumentNullException("d", "Dictionary cannot be null."); } IDictionaryEnumerator enumerator = d.GetEnumerator(); while (enumerator.MoveNext()) { this.Add(enumerator.Key, enumerator.Value); } }
public MessageDictionaryEnumerator(MessageDictionary md, IDictionary hashtable) { this._md = md; if (hashtable != null) { this._enumHash = hashtable.GetEnumerator(); } else { this._enumHash = null; } }
private static void AddAll(IDictionary<string, string> dest, IDictionary<string, string> from) { if (from != null && from.Count > 0) { IEnumerator<KeyValuePair<string, string>> em = from.GetEnumerator(); while (em.MoveNext()) { KeyValuePair<string, string> kvp = em.Current; dest.Add(kvp.Key, kvp.Value); } } }
internal void AddParameters(IDictionary<string, string> parameters) { if ((parameters != null) && (parameters.Count > 0)) { IEnumerator<KeyValuePair<string, string>> enumerator = parameters.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, string> current = enumerator.Current; KeyValuePair<string, string> pair2 = enumerator.Current; this.AddParameter(current.Key, pair2.Value); } } }
private void SerializeDictionary(IDictionary value) { IDictionaryEnumerator e = value.GetEnumerator(); _writer.BeginObject(); if (e.MoveNext()) { SerializeKeyValue(e.Key.ToString(), e.Value, true); } while (e.MoveNext()) { SerializeKeyValue(e.Key.ToString(), e.Value, false); } _writer.EndObject(); }
/// <summary> /// Creates a case-insensitive hashtable using the given <see cref="CultureInfo" />, initially /// populated with entries from another dictionary. /// </summary> /// <param name="d">the dictionary to copy entries from</param> /// <param name="culture">the <see cref="CultureInfo" /> to calculate the hashcode</param> public CaseInsensitiveHashtable(IDictionary d, CultureInfo culture) { AssertUtils.ArgumentNotNull(culture, "culture"); _culture = culture; if (d != null) { var enumerator = d.GetEnumerator(); while (enumerator.MoveNext()) { Add(enumerator.Key, enumerator.Value); } } }
public static int DictionaryGetHashCode(IDictionary d) { int h = 0; IDictionaryEnumerator e = d.GetEnumerator(); while(e.MoveNext()) { h = 5 * h + e.Key.GetHashCode(); if(e.Value != null) { h = 5 * h + e.Key.GetHashCode(); } } return h; }
public static IDictionary<Situation, RobotAction> Merge(IDictionary<Situation, RobotAction> s1, IDictionary<Situation, RobotAction> s2) { var newStrategy = new Dictionary<Situation, RobotAction>(); var e = s1.GetEnumerator(); bool chooseE1 = random.Next(0, 2) == 0; while (e.MoveNext()) { RobotAction e1 = e.Current.Value; var chosenAction = chooseE1 ? e1 : s2[e.Current.Key]; newStrategy.Add(e.Current.Key, chosenAction); chooseE1 = !chooseE1; } //RandomlyChange(20, newStrategy); RandomlyChange(0,20, newStrategy); return newStrategy; }
private CimInstance CreateCimInstance(string className, string cimNamespace, IEnumerable<string> key, IDictionary properties, NewCimInstanceCommand cmdlet) { CimInstance cimInstance = new CimInstance(className, cimNamespace); if (properties != null) { List<string> strs = new List<string>(); if (key != null) { foreach (string str in key) { strs.Add(str); } } IDictionaryEnumerator enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { CimFlags cimFlag = CimFlags.None; string str1 = enumerator.Key.ToString().Trim(); if (strs.Contains<string>(str1, StringComparer.OrdinalIgnoreCase)) { cimFlag = CimFlags.Key; } object baseObject = base.GetBaseObject(enumerator.Value); object[] objArray = new object[3]; objArray[0] = str1; objArray[1] = baseObject; objArray[2] = cimFlag; DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, objArray); PSReference pSReference = baseObject as PSReference; if (pSReference == null) { CimProperty cimProperty = CimProperty.Create(str1, baseObject, cimFlag); cimInstance.CimInstanceProperties.Add(cimProperty); } else { CimProperty cimProperty1 = CimProperty.Create(str1, base.GetBaseObject(pSReference.Value), CimType.Reference, cimFlag); cimInstance.CimInstanceProperties.Add(cimProperty1); } } return cimInstance; } else { return cimInstance; } }
public static DictionaryEntry[] GetEntries(IDictionary dictionary) { if ((dictionary == null) || (dictionary.Count == 0)) { return _zeroEntries; } DictionaryEntry[] entryArray = new DictionaryEntry[dictionary.Count]; using (IDictionaryEnumerator enumerator = dictionary.GetEnumerator()) { int num = 0; while (enumerator.MoveNext()) { entryArray[num++] = enumerator.Entry; } return entryArray; } }
/// <summary> /// 清除字典中值为空的项。 /// </summary> /// <param name="dict">待清除的字典</param> /// <returns>清除后的字典</returns> public static IDictionary<string, string> CleanupDictionary(IDictionary<string, string> dict) { IDictionary<string, string> newDict = new Dictionary<string, string>(); IEnumerator<KeyValuePair<string, string>> dem = dict.GetEnumerator(); while (dem.MoveNext()) { string name = dem.Current.Key; string value = dem.Current.Value; if (!string.IsNullOrEmpty(value)) { newDict.Add(name, value); } } return newDict; }
private static PSObject PopulateFromDictionary( IDictionary<string, object> entries, out ErrorRecord error ) { PSObject pSObject; error = null; PSObject pSObject1 = new PSObject( ); using ( IEnumerator<KeyValuePair<string, object>> enumerator = entries.GetEnumerator( ) ) { while ( enumerator.MoveNext( ) ) { KeyValuePair<string, object> current = enumerator.Current; PSPropertyInfo item = pSObject1.Properties[current.Key]; if ( item != null ) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string duplicateKeysInJsonString = "Duplicate keys in JSON string: {0}"; object[] name = new object[] { item.Name, current.Key }; string str = string.Format( invariantCulture, duplicateKeysInJsonString, name ); error = new ErrorRecord( new InvalidOperationException( str ), "DuplicateKeysInJsonString", ErrorCategory.InvalidOperation, null ); pSObject = null; return pSObject; } else if ( current.Value is IDictionary<string, object> ) { PSObject pSObject2 = JsonObject.PopulateFromDictionary( current.Value as IDictionary<string, object>, out error ); if ( error == null ) { pSObject1.Properties.Add( new PSNoteProperty( current.Key, pSObject2 ) ); } else { pSObject = null; return pSObject; } } else if ( !( current.Value is ICollection<object> ) ) { pSObject1.Properties.Add( new PSNoteProperty( current.Key, current.Value ) ); } else { ICollection<object> objs = JsonObject.PopulateFromList( current.Value as ICollection<object>, out error ); if ( error == null ) { pSObject1.Properties.Add( new PSNoteProperty( current.Key, objs ) ); } else { pSObject = null; return pSObject; } } } return pSObject1; } }
/// <summary> /// This is the worker method responsible for actually retrieving resources from the resource /// store. This method goes out queries the database by asking for a specific ResourceSet and /// Culture and it returns a Hashtable (as IEnumerable) to use as a ResourceSet. /// /// The ResourceSet manages access to resources via IEnumerable access which is ultimately used /// to return resources to the front end. /// /// Resources are read once and cached into an internal Items field. A ResourceReader instance /// is specific to a ResourceSet and Culture combination so there should never be a need to /// reload this data, except when explicitly clearing the reader/resourceset (in which case /// Items can be set to null via ClearResources()). /// </summary> /// <returns>An IDictionaryEnumerator of the resources for this reader</returns> public IDictionaryEnumerator GetEnumerator() { if (Items != null) return Items.GetEnumerator(); lock (_SyncLock) { // Check again to ensure we still don't have items if (Items != null) return Items.GetEnumerator(); // DEPENDENCY HERE // Here's the only place we really access the database and return // a specific ResourceSet for a given ResourceSet Id and Culture DbResourceDataManager Manager = new DbResourceDataManager(); Items = Manager.GetResourceSet(cultureInfo.Name, baseNameField); return Items.GetEnumerator(); } }
public static DictionaryEntry[] GetEntries(IDictionary dictionary) { if (dictionary == null || dictionary.Count == 0) return _zeroEntries; // // IMPORTANT! // // Dictionary entries are enumerated here manually using // IDictionaryEnumerator rather than relying on foreach. Using // IDictionaryEnumerator is faster and more robust. It is faster // because unboxing is avoided by going over // IDictionaryEnumerator.Entry rather than // IDictionaryEnumerator.Current that is used by foreach. It is // more robust because many people may get the implementation of // IDictionary.GetEnumerator wrong, especially if they are // implementing IDictionary<K, V> in .NET Framework 2.0. If the // implementations simply return the enumerator from the wrapped // dictionary then Current will return KeyValuePair<K, V> instead // of DictionaryEntry and cause a casting exception. // DictionaryEntry[] entries = new DictionaryEntry[dictionary.Count]; IDictionaryEnumerator e = dictionary.GetEnumerator(); try { int index = 0; while (e.MoveNext()) entries[index++] = e.Entry; return entries; } finally { IDisposable disposable = e as IDisposable; if (disposable != null) disposable.Dispose(); } }
public StringCollection GenerateSQL(IDictionary<string, StringCollection> dateTables, int daysToAdd) { StringCollection sqlStatements = new StringCollection(); IEnumerator<KeyValuePair<string, StringCollection>> enumer = dateTables.GetEnumerator(); while (enumer.MoveNext()) { string sql = "UPDATE " + enumer.Current.Key + " SET "; StringCollection columnNames = enumer.Current.Value; for (int i = 0; i < columnNames.Count; i++) { sql += columnNames[i] + " = DATEADD(DAY, " + daysToAdd + ", " + columnNames[i] + ")"; if (i != columnNames.Count - 1) { sql += ", "; } } sqlStatements.Add(sql); } return sqlStatements; }
public LinkMessage(IDictionary ht) { IDictionaryEnumerator en = ht.GetEnumerator(); _attributes = new StringDictionary(); while( en.MoveNext() ) { if( en.Key.Equals( "local" ) ) { IDictionary lht = en.Value as IDictionary; if( lht != null ) { _local_ni = NodeInfo.CreateInstance(lht); } } else if( en.Key.Equals( "remote" ) ) { IDictionary rht = en.Value as IDictionary; if( rht != null ) { _remote_ni = NodeInfo.CreateInstance(rht); } } else if (en.Key.Equals( "token" ) ) { _token = (string) ht["token"]; } else { _attributes[ String.Intern( en.Key.ToString() ) ] = String.Intern( en.Value.ToString() ); } } }
public static bool DictionaryEquals(IDictionary d1, IDictionary d2) { if(object.ReferenceEquals(d1, d2)) { return true; } if((d1 == null && d2 != null) || (d1 != null && d2 == null)) { return false; } if(d1.Count == d2.Count) { IDictionaryEnumerator e1 = d1.GetEnumerator(); IDictionaryEnumerator e2 = d2.GetEnumerator(); while(e1.MoveNext()) { e2.MoveNext(); if(!e1.Key.Equals(e2.Key)) { return false; } if(e1.Value == null) { if(e2.Value != null) { return false; } } else if(!e1.Value.Equals(e2.Value)) { return false; } } return true; } return false; }
//internal override void flush(IDictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> threadsAndFields, DocumentsWriter.FlushState state) internal override void flush(IDictionary<object, ICollection<object>> threadsAndFields, DocumentsWriter.FlushState state) { //IDictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> childThreadsAndFields = new Dictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>(); //IDictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> endChildThreadsAndFields = new Dictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>(); IDictionary<object, ICollection<object>> childThreadsAndFields = new Dictionary<object, ICollection<object>>(); IDictionary<object, ICollection<object>> endChildThreadsAndFields = new Dictionary<object, ICollection<object>>(); //IEnumerator<KeyValuePair<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>> it = threadsAndFields.GetEnumerator(); IEnumerator<KeyValuePair<object, ICollection<object>>> it = threadsAndFields.GetEnumerator(); while (it.MoveNext()) { //KeyValuePair<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> entry = it.Current; KeyValuePair<object, ICollection<object>> entry = it.Current; DocInverterPerThread perThread = (DocInverterPerThread)entry.Key; //ICollection<DocFieldConsumerPerField> fields = entry.Value; ICollection<object> fields = entry.Value; //IEnumerator<DocFieldConsumerPerField> fieldsIt = fields.GetEnumerator(); IEnumerator<object> fieldsIt = fields.GetEnumerator(); //IDictionary<DocFieldConsumerPerField, DocFieldConsumerPerField> childFields = new Dictionary<DocFieldConsumerPerField, DocFieldConsumerPerField>(); //IDictionary<DocFieldConsumerPerField, DocFieldConsumerPerField> endChildFields = new Dictionary<DocFieldConsumerPerField, DocFieldConsumerPerField>(); IDictionary<object, object> childFields = new Dictionary<object, object>(); IDictionary<object, object> endChildFields = new Dictionary<object, object>(); while (fieldsIt.MoveNext()) { DocInverterPerField perField = (DocInverterPerField)fieldsIt.Current; childFields[perField.consumer] = perField.consumer; endChildFields[perField.endConsumer] = perField.endConsumer; } childThreadsAndFields[perThread.consumer] = childFields.Keys; // create new collection to provide for deletions in NormsWriter endChildThreadsAndFields[perThread.endConsumer] = new List<object>(endChildFields.Keys); } consumer.flush(childThreadsAndFields, state); endConsumer.flush(endChildThreadsAndFields, state); }
public static Metadata BuildMetadata(IDictionary table) { var metadata = new Metadata { Items = new List<Metadata.ItemsData>() }; if (table != null) { IDictionaryEnumerator e = table.GetEnumerator(); while (e.MoveNext()) { metadata.Items.Add(new Metadata.ItemsData { Key = e.Key.ToString(), Value = e.Value.ToString() }); } } return metadata; }
/// <summary> /// 生成HTTP请求的参数字符串 /// </summary> /// <returns></returns> public static string GenerateQueryString(IDictionary<string, string> parameters) { StringBuilder strBuilder = new StringBuilder(); IEnumerator<KeyValuePair<string, string>> iterator = parameters.GetEnumerator(); //第一个参数不加“&”符号 if(iterator.MoveNext()) { string encodeKey = HttpUtility.UrlEncode(iterator.Current.Key); string encodeValue = HttpUtility.UrlEncode(iterator.Current.Value); strBuilder.Append(encodeKey).Append("=").Append(encodeValue); } //往后每个参数之前加“&”符号 while (iterator.MoveNext()) { string encodeKey = HttpUtility.UrlEncode(iterator.Current.Key); string encodeValue = HttpUtility.UrlEncode(iterator.Current.Value); strBuilder.Append("&").Append(encodeKey).Append("=").Append(encodeValue); } return strBuilder.ToString(); }
public void TestEnvironmentProperty() { Assert.NotEqual(0, new Process().StartInfo.Environment.Count); ProcessStartInfo psi = new ProcessStartInfo(); // Creating a detached ProcessStartInfo will pre-populate the environment // with current environmental variables. IDictionary <string, string> environment = psi.Environment; Assert.NotEqual(environment.Count, 0); int CountItems = environment.Count; environment.Add("NewKey", "NewValue"); environment.Add("NewKey2", "NewValue2"); Assert.Equal(CountItems + 2, environment.Count); environment.Remove("NewKey"); Assert.Equal(CountItems + 1, environment.Count); //Exception not thrown with invalid key Assert.Throws <ArgumentException>(() => { environment.Add("NewKey2", "NewValue2"); }); //Clear environment.Clear(); Assert.Equal(0, environment.Count); //ContainsKey environment.Add("NewKey", "NewValue"); environment.Add("NewKey2", "NewValue2"); Assert.True(environment.ContainsKey("NewKey")); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.ContainsKey("newkey")); Assert.False(environment.ContainsKey("NewKey99")); //Iterating string result = null; int index = 0; foreach (string e1 in environment.Values) { index++; result += e1; } Assert.Equal(2, index); Assert.Equal("NewValueNewValue2", result); result = null; index = 0; foreach (string e1 in environment.Keys) { index++; result += e1; } Assert.Equal("NewKeyNewKey2", result); Assert.Equal(2, index); result = null; index = 0; foreach (KeyValuePair <string, string> e1 in environment) { index++; result += e1.Key; } Assert.Equal("NewKeyNewKey2", result); Assert.Equal(2, index); //Contains Assert.True(environment.Contains(new KeyValuePair <string, string>("NewKey", "NewValue"))); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair <string, string>("nEwKeY", "NewValue"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("NewKey99", "NewValue99"))); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => environment.Contains(new KeyValuePair <string, string>(null, "NewValue99"))); environment.Add(new KeyValuePair <string, string>("NewKey98", "NewValue98")); //Indexed string newIndexItem = environment["NewKey98"]; Assert.Equal("NewValue98", newIndexItem); //TryGetValue string stringout = null; Assert.True(environment.TryGetValue("NewKey", out stringout)); Assert.Equal("NewValue", stringout); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.True(environment.TryGetValue("NeWkEy", out stringout)); Assert.Equal("NewValue", stringout); } stringout = null; Assert.False(environment.TryGetValue("NewKey99", out stringout)); Assert.Equal(null, stringout); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => { string stringout1 = null; environment.TryGetValue(null, out stringout1); }); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => environment.Add(null, "NewValue2")); //Invalid Key to add Assert.Throws <ArgumentException>(() => environment.Add("NewKey2", "NewValue2")); //Remove Item environment.Remove("NewKey98"); environment.Remove("NewKey98"); //2nd occurrence should not assert //Exception not thrown with null key Assert.Throws <ArgumentNullException>(() => { environment.Remove(null); }); //"Exception not thrown with null key" Assert.Throws <KeyNotFoundException>(() => environment["1bB"]); Assert.True(environment.Contains(new KeyValuePair <string, string>("NewKey2", "NewValue2"))); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair <string, string>("NEWKeY2", "NewValue2"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("NewKey2", "newvalue2"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("newkey2", "newvalue2"))); //Use KeyValuePair Enumerator var x = environment.GetEnumerator(); x.MoveNext(); var y1 = x.Current; Assert.Equal("NewKey NewValue", y1.Key + " " + y1.Value); x.MoveNext(); y1 = x.Current; Assert.Equal("NewKey2 NewValue2", y1.Key + " " + y1.Value); //IsReadonly Assert.False(environment.IsReadOnly); environment.Add(new KeyValuePair <string, string>("NewKey3", "NewValue3")); environment.Add(new KeyValuePair <string, string>("NewKey4", "NewValue4")); //CopyTo KeyValuePair <string, string>[] kvpa = new KeyValuePair <string, string> [10]; environment.CopyTo(kvpa, 0); Assert.Equal("NewKey", kvpa[0].Key); Assert.Equal("NewKey3", kvpa[2].Key); environment.CopyTo(kvpa, 6); Assert.Equal("NewKey", kvpa[6].Key); //Exception not thrown with null key Assert.Throws <ArgumentOutOfRangeException>(() => { environment.CopyTo(kvpa, -1); }); //Exception not thrown with null key Assert.Throws <ArgumentException>(() => { environment.CopyTo(kvpa, 9); }); //Exception not thrown with null key Assert.Throws <ArgumentNullException>(() => { KeyValuePair <string, string>[] kvpanull = null; environment.CopyTo(kvpanull, 0); }); }
/// <inheritdoc /> public IEnumerator <KeyValuePair <string, string> > GetEnumerator() => _data.GetEnumerator();
public IEnumerator <KeyValuePair <string, float> > GetEnumerator() { return(_rewards.GetEnumerator()); }
public DictionaryEntryEnumerator(IDictionary dictionary) { _entryEnumerator = dictionary?.GetEnumerator(); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() { return(dict.GetEnumerator()); }
public IEnumerator <KeyValuePair <TFirst, TSecond> > GetEnumerator() { return(forwardDict.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through a collection. /// </summary> /// <returns> /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection. /// </returns> IEnumerator IEnumerable.GetEnumerator() { return(idict.GetEnumerator()); }
public TransformDictionaryEnumerator(IDictionary <SymbolId, object> backing) { _backing = backing.GetEnumerator(); }
} // GetMachineAddress // // Core Serialization and Deserialization support // internal static Header[] GetMessagePropertiesAsSoapHeader(IMessage reqMsg) { IDictionary d = reqMsg.Properties; if (d == null) { return(null); } int count = d.Count; if (count == 0) { return(null); } IDictionaryEnumerator e = (IDictionaryEnumerator)d.GetEnumerator(); // cycle through the headers to get a length bool[] map = new bool[count]; int len = 0, i = 0; IMethodMessage msg = (IMethodMessage)reqMsg; while (e.MoveNext()) { String key = (String)e.Key; if ((key.Length >= 2) && (String.CompareOrdinal(key, 0, "__", 0, 2) == 0) && ( key.Equals("__Args") || key.Equals("__OutArgs") || key.Equals("__Return") || key.Equals("__Uri") || key.Equals("__MethodName") || (key.Equals("__MethodSignature") && (!RemotingServices.IsMethodOverloaded(msg)) && (!msg.HasVarArgs)) || key.Equals("__TypeName") || key.Equals("__Fault") || (key.Equals("__CallContext") && ((e.Value != null) ? (((LogicalCallContext)e.Value).HasInfo == false) : true)) ) ) { i++; continue; } map[i] = true; i++; len++; } if (len == 0) { return(null); } Header[] ret = new Header[len]; e.Reset(); int k = 0; i = 0; while (e.MoveNext()) { Object key = e.Key; if (!map[k]) { k++; continue; } Header h = e.Value as Header; // If the property is not a header, then make a header out of it. if (h == null) { h = new Header( (String)key, e.Value, false, "http://schemas.microsoft.com/clr/soap/messageProperties"); } // < if (i == ret.Length) { InternalRemotingServices.RemotingTrace("HTTPChannel::GetHeaders creating a new array of length " + (i + 1) + "\n"); Header[] newret = new Header[i + 1]; Array.Copy(ret, newret, i); ret = newret; } ret[i] = h; i++; k++; } return(ret); } // GetMessagePropertiesAsSoapHeader
public IEnumerator <KeyValuePair <VisualObject, Interval <int> > > GetEnumerator() => Selection.GetEnumerator();
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() { return baseDictionary.GetEnumerator(); }
public IEnumerator <KeyValuePair <string, object> > GetEnumerator() { return(_payload?.GetEnumerator() ?? Enumerable.Empty <KeyValuePair <string, object> >().GetEnumerator()); }
public IEnumerator <KeyValuePair <string, string> > GetEnumerator() { return(_inner.GetEnumerator()); }
/// <summary> /// Compare a dictionary /// </summary> /// <param name="object1"></param> /// <param name="object2"></param> /// <param name="breadCrumb"></param> void CompareIDictionary(object object1, object object2, string breadCrumb) { IDictionary iDict1 = object1 as IDictionary; IDictionary iDict2 = object2 as IDictionary; if (iDict1 == null) //This should never happen, null check happens one level up { throw new ArgumentNullException("object1"); } if (iDict2 == null) //This should never happen, null check happens one level up { throw new ArgumentNullException("object2"); } try { _parents.Add(object1); _parents.Add(object2); //Objects must be the same length if (iDict1.Count != iDict2.Count) { Differences.Add(string.Format("object1{0}.Count != object2{0}.Count ({1},{2})", breadCrumb, iDict1.Count, iDict2.Count)); if (Differences.Count >= MaxDifferences) { return; } } IDictionaryEnumerator enumerator1 = iDict1.GetEnumerator(); IDictionaryEnumerator enumerator2 = iDict2.GetEnumerator(); while (enumerator1.MoveNext() && enumerator2.MoveNext()) { string currentBreadCrumb = AddBreadCrumb(breadCrumb, "Key", string.Empty, -1); Compare(enumerator1.Key, enumerator2.Key, currentBreadCrumb); if (Differences.Count >= MaxDifferences) { return; } currentBreadCrumb = AddBreadCrumb(breadCrumb, "Value", string.Empty, -1); Compare(enumerator1.Value, enumerator2.Value, currentBreadCrumb); if (Differences.Count >= MaxDifferences) { return; } } } finally { _parents.Remove(object1); _parents.Remove(object2); } }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. /// </returns> /// <filterpriority>1</filterpriority> public IEnumerator <KeyValuePair <Symbol, T> > GetEnumerator() { return(_data.GetEnumerator()); }
public IEnumerator <KeyValuePair <string, object> > GetEnumerator() { return(InnerProperties.GetEnumerator()); }
public DictionaryEnumerator(IDictionary <TKey, TValue> value) { this.impl = value.GetEnumerator(); }
/// <inheritdoc /> IEnumerator <KeyValuePair <string, object> > IEnumerable <KeyValuePair <string, object> > .GetEnumerator() { return(_data.GetEnumerator()); }
public void TestEnvironmentProperty() { Assert.NotEqual(0, new Process().StartInfo.Environment.Count); ProcessStartInfo psi = new ProcessStartInfo(); // Creating a detached ProcessStartInfo will pre-populate the environment // with current environmental variables. IDictionary <string, string> environment = psi.Environment; Assert.NotEqual(0, environment.Count); int countItems = environment.Count; environment.Add("NewKey", "NewValue"); environment.Add("NewKey2", "NewValue2"); Assert.Equal(countItems + 2, environment.Count); environment.Remove("NewKey"); Assert.Equal(countItems + 1, environment.Count); environment.Add("NewKey2", "NewValue2Overridden"); Assert.Equal("NewValue2Overridden", environment["NewKey2"]); //Clear environment.Clear(); Assert.Equal(0, environment.Count); //ContainsKey environment.Add("NewKey", "NewValue"); environment.Add("NewKey2", "NewValue2"); Assert.True(environment.ContainsKey("NewKey")); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.ContainsKey("newkey")); Assert.False(environment.ContainsKey("NewKey99")); //Iterating string result = null; int index = 0; foreach (string e1 in environment.Values.OrderBy(p => p)) { index++; result += e1; } Assert.Equal(2, index); Assert.Equal("NewValueNewValue2", result); result = null; index = 0; foreach (string e1 in environment.Keys.OrderBy(p => p)) { index++; result += e1; } Assert.Equal("NewKeyNewKey2", result); Assert.Equal(2, index); result = null; index = 0; foreach (KeyValuePair <string, string> e1 in environment.OrderBy(p => p.Key)) { index++; result += e1.Key; } Assert.Equal("NewKeyNewKey2", result); Assert.Equal(2, index); //Contains Assert.True(environment.Contains(new KeyValuePair <string, string>("NewKey", "NewValue"))); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair <string, string>("nEwKeY", "NewValue"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("NewKey99", "NewValue99"))); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => environment.Contains(new KeyValuePair <string, string>(null, "NewValue99"))); environment.Add(new KeyValuePair <string, string>("NewKey98", "NewValue98")); //Indexed string newIndexItem = environment["NewKey98"]; Assert.Equal("NewValue98", newIndexItem); //TryGetValue string stringout = null; Assert.True(environment.TryGetValue("NewKey", out stringout)); Assert.Equal("NewValue", stringout); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.True(environment.TryGetValue("NeWkEy", out stringout)); Assert.Equal("NewValue", stringout); } stringout = null; Assert.False(environment.TryGetValue("NewKey99", out stringout)); Assert.Equal(null, stringout); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => { string stringout1 = null; environment.TryGetValue(null, out stringout1); }); //Exception not thrown with invalid key Assert.Throws <ArgumentNullException>(() => environment.Add(null, "NewValue2")); environment.Add("NewKey2", "NewValue2OverriddenAgain"); Assert.Equal("NewValue2OverriddenAgain", environment["NewKey2"]); //Remove Item environment.Remove("NewKey98"); environment.Remove("NewKey98"); //2nd occurrence should not assert //Exception not thrown with null key Assert.Throws <ArgumentNullException>(() => { environment.Remove(null); }); //"Exception not thrown with null key" Assert.Throws <KeyNotFoundException>(() => environment["1bB"]); Assert.True(environment.Contains(new KeyValuePair <string, string>("NewKey2", "NewValue2OverriddenAgain"))); Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair <string, string>("NEWKeY2", "NewValue2OverriddenAgain"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("NewKey2", "newvalue2Overriddenagain"))); Assert.False(environment.Contains(new KeyValuePair <string, string>("newkey2", "newvalue2Overriddenagain"))); //Use KeyValuePair Enumerator string[] results = new string[2]; var x = environment.GetEnumerator(); x.MoveNext(); results[0] = x.Current.Key + " " + x.Current.Value; x.MoveNext(); results[1] = x.Current.Key + " " + x.Current.Value; Assert.Equal(new string[] { "NewKey NewValue", "NewKey2 NewValue2OverriddenAgain" }, results.OrderBy(s => s)); //IsReadonly Assert.False(environment.IsReadOnly); environment.Add(new KeyValuePair <string, string>("NewKey3", "NewValue3")); environment.Add(new KeyValuePair <string, string>("NewKey4", "NewValue4")); //CopyTo - the order is undefined. KeyValuePair <string, string>[] kvpa = new KeyValuePair <string, string> [10]; environment.CopyTo(kvpa, 0); KeyValuePair <string, string>[] kvpaOrdered = kvpa.OrderByDescending(k => k.Value).ToArray(); Assert.Equal("NewKey4", kvpaOrdered[0].Key); Assert.Equal("NewKey2", kvpaOrdered[2].Key); environment.CopyTo(kvpa, 6); Assert.Equal(default(KeyValuePair <string, string>), kvpa[5]); Assert.StartsWith("NewKey", kvpa[6].Key); Assert.NotEqual(kvpa[6].Key, kvpa[7].Key); Assert.StartsWith("NewKey", kvpa[7].Key); Assert.NotEqual(kvpa[7].Key, kvpa[8].Key); Assert.StartsWith("NewKey", kvpa[8].Key); //Exception not thrown with null key Assert.Throws <ArgumentOutOfRangeException>(() => { environment.CopyTo(kvpa, -1); }); //Exception not thrown with null key Assert.Throws <ArgumentException>(() => { environment.CopyTo(kvpa, 9); }); //Exception not thrown with null key Assert.Throws <ArgumentNullException>(() => { KeyValuePair <string, string>[] kvpanull = null; environment.CopyTo(kvpanull, 0); }); }
public IEnumerator <KeyValuePair <string, string> > GetEnumerator() { return(_headers.GetEnumerator()); }
public IEnumerator <KeyValuePair <string, object> > GetEnumerator() { return(backend.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <Key, Data> > GetEnumerator() { return(source.GetEnumerator()); }
/// <summary> /// Returns an enumerator over the fields in this insert row. This /// method is only provided in order to implement <see cref="IEnumerable"/>, /// to permit collection initializers. /// </summary> /// <returns>An enumerator over the fields in this insert row.</returns> IEnumerator IEnumerable.GetEnumerator() => _fields.GetEnumerator();
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <string, V> > GetEnumerator() { return(_subDictionary.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// An enumerator that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() => Items.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() { return(Data.GetEnumerator()); }
public IEnumerator <KeyValuePair <string, ICollection <string> > > GetEnumerator() { return(fields.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns>An enumerator that can be used to iterate through the collection.</returns> public IEnumerator <KeyValuePair <String, Object> > GetEnumerator() { return(_dictionary.GetEnumerator()); }
/// <summary> /// Returns an enumerator for iterating over the Key-Value pairs in the Dictionary. /// </summary> /// <returns>The enumerator.</returns> public IEnumerator <KeyValuePair <string, MultiTypeValue> > GetEnumerator() { return(m_dictionary.GetEnumerator()); }
IEnumerator <KeyValuePair <string, IDictionary <string, object> > > IEnumerable <KeyValuePair <string, IDictionary <string, object> > > .GetEnumerator() { return(dict.GetEnumerator()); }