private static string Part0(string input, Func <IEnumerable <int>, int> reduceFunc) { var dict = new Dictionary <Tuple <string, string>, int>(); var locs = new HashSet <string>(); foreach (var line in input.Lines()) { var words = line.Words().ToList(); var fromTo = new List <string> { words[0], words[2] }; fromTo.Sort(); var dist = words.Last().ToInt(); var key = new Tuple <string, string>(fromTo[0], fromTo.Last()); dict.Add(key, dist); locs.TryAdd(fromTo[0]); locs.TryAdd(fromTo[1]); } var routes = locs.ToList().GenerateRoutes(); return(reduceFunc(routes.Select(route => CalculateRoute(dict, route.ToList()))) .ToString()); }
protected ObjectSchema() { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(); List <PropertyDefinition> list = new List <PropertyDefinition>(); List <FieldInfo> list2 = ReflectionHelper.AggregateTypeHierarchy <FieldInfo>(base.GetType(), new AggregateType <FieldInfo>(ReflectionHelper.AggregateStaticFields)); IEnumerable <FieldInfo> declaredFields = base.GetType().GetTypeInfo().DeclaredFields; foreach (FieldInfo fieldInfo in list2) { object value = fieldInfo.GetValue(null); if (typeof(ProviderPropertyDefinition).GetTypeInfo().IsAssignableFrom(fieldInfo.FieldType.GetTypeInfo()) && value == null) { throw new InvalidOperationException(string.Format("Property definition '{0}' is not initialized. This can be caused by loop dependency between initialization of one or more static fields.", fieldInfo.Name)); } ProviderPropertyDefinition providerPropertyDefinition = value as ProviderPropertyDefinition; if (providerPropertyDefinition != null) { bool flag = false; foreach (FieldInfo fieldInfo2 in declaredFields) { if (fieldInfo2.Name.Equals(fieldInfo.Name) && !this.IsSameFieldHandle(fieldInfo2, fieldInfo)) { flag = true; break; } } if (!this.containsCalculatedProperties && providerPropertyDefinition.IsCalculated) { this.containsCalculatedProperties = true; } if (!flag) { if (!providerPropertyDefinition.IsFilterOnly) { hashSet.TryAdd(providerPropertyDefinition); if (!providerPropertyDefinition.IsCalculated) { continue; } using (ReadOnlyCollection <ProviderPropertyDefinition> .Enumerator enumerator3 = providerPropertyDefinition.SupportingProperties.GetEnumerator()) { while (enumerator3.MoveNext()) { ProviderPropertyDefinition item = enumerator3.Current; hashSet.TryAdd(item); } continue; } } if (!providerPropertyDefinition.IsCalculated) { list.Add(providerPropertyDefinition); } } } } this.AllProperties = new ReadOnlyCollection <PropertyDefinition>(hashSet.ToArray()); this.AllFilterOnlyProperties = new ReadOnlyCollection <PropertyDefinition>(list.ToArray()); this.InitializePropertyCollections(); }
private static ICollection <NativeStorePropertyDefinition> GetNativePropertyDefinitions <T>(PropertyDependencyType targetDependencyType, ICollection <T> propertyDefinitions, bool hashSetOrList, Predicate <NativeStorePropertyDefinition> addToCollection) where T : PropertyDefinition { EnumValidator.AssertValid <PropertyDependencyType>(targetDependencyType); if (propertyDefinitions == null) { return(StorePropertyDefinition.EmptyNativeStoreProperties); } int num = (propertyDefinitions.Count >= StorePropertyDefinition.dependencyEstimates.Length) ? propertyDefinitions.Count : StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count]; ICollection <NativeStorePropertyDefinition> collection = null; Action <NativeStorePropertyDefinition> action; if (hashSetOrList) { HashSet <NativeStorePropertyDefinition> nativePropertyDefinitionsSet = new HashSet <NativeStorePropertyDefinition>(num); action = delegate(NativeStorePropertyDefinition item) { if (addToCollection == null) { nativePropertyDefinitionsSet.TryAdd(item); return; } if (addToCollection(item)) { nativePropertyDefinitionsSet.TryAdd(item); } }; collection = nativePropertyDefinitionsSet; } else { IList <NativeStorePropertyDefinition> loadList = new List <NativeStorePropertyDefinition>(num); action = delegate(NativeStorePropertyDefinition item) { if (addToCollection == null) { loadList.Add(item); return; } if (addToCollection(item)) { loadList.Add(item); } }; collection = loadList; } foreach (T t in propertyDefinitions) { PropertyDefinition propertyDefinition = t; StorePropertyDefinition storePropertyDefinition = InternalSchema.ToStorePropertyDefinition(propertyDefinition); storePropertyDefinition.ForEachMatch(targetDependencyType, action); } int count = collection.Count; if (count != num && propertyDefinitions.Count < StorePropertyDefinition.dependencyEstimates.Length) { Interlocked.Exchange(ref StorePropertyDefinition.dependencyEstimates[propertyDefinitions.Count], count); } return(collection); }
public static LuaNativeFunction lua_atpanic(lua_State L, LuaNativeFunction panicFunction) { #if SAVE_FUNC savedFn.TryAdd(panicFunction); #endif IntPtr newPanicPtr = panicFunction.ToFunctionPointer(); return(lua_atpanic(L, newPanicPtr).ToLuaFunction()); }
private void AddShadowPropertiesToAllPropertiesList() { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(); foreach (PropertyDefinition propertyDefinition in base.AllProperties) { hashSet.TryAdd(propertyDefinition); ADPropertyDefinition adpropertyDefinition = propertyDefinition as ADPropertyDefinition; if (adpropertyDefinition != null && adpropertyDefinition.ShadowProperty != null) { hashSet.TryAdd(adpropertyDefinition.ShadowProperty); } } base.AllProperties = new ReadOnlyCollection <PropertyDefinition>(hashSet.ToArray()); base.InitializePropertyCollections(); }
private static void GenerateDsnBody(MessageItem message, Stream outputStream, DsnHumanReadableWriter dsnWriter, HeaderList headerList, out CultureInfo cultureInfo, out Charset charset) { message.Load(ReportMessageSchema.Instance.AutoloadProperties); MailboxSession mailboxSession = message.Session as MailboxSession; List <DsnRecipientInfo> list = new List <DsnRecipientInfo>(message.Recipients.Count); HashSet <string> hashSet = new HashSet <string>(); foreach (Recipient recipient in message.Recipients) { list.Add(new DsnRecipientInfo(recipient.Participant.DisplayName, recipient.Participant.EmailAddress, recipient.Participant.RoutingType, DsnMdnUtil.GetMimeDsnRecipientStatusCode(recipient).Value, recipient.GetValueOrDefault <string>(InternalSchema.SupplementaryInfo))); string valueOrDefault = recipient.GetValueOrDefault <string>(InternalSchema.RemoteMta); if (!string.IsNullOrEmpty(valueOrDefault)) { hashSet.TryAdd(valueOrDefault); } } StringBuilder stringBuilder = new StringBuilder(hashSet.Count * 20); foreach (string value in hashSet) { stringBuilder.Append(value); stringBuilder.Append(", "); } dsnWriter.CreateDsnHumanReadableBody(outputStream, ReportMessage.GetDsnCultures(mailboxSession, headerList, dsnWriter), message.GetValueOrDefault <string>(InternalSchema.OriginalSubject), list, ReportMessage.GetDsnFlags(message.ClassName), message.GetValueOrDefault <string>(InternalSchema.ReportingMta, string.Empty), (stringBuilder.Length > 0) ? stringBuilder.ToString(0, stringBuilder.Length - ", ".Length) : null, null, headerList, out cultureInfo, out charset); }
static TrackInfo ExtractTrackInfo(string originalFileName, HashSet <string> commonTokens, string fileName) { string RemoveCommonTokens(string s) => s .Apply(StringUtils.SplitToTokens) .Filter(x => !commonTokens.Contains(x)) .Apply(ws => string.Join(' ', ws)); var trackNoRegex = new Regex("(?<n>\\d+) ?[-.] ?"); var match = trackNoRegex.Matches(fileName).LastOrDefault(); if (match == null) { return(new TrackInfo( fileName: originalFileName, trackNumber: None, trackTitle: fileName, meaningfulTrackTitleTokens: RemoveCommonTokens(fileName) )); } var trackNumber = int.Parse(match.Groups["n"].Value); var trackTitle = fileName.Substring(match.Index + match.Length).Trim(); commonTokens = commonTokens.TryAdd(trackNumber.ToString("0")).TryAdd(trackNumber.ToString("00")); return(new TrackInfo( fileName: originalFileName, trackNumber: trackNumber, trackTitle: trackTitle, meaningfulTrackTitleTokens: RemoveCommonTokens(trackTitle) )); }
public IEnumerable <string> GetOptions(MarkovDatum token, int optionCount) { if (optionCount <= 0) { throw new ArgumentException("You must require at least one option.", "optionCount"); } if (token.TrailingTokens.Count <= optionCount) //uncommon token, very few trailing tokens { foreach (var Trailing in token.TrailingTokens.Keys) { yield return(Trailing); } } else { HashSet <string> Options = new HashSet <string>(); do { var Option = GetOption(token); if (Options.TryAdd(Option)) { yield return(Option); } } while (Options.Count < optionCount); } }
protected override void HandleNonAuthoritativeDomains(EmailAddressPolicy policy, HashSet <SmtpDomain> domains) { HashSet <SmtpDomain> hashSet = new HashSet <SmtpDomain>(policy.NonAuthoritativeDomains.Count); foreach (ProxyAddressTemplate template in policy.NonAuthoritativeDomains) { SmtpDomain item; if (UpdateEmailAddressPolicy.DomainValidator.TryGetDomain(template, out item)) { hashSet.TryAdd(item); } } foreach (SmtpDomain smtpDomain in hashSet) { if (!domains.Contains(smtpDomain)) { this.warningWriter(Strings.UnexpectedNonAuthoritativeDomain(smtpDomain)); } } foreach (SmtpDomain smtpDomain2 in domains) { if (!hashSet.Contains(smtpDomain2)) { this.warningWriter(Strings.MissingNonAuthoritativeDomain(smtpDomain2)); } } }
private static NativeStorePropertyDefinition[] CreatePrefetchPropertySet <T>(ICollection <NativeStorePropertyDefinition> oldSet, ICollection <T> additionalProperties) where T : PropertyDefinition { HashSet <NativeStorePropertyDefinition> hashSet = new HashSet <NativeStorePropertyDefinition>(oldSet); ICollection <NativeStorePropertyDefinition> nativePropertyDefinitions = StorePropertyDefinition.GetNativePropertyDefinitions <T>(PropertyDependencyType.AllRead, additionalProperties); foreach (NativeStorePropertyDefinition item in nativePropertyDefinitions) { hashSet.TryAdd(item); } return(hashSet.ToArray()); }
public OverlayUiOperator GetChecker() { if (ids.IsEmpty()) { uiCanvas?.Show(); } int id = idGenerator.Get(); ids.TryAdd(id); return(new OverlayUiOperator(actionToAddShownAction, notifyTerminationAction, id)); }
private static PropertyDefinition[] GetPropertyDefinitions(StoreObjectConstraint[] constraints) { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(); foreach (StoreObjectConstraint storeObjectConstraint in constraints) { foreach (PropertyDefinition item in storeObjectConstraint.RelevantProperties) { hashSet.TryAdd(item); } } return(hashSet.ToArray()); }
internal HashSet <PropertyDefinition> GetPropertiesNeededForResolution(IEnumerable <PropertyDefinition> propertyDefinitions) { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(); foreach (PropertyDefinition propertyDefinition in propertyDefinitions) { foreach (PropertyDefinition item in this.GetPropertiesNeededForResolution(propertyDefinition)) { hashSet.TryAdd(item); } } return(hashSet); }
void IBackgroundUiBank.NotifyEntried(IBackgroundUiCanvas backgroundUiCanvas) { entriedCanvases.RemoveWhere(c => c.IsDestroyed); entriedCanvases.TryAdd(backgroundUiCanvas); backgroundUiCanvasList.RemoveAll(c => c.IsDestroyed); int forefrontCanvasIndex = GetForefrontCanvasIndex(backgroundUiCanvasList, new FixedHashSet <IBackgroundUiCanvas>(entriedCanvases)); for (int i = 0; i < forefrontCanvasIndex; i++) { backgroundUiCanvasList[i].Exit(); } }
private static void PatchAssemblyFull(string key, List <Assembly> assemblies) { var meths = new HashSet <MethodInfo>(); foreach (var asm in assemblies) { try { var asmName = $"{asm.GetName().Name}.dll"; if (patchedAssemblies.Contains(asm.FullName)) { Warn($"patching {asmName} failed, already patched"); continue; } patchedAssemblies.Add(asm.FullName); foreach (var type in AccessTools.GetTypesFromAssembly(asm)) { var methods = AccessTools.GetDeclaredMethods(type).ToList(); foreach (var m in methods) { try { if (ValidMethod(m) && m.DeclaringType == type) { meths.TryAdd(m); } } catch (Exception e) { ReportException(e, $"Skipping method {GetSignature(m)}"); } } } } catch (Exception e) { ReportException(e, $"Failed to patch the assembly {asm.FullName}"); } } var asms = assemblies.Select(a => a.GetName().Name + ".dll").Join(); var asmString = assemblies.Count > 1 ? "assemblies" : "assembly"; Messages.Message($"Attempting to patch {meths.Count} methods from the {asmString} [{asms}]", MessageTypeDefOf.CautionInput, false); MethodTransplanting.UpdateMethods(GUIController.types[key], meths); }
private static HashSet <int> GetGroupFor(ProgramPathCollection <int> paths, HashSet <int> seen, int key) { seen.Add(key); foreach (var i in paths.GetValue(key)) { if (seen.Contains(i)) { continue; } foreach (var h in GetGroupFor(paths, seen, i)) { seen.TryAdd(h); } } return(seen); }
// Token: 0x06000488 RID: 1160 RVA: 0x00019F24 File Offset: 0x00018124 protected ADPropertyUnionSchema() { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(); HashSet <PropertyDefinition> hashSet2 = new HashSet <PropertyDefinition>(); foreach (ObjectSchema objectSchema in this.ObjectSchemas) { foreach (PropertyDefinition item in objectSchema.AllProperties) { hashSet.TryAdd(item); } foreach (PropertyDefinition item2 in objectSchema.AllFilterOnlyProperties) { hashSet2.TryAdd(item2); } } base.AllProperties = new ReadOnlyCollection <PropertyDefinition>(hashSet.ToArray()); base.AllFilterOnlyProperties = new ReadOnlyCollection <PropertyDefinition>(hashSet2.ToArray()); base.InitializePropertyCollections(); base.InitializeADObjectSchemaProperties(); }
public void Validate(EmailAddressPolicy policy) { HashSet <SmtpDomain> hashSet = new HashSet <SmtpDomain>(); foreach (ProxyAddressTemplate proxyAddressTemplate in UpdateEmailAddressPolicy.DomainValidator.EnumerateTemplates(policy)) { SmtpDomain smtpDomain; if (UpdateEmailAddressPolicy.DomainValidator.TryGetDomain(proxyAddressTemplate, out smtpDomain)) { UpdateEmailAddressPolicy.DomainValidator.TemplateValidationEntry bestMatch = this.map.GetBestMatch(smtpDomain); if (bestMatch == null || !bestMatch.AllowsPolicies) { this.WriteInvalidTemplate(proxyAddressTemplate as SmtpProxyAddressTemplate); } else if (!bestMatch.IsAuthoritative) { hashSet.TryAdd(smtpDomain); } } } this.HandleNonAuthoritativeDomains(policy, hashSet); }
private Dictionary <PropertyDefinition, AcrPropertyProfile.ValuesToResolve> GetValuesToResolve(PropertyBag acrPropertyBag) { HashSet <PropertyDefinition> hashSet = new HashSet <PropertyDefinition>(this.propertyTrackingCache.Count); foreach (KeyValuePair <PropertyDefinition, AcrPropertyBag.TrackingInfo> keyValuePair in this.propertyTrackingCache) { if (keyValuePair.Value.Dirty) { foreach (PropertyDefinition item in this.profile.GetPropertiesNeededForResolution(keyValuePair.Key)) { hashSet.TryAdd(item); } } } Dictionary <PropertyDefinition, AcrPropertyProfile.ValuesToResolve> dictionary = new Dictionary <PropertyDefinition, AcrPropertyProfile.ValuesToResolve>(); if (hashSet.Count > 0) { this.propertyBag.Load(hashSet); acrPropertyBag.Load(hashSet); foreach (PropertyDefinition propertyDefinition in hashSet) { AcrPropertyBag.TrackingInfo trackingInfo; this.propertyTrackingCache.TryGetValue(propertyDefinition, out trackingInfo); object clientValue = this.propertyBag.TryGetProperty(propertyDefinition); if (acrPropertyBag == this.propertyBag) { dictionary.Add(propertyDefinition, new AcrPropertyProfile.ValuesToResolve(clientValue, trackingInfo.ServerValue, trackingInfo.OriginalValue)); } else { object serverValue = acrPropertyBag.TryGetProperty(propertyDefinition); dictionary.Add(propertyDefinition, new AcrPropertyProfile.ValuesToResolve(clientValue, serverValue, (trackingInfo != null) ? trackingInfo.OriginalValue : null)); } } } return(dictionary); }
public static IList <string> ParseUserSpecifiedProperties(string[] userSpecifiedProperties) { HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase); if (userSpecifiedProperties != null) { if (userSpecifiedProperties.Length == 1) { userSpecifiedProperties = userSpecifiedProperties[0].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } foreach (string text in userSpecifiedProperties) { if (!string.IsNullOrWhiteSpace(text)) { hashSet.TryAdd(text.Trim()); } } } return(hashSet.ToList <string>()); }
/// <summary> /// 获取插件容器 /// </summary> /// <returns> </returns> private static CompositionContainer GetContainer() { var dir = AppDomain.CurrentDomain.RelativeSearchPath; var files = new HashSet<string>( Directory.EnumerateFiles(dir, "*.dll", SearchOption.AllDirectories) .Union(Directory.EnumerateFiles(dir, "*.exe", SearchOption.AllDirectories)) , StringComparer.OrdinalIgnoreCase); var catalogs = new AggregateCatalog(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var loaded = new HashSet<string>(); foreach (var a in assemblies) { if (a.CanLoad() && loaded.TryAdd(a)) { a.LoadTypes()?.ForEach(catalogs.Catalogs.Add); } if (a.IsDynamic == false) { Uri filePath; if (Uri.TryCreate(a.EscapedCodeBase, UriKind.Absolute, out filePath) && filePath.IsLoopback) { files.Remove(filePath.LocalPath); } files.Remove(a.Location); } } LogServices.Logger?.Write(TraceEventType.Start, $"扫描动态文件 -> 文件个数:{files.Count}"); if (files.Count > 0) { var domain = AppDomain.CreateDomain("mef"); LogServices.Logger?.Write(TraceEventType.Start, "新建临时程序域"); foreach (var file in files) { try { var bytes = File.ReadAllBytes(file); var ass = domain.Load(bytes); if (loaded.TryAdd(ass) && ass.CanLoad()) { Assembly.Load(bytes).LoadTypes()?.ForEach(catalogs.Catalogs.Add); } } catch (Exception ex) { LogServices.Logger?.Write(TraceEventType.Error, $"文件加载失败{file}", ex); } } LogServices.Logger?.Write(TraceEventType.Stop, "卸载程序域"); AppDomain.Unload(domain); } LogServices.Logger?.Write(TraceEventType.Stop, "文件处理完成"); return new SelectionPriorityContainer(catalogs); }
void TestTriangleIds(Navmesh *lct) { if (_previousTriangles.IsCreated) { _previousTriangles.Dispose(); } _previousTriangles = _triangles.ToNativeArray(); _triangles.Clear(); _closed.Clear(); _removedTriangles.Clear(); var e = lct->GetEdgeEnumerator(true); while (e.MoveNext()) { if (!Math.Contains(e.Current->Org->Point, -lct->Extent, lct->Extent)) { continue; } if (_closed.Contains((IntPtr)e.Current)) { continue; } if (e.Current->TriangleId == 0) { Debug.Log("unset Triangle Id"); Assert.IsTrue(false); } if (!_triangles.TryAdd(e.Current->TriangleId)) { Debug.Log("duplicate Triangle Id"); Assert.IsTrue(false); } if (e.Current->TriangleId != e.Current->LNext->TriangleId || e.Current->TriangleId != e.Current->LPrev->TriangleId) { Debug.Log("inconsistent triangle ids"); Assert.IsTrue(false); } _closed.TryAdd((IntPtr)e.Current); _closed.TryAdd((IntPtr)e.Current->LNext); _closed.TryAdd((IntPtr)e.Current->LPrev); } for (int i = 0; i < _previousTriangles.Length; i++) { if (!_triangles.Contains(_previousTriangles[i])) { _removedTriangles.Add(_previousTriangles[i]); } } var destroyed = new HashSet <int>(64, Allocator.Temp); var enumerator = lct->DestroyedTriangles.GetEnumerator(); while (enumerator.MoveNext()) { destroyed.TryAdd(enumerator.Current); } for (int i = 0; i < _removedTriangles.Length; i++) { var id = _removedTriangles[i]; if (!destroyed.Remove(id)) { Debug.Log($"Destroyed triangle {id} not reported"); Assert.IsTrue(false); } } var remaining = destroyed.GetEnumerator(); while (remaining.MoveNext()) { if (_triangles.Contains(remaining.Current)) { Debug.Log($"Triangle {remaining.Current} incorrectly reported as destroyed"); Assert.IsTrue(false); } } destroyed.Dispose(); }
public void op_TryAdd_ICollectionOfT_T_whenTrue() { var list = new HashSet<string>(); Assert.True(list.TryAdd("example")); }
// Token: 0x06001767 RID: 5991 RVA: 0x0008B328 File Offset: 0x00089528 public MailboxUtilityDeviceInfo GetDevice(DeviceIdentity deviceIdentity) { using (Folder folder = Folder.Bind(this.MailboxSessionForUtility, this.MailboxSessionForUtility.GetDefaultFolderId(DefaultFolderType.Configuration))) { StoreObjectId folderIdByDisplayName = MailboxUtility.GetFolderIdByDisplayName(folder, "Microsoft-Server-ActiveSync"); if (folderIdByDisplayName == null) { return(null); } using (Folder folder2 = Folder.Bind(this.MailboxSessionForUtility, folderIdByDisplayName)) { StoreObjectId folderIdByDisplayName2 = MailboxUtility.GetFolderIdByDisplayName(folder2, deviceIdentity.DeviceType); if (folderIdByDisplayName2 == null) { return(null); } using (QueryResult queryResult = folder2.FolderQuery(FolderQueryFlags.DeepTraversal, null, null, MailboxUtility.folderProperties)) { QueryFilter seekFilter = new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.DisplayName, deviceIdentity.DeviceId); queryResult.SeekToCondition(SeekReference.OriginBeginning, seekFilter); object[] array = null; object[][] rows; while (array == null && (rows = queryResult.GetRows(10000)) != null && rows.Length > 0) { for (int i = 0; i < rows.Length; i++) { StoreObjectId storeObjectId = rows[i][1] as StoreObjectId; if (storeObjectId.CompareTo(folderIdByDisplayName2) == 0) { array = rows[i]; break; } } } if (array != null) { StoreObjectId storeOrVersionedId = MailboxUtility.GetStoreOrVersionedId(array[0]); if (storeOrVersionedId == null) { return(null); } using (Folder folder3 = Folder.Bind(this.MailboxSessionForUtility, storeOrVersionedId)) { using (QueryResult queryResult2 = folder3.ItemQuery(ItemQueryType.None, null, null, MailboxUtility.itemSubjectProperty)) { object[][] rows2 = queryResult2.GetRows(10000); HashSet <string> hashSet = new HashSet <string>(); while (rows2 != null && rows2.Length > 0) { for (int j = 0; j < rows2.Length; j++) { string text = rows2[j][0] as string; if (text != null) { hashSet.TryAdd(text); } } rows2 = queryResult2.GetRows(10000); } return(new MailboxUtilityDeviceInfo(deviceIdentity.DeviceId, deviceIdentity.DeviceType, storeOrVersionedId, hashSet)); } } } } } } return(null); }
private void Subscribe(Tuple<SecurityId, DataType> subscription) { _subscriptions.TryAdd(subscription); }
public void op_TryAdd_ICollectionOfT_T_whenTrue() { var list = new HashSet <string>(); Assert.True(list.TryAdd("example")); }
private IEnumerable <string> GetPossibleNames(string episodeName) { // 4! = 24 combinations var priorityPermutations = new List <Func <string, string> > { RemoveSquareBrackets, RemoveTriangleBrackets, SpliceOnHyphen }.GetPermutations().ToArray(); // 5! = 120 combinations var secondary = new List <Func <string, string> > { SpliceOnHyphen, RemoveSeasonLetter, RemoveRomanNumerals, RemoveBuzzwords, RemoveSpecialSeasonWords }; var secondaryPermutations = secondary.GetPermutations() // add an extra sequence to remove circular brackets (some shows have a year on the end). .Concat(new[] { secondary.Append(RemoveCircularBrackets) }) .ToList(); // 2! = 2 combinations var tertiaryPermutations = new List <Func <string, string> > { RemoveNumbersAtEnd, RemoveLastWord }.GetPermutations().ToArray(); HashSet <string> results = new HashSet <string>(); // This needs better comments and refactoring. // In Short: // We randomize our functions with permutations, our secondary // functions we want to execute each individually, not just all. foreach (var priorityActions in priorityPermutations) { string result1 = TryAggregateActions(episodeName, priorityActions).Trim(); results.TryAdd(result1); results.TryAdd(secondary.Select(x => x(result1))); foreach (var secondaryActions in secondaryPermutations) { var secondarySequence = priorityActions.Concat(secondaryActions).ToArray(); string result2 = TryAggregateActions(episodeName, secondarySequence).Trim(); results.TryAdd(result2); foreach (var tertiaryActions in tertiaryPermutations) { var tertiarySequence = secondarySequence.Concat(tertiaryActions).ToArray(); string result3 = TryAggregateActions(episodeName, tertiarySequence).Trim(); results.TryAdd(result3); } } } return(results .Where(x => x.Length > 2 || x.Length == episodeName.Length) .Select(x => x.Trim()) // Prioritize the longest values // We do this because going down the permutations will only result // in small results - and these are commonly less likely. .OrderByDescending(x => x) .Distinct() .DefaultIfEmpty(episodeName) .ToArray()); }
// Token: 0x0600108A RID: 4234 RVA: 0x00060890 File Offset: 0x0005EA90 internal void GetMetricsForSingleGroup(IRecipientSession session, string groupDN, TypedHashSet calculatedGroups, Dictionary <string, object> parentGroupDictionary, IList <string> parentGroupList) { ADObjectId id = new ADObjectId(groupDN); ADRawEntry group = null; ADOperationResult adoperationResult = this.TryRunPerGroupADOperation(delegate { group = session.ReadADRawEntry(id, GroupMetricsGenerator.groupProperties); }, groupDN); if (!adoperationResult.Succeeded || group == null) { return; } ulong hash = GroupMetricsUtility.GetHash(group.Id.ObjectGuid); if (calculatedGroups.Contains(hash)) { return; } int externalMemberCount = 0; HashSet <ulong> allMemberHashes = new HashSet <ulong>(2000); ADRecipientExpansion expander = new ADRecipientExpansion(session, false); adoperationResult = this.TryRunPerGroupADOperation(delegate { if (GroupMetricsUtility.Fault == GroupMetricsFault.TransientExceptionInExpansion) { throw new ADTransientException(new LocalizedString("Fault Injection")); } if (GroupMetricsUtility.Fault == GroupMetricsFault.InvalidCredentialExceptionInExpansion) { throw new ADInvalidCredentialException(new LocalizedString("Fault Injection")); } if (GroupMetricsUtility.Fault == GroupMetricsFault.PermanentExceptionInExpansion) { throw new DataSourceOperationException(new LocalizedString("Fault Injection")); } expander.Expand(group, delegate(ADRawEntry member, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType) { this.RunData.ThrowIfShuttingDown(); if (recipientExpansionType == ExpansionType.GroupMembership) { return(ExpansionControl.Continue); } ulong hash2 = GroupMetricsUtility.GetHash(member.Id.ObjectGuid); if (allMemberHashes.TryAdd(hash2) && this.IsExternal(member)) { externalMemberCount++; } if (allMemberHashes.Count >= 1000) { return(ExpansionControl.Terminate); } if (recipientExpansionType != ExpansionType.None) { return(ExpansionControl.Skip); } return(ExpansionControl.Continue); }, (ExpansionFailure failure, ADRawEntry member, ExpansionType recipientExpansionType, ADRawEntry parent, ExpansionType parentExpansionType) => ExpansionControl.Continue); }, groupDN); if (!adoperationResult.Succeeded) { return; } MultiValuedProperty <ADObjectId> multiValuedProperty = group[ADRecipientSchema.MemberOfGroup] as MultiValuedProperty <ADObjectId>; foreach (ADObjectId adobjectId in multiValuedProperty) { string distinguishedName = adobjectId.DistinguishedName; if (!parentGroupDictionary.ContainsKey(distinguishedName)) { parentGroupDictionary.Add(distinguishedName, null); parentGroupList.Add(distinguishedName); } } int count = allMemberHashes.Count; calculatedGroups.Add(hash); this.groupsExpanded++; int oldValue = (int)group[ADGroupSchema.GroupMemberCount]; int oldValue2 = (int)group[ADGroupSchema.GroupExternalMemberCount]; if (this.ShouldSaveToAD(oldValue, count) || this.ShouldSaveToAD(oldValue2, externalMemberCount)) { this.SaveGroupMetricsToAD(session, group, count, externalMemberCount); } }