public static ConcurrentDictionary <TKey, TValue> Merge <TKey, TValue> (this ConcurrentDictionary <TKey, TValue> first, IEnumerable <KeyValuePair <TKey, TValue> > second) { if (first == null && second == null) { return(null); } else if (first == null) { return(new ConcurrentDictionary <TKey, TValue>(second));//.ToDictionary(x => x.Key, x => x.Value)); } else if (second == null) { return(first); } ConcurrentDictionary <TKey, TValue> dictionary = new ConcurrentDictionary <TKey, TValue>(); foreach (var x in first.Concat(second).Where(x => x.Value != null)) { dictionary[x.Key] = x.Value;//重複していたら上書き } return(dictionary); //return new ConcurrentDictionary<TKey, TValue>(first.Concat(second).Where(x => x.Value != null)); //.ToDictionary(x => x.Key, x => x.Value); }
internal static IReadOnlyList <IEntityType> GetAll() { return(addedTemporalEntities .Concat(removedTemporalEntities) .Select(e => e.Value) .ToList()); }
public async Task SaveAsync(string path, byte[] fileData, string extension) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // ImageHelper.RemoveEXIFData(ref fileData); // string destinationFileName = this.GetHash(fileData); string destinationFileName = Path.GetRandomFileName(); destinationFileName = Path.ChangeExtension(destinationFileName, extension); var fileHash = GetHash(fileData); var fileName = $"{path}\\{destinationFileName}"; ProcessedFileHashes.Concat(Directory.GetFiles(path).Where(f => !ProcessedFileHashes.ContainsKey(f)).Select(f => KeyValuePair.Create <string, string>(f, GetHash(GetFileAsBytes(f))))); if (!ProcessedFileHashes.Values.Contains(fileHash)) { //if (!await this.ExistsAsync(path, fileData)) //{ // Does the destination already contain the file? await File.WriteAllBytesAsync(fileName, fileData); ProcessedFileHashes.TryAdd(fileName, fileHash); Trace.WriteLine($"Processed file: {fileName}"); //} //else //{ // Trace.WriteLine($"File {fileName} already exists. Skipping .."); //} } else { Trace.WriteLine($"Duplicate file found {fileName}. Skipping ..."); } return; }
public IEnumerator <KeyValuePair <string, Topic> > GetEnumerator() { return(_topics.Concat(_groupTopics).GetEnumerator()); }
/// <inheritdoc /> public IEnumerable <KeyValuePair <VariableName, object> > GetState() => _scopedStateDictionary.Concat(_fixedState);