/// <summary> /// Reads connections from configuration parameters. /// Each section represents an individual Connectionparams /// </summary> /// <param name="connections">configuration parameters to be read</param> private void ReadConnections(ConfigParams connections) { lock (_lock) { _items.Clear(); var connects = connections.GetSection("connections"); if (connections.Count > 0) { var connectionSections = connects.GetSectionNames(); foreach (var key in connectionSections) { var config = connects.GetSection(key); var item = new DiscoveryItem() { Key = key, Connection = new ConnectionParams(config) }; _items.Add(item); } } } }
public async Task RegisterAsync(string correlationId, string key, ConnectionParams connection) { lock (_lock) { var item = new DiscoveryItem() { Key = key, Connection = connection }; _items.Add(item); } await Task.Delay(0); }
private void ReadConnections(ConfigParams connections) { lock (_lock) { _items.Clear(); foreach (var entry in connections) { var item = new DiscoveryItem() { Key = entry.Key, Connection = ConnectionParams.FromString(entry.Value) }; _items.Add(item); } } }
/// <summary>Constructs a new logic item.</summary> public NuGetApiPublisher(DiscoveryItem item) { this.item = item; }
private void ReadCombos() { string[] lines = new string[] { }; this.discoverylist.Clear(); string path = Settings.Instance.path; string cleanpath = "Silverfish" + Path.DirectorySeparatorChar; string datapath = path + "Data" + Path.DirectorySeparatorChar; string cleandatapath = cleanpath + "Data" + Path.DirectorySeparatorChar; string classpath = datapath + ownClass + Path.DirectorySeparatorChar; string cleanclasspath = cleandatapath + ownClass + Path.DirectorySeparatorChar; string deckpath = classpath + deckName + Path.DirectorySeparatorChar; string cleandeckpath = cleanclasspath + deckName + Path.DirectorySeparatorChar; const string filestring = "_discovery.txt"; if (deckName != "" && File.Exists(deckpath + filestring)) { path = deckpath; cleanPath = cleandeckpath + filestring; } else if (deckName != "" && File.Exists(classpath + filestring)) { path = classpath; cleanPath = cleanclasspath + filestring; } else if (deckName != "" && File.Exists(datapath + filestring)) { path = datapath; cleanPath = cleandatapath + filestring; } else if (File.Exists(path + filestring)) { cleanPath = cleanpath + filestring; } else { Helpfunctions.Instance.ErrorLog("[Discovery] cant find base _discovery.txt, consider creating one"); return; } Helpfunctions.Instance.ErrorLog("[Discovery] read " + cleanPath); try { lines = File.ReadAllLines(path + "_discovery.txt"); } catch { Helpfunctions.Instance.ErrorLog("_discovery.txt read error. Continuing without user-defined rules."); return; } foreach (string line in lines) { string shortline = line.Replace(" ", ""); if (shortline.StartsWith("//")) { continue; } if (shortline.Length == 0) { continue; } try { DiscoveryItem d = new DiscoveryItem(line); this.discoverylist.Add(d); } catch { Helpfunctions.Instance.ErrorLog("[Discovery] cant read line: " + line); } } Helpfunctions.Instance.ErrorLog("[Discovery] " + discoverylist.Count + " rules found"); }
protected virtual void GetMembers(Type type, DiscoveryItem item) { if (type != typeof(string) && typeof(IEnumerable).IsAssignableFrom(type)) { var genericType = type.EnumerableType(); if (genericType != null) { GetMembers(genericType, item); return; } var indexer = type.StringIndexParameter(); if (indexer != null) { var valueType = indexer.PropertyType; var generic = typeof(KeyValuePair <,>); var constructed = generic.MakeGenericType(new Type[] { typeof(string), valueType }); GetMembers(constructed, item); return; } //If it wasn't IEnumberable<T> or inherited from IEnumerable<T> //Or had a string indexer //then it's unhandled right now item.Members.Add(new DiscoveryItem("Unhandled IEnumerable type", type.FullName)); return; } var members = type.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); foreach (var mem in members) { //We don't support explicit interface implementations as of now. That would require casting on the other end which doesn't make it it that easy if (mem.Name.Contains(".")) { continue; } if (!item.Members.Any(di => mem.Name == di.Name)) { var newTaxonomy = $"{item.Taxonomy}.{mem.Name}"; if (mem.MemberType == MemberTypes.Field) { var fld = (FieldInfo)mem; if (fld.IsDefined(typeof(CompilerGeneratedAttribute), true)) { continue; } item.Members.Add(new DiscoveryItem(fld, newTaxonomy)); } else if (mem.MemberType == MemberTypes.Property) { var prop = (PropertyInfo)mem; if (prop.IsDefined(typeof(CompilerGeneratedAttribute), true)) { continue; } item.Members.Add(new DiscoveryItem(prop, newTaxonomy)); } } } if (type.BaseType != null) { GetMembers(type.BaseType, item); } }