public PrincipalContext GetPricipalContext(String name, params ContextType[] ctx) { if (name == null) { return(null); } PrincipalContext ret = null; lock (_lock) { if (contextCache.TryGetValue(name, out ret)) { return(ret); } } PrincipalContext created = createPricipalContext(name, ContextType.Machine, ContextType.Domain, ContextType.ApplicationDirectory); lock (_lock) { if (contextCache.TryGetValue(name, out ret)) { Utils.FreeAndNil(ref created); return(ret); } contextCache.Add(name, created); return(created); } }
public SecurityAccount GetAccount(String name) { SecurityAccount ret = null; lock (_lock) { if (accountCache.TryGetValue(name, out ret)) { return(ret); } } return(null); }
/// <summary> /// <para>- If name!=null, the element associated with that name is returned or an exception is thrown</para> /// <para>- If altName != null, a check is done for altName. If found, it is returned.</para> /// <para>- Otherwise the 1st element is returned (if count==1), or an exception is thrown.</para> /// </summary> public T GetByNamesOrFirst(String name, String altName) { if (name != null) { return(GetByName(name)); } T item = null; if (altName != null) { if (namedItems.TryGetValue(altName, out item)) { return(item); } } switch (namedItems.Count) { case 0: throw new BMException("'{0}' collection contains no elements. Cannot get the correct element.", typeof(T).FullName); case 1: return(this[0]); default: throw new BMException("'{0}' collection contains {1} elements. Cannot auto-configure the correct element, since it will be ambigious.", typeof(T).FullName, namedItems.Count); } }
public IPostProcessor GetPostProcessor(string processor) { IPostProcessor x; if (postProcessors.TryGetValue(processor, out x)) { return(x); } throw new BMException("Postprocessor [{0}] not found.", processor); }
public static _TagType GetTagType(StringDict <_TagType> tagDict, String tag) { if (String.IsNullOrEmpty(tag)) { return(_TagType.Unknown); } _TagType ret; if (tagDict.TryGetValue(tag.ToLowerInvariant(), out ret)) { return(ret); } return(_TagType.Unknown); }
/// <summary> /// Gets an existing endpoint from the cache or creates and initializes a new one. /// If a new endpoint is instantiated, its optionally wrapped by a list of postprocessors /// </summary> public IDataEndpoint CreateOrGetDataEndpoint(PipelineContext ctx, String name, String postProcessors) { String endpointName = getEndpointName(name, ctx.DatasourceAdmin); EndpointCacheEntry epEntry; if (endPointCache == null) { endPointCache = new StringDict <EndpointCacheEntry>(); } if (endPointCache.TryGetValue(endpointName, out epEntry)) { if (postProcessors == null || String.Equals(postProcessors, epEntry.PostProcessors, StringComparison.OrdinalIgnoreCase)) { return(epEntry.Endpoint); } throw new BMException("Endpoint [{0}] is used with different post-processors [{1}] adn [{2}].", epEntry.Name, epEntry.PostProcessors, postProcessors); } IDataEndpoint ep = this.ImportEngine.Endpoints.GetDataEndpoint(ctx, endpointName); if (postProcessors == null) { postProcessors = DefaultPostProcessors; } if (postProcessors != null) { ep = wrapPostProcessors(ctx, ep, postProcessors); } epEntry = new EndpointCacheEntry(endpointName, ep, postProcessors); endPointCache.Add(endpointName, epEntry); if (started) { epEntry.Endpoint.Start(ctx); } return(epEntry.Endpoint); }
public ESIndexDefinition GetDefinition(String name, bool mustExcept = true) { ESIndexDefinition x; if (name != null && dict.TryGetValue(name, out x)) { return(x); } if (!mustExcept) { return(null); } throw new BMException("Index '{0}' is not defined in the config.", name); }
private int keyToIndex(string key) { int ret; if (lenient) { if (lenientIndexes == null) { lenientIndexes = new StringDict <int>(false); } if (lenientIndexes.TryGetValue(key, out ret)) { return(ret); } ret = -1; if (!selectiveExport) { foreach (var kvp in lenientIndexes) { if (kvp.Value > ret) { ret = kvp.Value; } } ret++; } lenientIndexes.Add(key, ret); return(ret); } String key2 = key; switch (key[0]) { case 'f': case 'F': key2 = key.Substring(1); break; } if (int.TryParse(key2, NumberStyles.Integer, Invariant.Culture, out ret)) { return(ret); } throw new BMException("Fieldname '{0}' should be a number or an 'F' with a number, to make sure that the field is written on the correct place in the CSV file.", key); }
private void diagnose() { StringComparer cmp; bool caseSens = checkBox1.Checked; cmp = caseSens ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase; listBox1.Items.Clear(); var dict = new StringDict <int>(!caseSens); int cntPerItem = -1; for (int i = 0; i < lines.Count;) { String line = lines[i]; int existing; if (dict.TryGetValue(line, out existing)) { addMsg("Line {0} clashes with existing line {1}.", i, existing); } else { dict.Add(line, i); } int start = i; for (i++; i < lines.Count; i++) { String s = lines[i]; if (!cmp.Equals(s, line)) { break; } } int cnt = i - start; if (cntPerItem < 0) { cntPerItem = cnt; } else if (cnt != cntPerItem) { addMsg("Line {0}: unexpected count {1}, existing={2}.", start, cnt, cntPerItem); } } addMsg("Lines={0}, unique={1}, perUnique={2}. ", lines.Count, dict.Count, lines.Count / (double)dict.Count); }
public object Get(string key) { Object o; return(vars.TryGetValue(key, out o) ? o : null); }